Exemplo n.º 1
0
        /// <summary>
        /// 从字符串获取密钥
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        static public RSAParameters KeyFromString(string str)
        {
            byte[] buf = EncryptString.GetBytes(str);

            MemoryStream s = new MemoryStream();

            s.Write(buf, 0, buf.Length);
            s.Position = 0;

            object obj;

            obj = Hubble.Framework.Serialization.XmlSerialization.Deserialize(s, typeof(InnerRSAParameters));

            InnerRSAParameters inner = (InnerRSAParameters)obj;

            RSAParameters key = new RSAParameters();

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

            return(key);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 解密字符串
        /// </summary>
        /// <param name="str">要解密的字符串</param>
        /// <param name="RSAKeyInfo">私钥</param>
        /// <returns>加密后的字符串</returns>
        static public string RSADecryptString(string str, RSAParameters RSAKeyInfo)
        {
            byte[] buf = EncryptString.GetBytes(str);
            buf = RSADecrypt(buf, RSAKeyInfo);
            MemoryStream s = new MemoryStream();

            s.Write(buf, 0, buf.Length);

            string retString;

            s.Position = 0;
            Hubble.Framework.IO.Stream.ReadStreamToString(s, out retString, Encoding.UTF8);

            return(retString);
        }
Exemplo n.º 3
0
 public static String Decrypt(string key, String text)
 {
     return(Decrypt(EncryptString.GetBytes(key), EncryptString.GetBytes(text)));
 }
Exemplo n.º 4
0
 public static String Decrypt(byte[] key, String text)
 {
     return(Decrypt(key, EncryptString.GetBytes(text)));
 }