예제 #1
0
        /// <summary>
        /// 加密字符串
        /// </summary>
        /// <param name="str">要加密的字符串</param>
        /// <param name="RSAKeyInfo">公钥</param>
        /// <returns>加密后的字符串</returns>
        static public string RSAEncryptString(string str, RSAParameters RSAKeyInfo)
        {
            Stream s = Hubble.Framework.IO.Stream.WriteStringToStream(str, Encoding.UTF8);

            byte[] buf = new byte[s.Length];
            s.Position = 0;
            s.Read(buf, 0, buf.Length);
            buf = RSAEncrypt(buf, RSAKeyInfo);
            return(EncryptString.GetString(buf));
        }
예제 #2
0
        public static String Encrypt(byte[] key, String text)
        {
            byte[] textArray = Encoding.UTF8.GetBytes(text);

            DESCryptoServiceProvider dCSP    = new DESCryptoServiceProvider();
            MemoryStream             mStream = new MemoryStream();
            CryptoStream             cStream = new CryptoStream(mStream, dCSP.CreateEncryptor(key, IV), CryptoStreamMode.Write);

            cStream.Write(textArray, 0, textArray.Length);
            cStream.FlushFinalBlock();
            return(EncryptString.GetString(mStream.ToArray()));
        }
예제 #3
0
        /// <summary>
        /// 将密钥转换为字符串
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        static public string KeyToString(RSAParameters key)
        {
            InnerRSAParameters inner;

            inner.D        = key.D;
            inner.DP       = key.DP;
            inner.DQ       = key.DQ;
            inner.Exponent = key.Exponent;
            inner.InverseQ = key.InverseQ;
            inner.Modulus  = key.Modulus;
            inner.P        = key.P;
            inner.Q        = key.Q;

            Stream s = Hubble.Framework.Serialization.XmlSerialization.Serialize(inner);

            byte[] buf = new byte[s.Length];

            s.Position = 0;
            s.Read(buf, 0, (int)s.Length);

            return(EncryptString.GetString(buf));
        }