public static CryptoEncryptedPacket Encrypt(string plainText, RSAParameters publicKey) { var sessionKey = CryptoRandom.Generate(32); var encryptedPacket = new CryptoEncryptedPacket { Iv = CryptoRandom.Generate(16) }; encryptedPacket.EncryptedData = CryptoAes.Encrypt(plainText, sessionKey, encryptedPacket.Iv); encryptedPacket.EncryptedSessionKey = CryptoRsa.Encrypt(sessionKey, publicKey); return(encryptedPacket); }
public static CryptoEncryptedPacket Encrypt(string plainText, CryptoRSAParameters rsaParameters) { var sessionKey = CryptoRandom.Generate(32); var encryptedPacket = new CryptoEncryptedPacket { Iv = CryptoRandom.Generate(16) }; encryptedPacket.EncryptedData = CryptoAes.Encrypt(plainText, sessionKey, encryptedPacket.Iv); encryptedPacket.EncryptedSessionKey = CryptoRsa.Encrypt(sessionKey, rsaParameters.publicKey); encryptedPacket.Hmac = CryptoHmac.Sha256(encryptedPacket.EncryptedData, sessionKey); encryptedPacket.Signature = CryptoDigitalSignature.Sign(encryptedPacket.Hmac, rsaParameters.privateKey); return(encryptedPacket); }