首页新闻找找看学习计划

求防伪码的加密解密算法

0
悬赏园豆:100 [已解决问题] 解决于 2014-07-11 22:05

在做防伪码,生成一组数字组成的字符串想通过加密算法,得到另一组数字。不知道怎么搞,求大神指导

一念成魔卍的主页 一念成魔卍 | 初学一级 | 园豆:3
提问于:2014-05-16 20:23
< >
分享
最佳答案
0

对称加密,非对称加密,指纹摘要,看你要哪种

收获园豆:30
钧梓昊逑 | 小虾三级 |园豆:945 | 2014-05-20 13:12
其他回答(3)
0

md5

收获园豆:20
刘宏玺 | 园豆:14004 (专家六级) | 2014-05-17 01:42
0
收获园豆:20
happydaily | 园豆:581 (小虾三级) | 2014-05-17 08:06
0
 1   private static Byte[] KEY_64 { get { return new byte[] { 42, 16, 93, 156, 78, 4, 218, 32 }; } }    
 2        private static Byte[] IV_64 { get { return new byte[] { 55, 103, 246, 79, 36, 99, 167, 3 }; } }
 3        
 4      
 5        /// <summary>
 6        /// 加密
 7        /// </summary>
 8        /// <param name="name"></param>
 9        /// <returns></returns>
10        public static string Encrypt(string name)//标准的DES加密  关键字、数据加密             
11        {
12            //#region DES加密算法                    
13            if (name != "")
14            {
15                DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider(); 
16                MemoryStream ms = new MemoryStream(); 
17                CryptoStream cs = new CryptoStream(ms, cryptoProvider.CreateEncryptor(KEY_64, IV_64), CryptoStreamMode.Write); 
18                StreamWriter sw = new StreamWriter(cs); sw.Write(name); sw.Flush(); cs.FlushFinalBlock(); ms.Flush(); //再转换为一个字符串  
19                return Convert.ToBase64String(ms.GetBuffer(), 0, Int32.Parse(ms.Length.ToString()));
20            }
21            else { return ""; }
22            //#endregion     
23        }
24 
25        /// <summary>
26        ///解密
27        /// </summary>
28        /// <param name="temp"></param>
29        /// <returns></returns>
30        public static string Decrypt(string temp)//标准的DES解密
31        {
32            //#region DES 解密算法          
33            if (temp != "")
34            {
35                DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider();   //从字符串转换为字节组              
36                Byte[] buffer = Convert.FromBase64String(temp);
37                MemoryStream ms = new MemoryStream(buffer);
38                CryptoStream cs = new CryptoStream(ms, cryptoProvider.CreateDecryptor(KEY_64, IV_64), CryptoStreamMode.Read);
39                StreamReader sr = new StreamReader(cs); return sr.ReadToEnd();
40            }
41            else 
42            { return ""; }
43            //#endregion     
44        }
收获园豆:30
青青子靖 | 园豆:234 (菜鸟二级) | 2014-05-17 09:08
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册