public byte[] DecryptDataWithSignature(EncryptedPacket EP, RsaWithRsaParameterKey rsaParams, DigitalSignatures DS) { // Receiver decrypts AES session key with RSA byte[] decryptedSessionKey = rsaParams.DecryptData(EP.EncryptedSessionKey); // Receiver compares using (HMACSHA256 hmac = new HMACSHA256(decryptedSessionKey)) { byte[] hmacToCheck = hmac.ComputeHash(EP.EncryptedData); if (!CompareHashes(EP.Hmac, hmacToCheck)) { throw new CryptographicException("HMAC for decryption does not match encrypted packet HMAC"); } if (!DS.VerifySignature(EP.Hmac, EP.Signature)) { throw new CryptographicException("Digital Signature cannot be verified"); } } // Receiver decrypts the data wuth AES using the decrypted session key byte[] decryptedData = _cryptographyExample.DecryptUsingAES(EP.EncryptedData, decryptedSessionKey, EP.IV); return(decryptedData); }
public byte[] DecryptData(EncryptedPacket EP, RsaWithRsaParameterKey rsaParams) { // Receiver decrypts AES session key with RSA byte[] decryptedSessionKey = rsaParams.DecryptData(EP.EncryptedSessionKey); // Receiver decrypts the data wuth AES using the decrypted session key byte[] decryptedData = _cryptographyExample.DecryptUsingAES(EP.EncryptedData, decryptedSessionKey, EP.IV); return(decryptedData); }