Exemple #1
0
 public void EncryptAndDecryptTest()
 {
     DesHelper des = new DesHelper();
     Assert.AreEqual(des.Decrypt(des.Encrypt("admin")), "admin");
     des = new DesHelper(true);
     Assert.AreEqual(des.Decrypt(des.Encrypt("admin")), "admin");
 }
Exemple #2
0
        /// <summary>
        /// 解密字符串,输入BASE64编码字符串
        /// </summary>
        /// <param name="source">要解密的BASE64编码字符串</param>
        /// <param name="key">密钥字符串,长度为8或者24</param>
        /// <returns>解密的明文字符串</returns>
        public static string Decrypt(string source, string key)
        {
            source.CheckNotNullOrEmpty("source");
            key.CheckNotNullOrEmpty("key");
            byte[]    keyBytes = Encoding.UTF8.GetBytes(key);
            DesHelper des      = new DesHelper(keyBytes);

            return(des.Decrypt(source));
        }
Exemple #3
0
        public void DecryptTest()
        {
            string key = "12345678";
            string actual = "TMR29YtnGPI=";
            DesHelper des = new DesHelper(Encoding.UTF8.GetBytes(key));
            Assert.AreEqual(des.Decrypt(actual), "admin");
            Assert.AreEqual(DesHelper.Decrypt(actual, key), "admin");

            key = "!@#$%^&*QWERTYUI12345678";
            actual = "Qp4r67VJ8Z0=";
            des = new DesHelper(Encoding.UTF8.GetBytes(key));
            Assert.AreEqual(des.Decrypt(actual), "admin");
            Assert.AreEqual(DesHelper.Decrypt(actual, key), "admin");
        }
Exemple #4
0
 /// <summary>
 /// 解密字符串,输入BASE64编码字符串
 /// </summary>
 /// <param name="source">要解密的BASE64编码字符串</param>
 /// <param name="key">密钥字符串,长度为8或者24</param>
 /// <returns>解密的明文字符串</returns>
 public static string Decrypt(string source, string key)
 {
     source.CheckNotNullOrEmpty("source");
     key.CheckNotNullOrEmpty("key");
     byte[] keyBytes = Encoding.UTF8.GetBytes(key);
     DesHelper des = new DesHelper(keyBytes);
     return des.Decrypt(source);
 }
Exemple #5
0
 /// <summary>
 /// 解密字节数组
 /// </summary>
 /// <param name="source">要解密的字节数组</param>
 /// <param name="key">密钥字节数组,长度为8或者24</param>
 /// <returns>解密后的字节数组</returns>
 public static byte[] Decrypt(byte[] source, byte[] key)
 {
     DesHelper des = new DesHelper(key);
     return des.Decrypt(source);
 }
Exemple #6
0
        /// <summary>
        /// 解密字节数组
        /// </summary>
        /// <param name="source">要解密的字节数组</param>
        /// <param name="key">密钥字节数组,长度为8或者24</param>
        /// <returns>解密后的字节数组</returns>
        public static byte[] Decrypt(byte[] source, byte[] key)
        {
            DesHelper des = new DesHelper(key);

            return(des.Decrypt(source));
        }