public static string Decrypt(CryptoEncryptedPacket encryptedPacket, CryptoRSAParameters rsaParameters) { var decryptedSessionKey = CryptoRsa.Decrypt(encryptedPacket.EncryptedSessionKey, rsaParameters.privateKey); var hmacToCheck = CryptoHmac.Sha256(encryptedPacket.EncryptedData, decryptedSessionKey); if (!Compare(encryptedPacket.Hmac, hmacToCheck)) { throw new CryptographicException("HMAC for decyrption does not match encrypted packet"); } if (!CryptoDigitalSignature.Verify(encryptedPacket.Hmac, encryptedPacket.Signature, rsaParameters.publicKey)) { throw new CryptographicException("Digital Signature can not be verified"); } return(CryptoAes.Decrypt(encryptedPacket.EncryptedData, decryptedSessionKey, encryptedPacket.Iv)); }
public static string Decrypt(CryptoEncryptedPacket encryptedPacket, RSAParameters privateKey) { var decryptedSessionKey = CryptoRsa.Decrypt(encryptedPacket.EncryptedSessionKey, privateKey); return(CryptoAes.Decrypt(encryptedPacket.EncryptedData, decryptedSessionKey, encryptedPacket.Iv)); }