コード例 #1
0
 /// <summary>
 /// Encrypts the message using an exchange public key
 /// </summary>
 /// <param name="message">Message to be encrypted</param>
 /// <param name="publicKey">Public exchange key to encrypt the message</param>
 /// <param name="padding">Padding mode to be used with the encryption</param>
 /// <returns>Encrypted message as byte array</returns>
 /// <exception cref="ArgumentException">There is null in the parameters or one of the parameters empty</exception>
 /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired.-or- The parameters parameter has missing fields. -or- The padding mode is not supported. -or- The certificate context is invalid.</exception>
 public static byte[] EncryptToByteArray(byte[] message, X509Certificate2 publicKey, RSAEncryptionPadding padding)
 {
     return(CertificateCrypto.Encrypt(message, publicKey, padding));
 }
コード例 #2
0
 /// <summary>
 /// Encrypts the message using an exchange public key
 /// </summary>
 /// <param name="message">Message to be encrypted</param>
 /// <param name="publicKey">Public exchange key to encrypt the message</param>
 /// <param name="padding">Padding mode to be used with the encryption</param>
 /// <returns>Encrypted message as base64 string</returns>
 /// <exception cref="ArgumentException">There is null in the parameters or one of the parameters empty</exception>
 /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired.-or- The parameters parameter has missing fields. -or- The padding mode is not supported. -or- The certificate context is invalid.</exception>
 public static string Encrypt(byte[] message, X509Certificate2 publicKey, RSAEncryptionPadding padding)
 {
     return(Convert.ToBase64String(CertificateCrypto.Encrypt(message, publicKey, padding)));
 }