public static byte[] Decrypt(X509Certificate2 keyCertificate, byte[] encryptedKey, byte[] encryptedData) { RSA privateKey = RSAKeyLoader.LoadFromCertificate(keyCertificate); if (!privateKey.GetHasPrivateKey()) { throw new ArgumentException("Private key information not found in certificate."); } return(Decrypt(privateKey, encryptedKey, encryptedData)); }
public static (byte[] encryptedKey, byte[] encryptedData) Encrypt(X509Certificate2 publicCertificate, byte[] data, int aesKeySize = 128) { RSA publicKey = RSAKeyLoader.LoadFromCertificate(publicCertificate); if (!publicKey.GetHasPublicKey()) { throw new ArgumentException("Public key information not found in certificate."); } return(Encrypt(publicKey, data, aesKeySize)); }