function decrypt(EncryptedPersonalData $data, CryptographicDetails $crypto): PersonalData {

        if ( ! $crypto->encryption() == 'libsodium') {
            throw new CryptographicDetailsNotCompatibleWithEncryption("{$crypto->encryption()} received, expected 'libsodium'");
        }

        $encrypted = $data->toString();
        $secretKey = $crypto->key('secretKey');
        $nonce     = $crypto->key('nonce');

        $decrypted = sodium_crypto_secretbox_open($encrypted, $nonce, $secretKey);

        return PersonalData::fromString($decrypted);
    }
function decrypt(EncryptedPersonalData $data, CryptographicDetails $crypto): PersonalData {

        if ( ! $crypto->encryption() == 'libsodium') {
            throw new CryptographicDetailsNotCompatibleWithEncryption("{$crypto->encryption()} received, expected 'libsodium'");
        }

        $encrypted = $data->toString();
        $secretKey = $crypto->key('secretKey');
        $nonce     = $crypto->key('nonce');

        $decrypted = sodium_crypto_secretbox_open($encrypted, $nonce, $secretKey);

        return PersonalData::fromString($decrypted);
    }
function decrypt ( EncryptedPersonalData $ data , CryptographicDetails $ crypto ) : PersonalData { if ( ! $ crypto -> encryption ( ) == 'libsodium' ) { throw new CryptographicDetailsNotCompatibleWithEncryption ( "{$crypto->encryption()} received, expected 'libsodium'" ) ; } $ encrypted = $ data -> toString ( ) ; $ secretKey = $ crypto -> key ( 'secretKey' ) ; $ nonce = $ crypto -> key ( 'nonce' ) ; $ decrypted = sodium_crypto_secretbox_open ( $ encrypted , $ nonce , $ secretKey ) ; return PersonalData :: fromString ( $ decrypted ) ; }
decrypted encrypted personal data and return a decrypted form

@param EncryptedPersonalData $data
@param CryptographicDetails $crypto
@throws CryptographicDetailsDoNotContainKey
@throws CryptographicDetailsNotCompatibleWithEncryption
@return PersonalData
decrypted encrypted personal data and return a decrypted form