在做防伪码,生成一组数字组成的字符串想通过加密算法,得到另一组数字。不知道怎么搞,求大神指导
对称加密,非对称加密,指纹摘要,看你要哪种
md5
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 }