コード例 #1
0
        /// <summary>
        /// 使用公钥Rsa解密
        /// <para>
        /// 如果PKCS#8格式的公钥则使用 <see cref="RsaEncryptByPublicKey"/>
        /// </para>
        /// <para>
        /// 如果PKCS#1格式的公钥则使用 <see cref="RsaEncryptByAsn1PublicKey"/>
        /// </para>
        /// </summary>
        /// <param name="data">待解密的字节码</param>
        /// <param name="publicKey">PKCS#1的BASE64编码的公钥(BASE64编码)</param>
        /// <param name="cipherMode">密码模式</param>
        /// <param name="cipherPadding">填充方式</param>
        /// <returns>返回Rsa加密后的字节码</returns>
        public static byte[] RsaEncryptByAsn1PublicKey(this byte[] data, string publicKey, CipherMode cipherMode, CipherPadding cipherPadding)
        {
            var cipherParameters = RSAUtilities.GetPublicKeyParameterFormAsn1PublicKey(publicKey);

            return(SecurityExtension.Encrypt(data, CipherAlgorithm.RSA, cipherMode, cipherPadding, cipherParameters));
        }