示例#1
0
文件: Rsa.cs 项目: wingahi/CSHive
        /// <summary>
        /// 用公钥加密字符串
        /// </summary>
        /// <param name="source">源有长度限制</param>
        /// <param name="publicKey"></param>
        /// <returns>返回加密后的Base64字符串</returns>
        public static string Encrypt(string source, string publicKey)
        {
            var bs  = Encoding.UTF8.GetBytes(source);
            var rsa = new Rsa(publicKey);
            var rst = rsa.Encrypt(bs);

            return(Convert.ToBase64String(rst));
        }
示例#2
0
 /// <summary>
 /// 将Key用RSA加密
 /// </summary>
 /// <param name="key"></param>
 /// <returns></returns>
 public static byte[] RsaKey(byte[] key)
 {
     var rsa = new Rsa(PublicKey);
     return rsa.Encrypt(key);
 }
示例#3
0
        /// <summary>
        /// 将Key用RSA加密
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static byte[] RsaKey(byte[] key)
        {
            var rsa = new Rsa(PublicKey);

            return(rsa.Encrypt(key));
        }