/// <summary> /// Decrypts the specified <see cref="byte" />[] using the specified private key and returns a <see cref="byte" />[] representing the decrypted version of <paramref name="data" />. The <paramref name="data" /> parameter is a proprietary binary, created by the <see cref="Encrypt(byte[], RSAParameters)" /> method. /// </summary> /// <param name="data">A <see cref="byte" />[] with the data to be decrypted.</param> /// <param name="pemKey">A <see cref="string" /> value with the private key in its PEM representation, starting with "-----BEGIN RSA PRIVATE KEY-----".</param> /// <returns> /// A new <see cref="byte" />[] representing the decrypted version of <paramref name="data" />. /// </returns> public static byte[] Decrypt(byte[] data, string pemKey) { Check.ArgumentNull(data, nameof(data)); Check.ArgumentNull(pemKey, nameof(pemKey)); return(Decrypt(data, AsymmetricKeyConverter.ConvertToKey(pemKey))); }
/// <summary> /// Encrypts the specified <see cref="byte" />[] using the specified public key and returns a <see cref="byte" />[] representing the encrypted version of <paramref name="data" />. The resulting binary is proprietary and can be decrypted using the <see cref="Decrypt(byte[], RSAParameters)" /> method. /// </summary> /// <param name="data">A <see cref="byte" />[] with the data to be encrypted.</param> /// <param name="derKey">A <see cref="byte" />[] containing the public key in its DER representation.</param> /// <returns> /// A new <see cref="byte" />[] representing the encrypted version of <paramref name="data" />. The resulting binary is proprietary and can be decrypted using the <see cref="Decrypt(byte[], RSAParameters)" /> method. /// </returns> public static byte[] Encrypt(byte[] data, byte[] derKey) { Check.ArgumentNull(data, nameof(data)); Check.ArgumentNull(derKey, nameof(derKey)); return(Encrypt(data, AsymmetricKeyConverter.ConvertToKey(derKey))); }