public static function hash(
        HiddenString $password,
        EncryptionKey $secretKey,
        string $level = KeyFactory::INTERACTIVE,
        string $additionalData = ''
    ): string {
        $kdfLimits = KeyFactory::getSecurityLevels($level);
        // First, let's calculate the hash
        $hashed = \sodium_crypto_pwhash_str(
            $password->getString(),
            $kdfLimits[0],
            $kdfLimits[1]
        );
        
        // Now let's encrypt the result
        return Crypto::encryptWithAd(
            new HiddenString($hashed),
            $secretKey,
            $additionalData
        );
    }
public static function hash(
        HiddenString $password,
        EncryptionKey $secretKey,
        string $level = KeyFactory::INTERACTIVE,
        string $additionalData = ''
    ): string {
        $kdfLimits = KeyFactory::getSecurityLevels($level);
        // First, let's calculate the hash
        $hashed = \sodium_crypto_pwhash_str(
            $password->getString(),
            $kdfLimits[0],
            $kdfLimits[1]
        );
        
        // Now let's encrypt the result
        return Crypto::encryptWithAd(
            new HiddenString($hashed),
            $secretKey,
            $additionalData
        );
    }
public static function hash ( HiddenString $ password , EncryptionKey $ secretKey , string $ level = KeyFactory :: INTERACTIVE , string $ additionalData = '' ) : string { $ kdfLimits = KeyFactory :: getSecurityLevels ( $ level ) ; // First, let's calculate the hash $ hashed = \ sodium_crypto_pwhash_str ( $ password -> getString ( ) , $ kdfLimits [ 0 ] , $ kdfLimits [ 1 ] ) ; // Now let's encrypt the result return Crypto :: encryptWithAd ( new HiddenString ( $ hashed ) , $ secretKey , $ additionalData ) ; }
Hash then encrypt a password

@param HiddenString $password    The user's password
@param EncryptionKey $secretKey  The master key for all passwords
@param string $level             The security level for this password
@param string $additionalData    Additional authenticated data
@return string                   An encrypted hash to store

@throws InvalidDigestLength
@throws CannotPerformOperation
@throws InvalidMessage
@throws InvalidType
@throws \TypeError
Hash then encrypt a password