public static string GetRasString() { KeyValuePair <string, string> encryptDecrypt = RsaEncrypt.GetKeyPair(); string rsaEn1 = RsaEncrypt.Encrypt("222222", encryptDecrypt.Key); return(rsaEn1); }
public void TestMethodEncrypt() { //var res = AesEncrypt.Encrypt("你好世界你好世界你好世界你好世界你好世界你好世界你好世界你好世界"); //var res2 = AesEncrypt.Decrypt(res); var jia = RsaEncrypt.Encrypt("Hello World"); var jie = RsaEncrypt.Decrypt("r1naGY+ZV4Hq6i7rQGlpiAO3UD2WNv1Vp+8dMcZB22CeKaA7wMzQayfd7YFlbcVBqRONuu6YO7MaI5If+JZjUGzKMPMyH8/Bx20jaEjgOJOTfukRNXnF+CK62jMOWJhbdc7Z82vz0zvbJbJqdThduBMl8CegGA/NXFfLuTlk+/c="); Component.Logger.Error(jie); Assert.IsFalse(false); }
protected void Page_Load(object sender, EventArgs e) { RsaEncrypt re = new RsaEncrypt(); string privatek = "", publick = ""; string[] arr = RsaEncrypt.GenerateKeys(ref privatek, ref publick); Response.Write(arr[0]); Response.Write("<br/><br/><br/><hr/><br/><br/><br/>"); Response.Write(arr[0]); }
static void Main(string[] args) { try { #region MD5 //1 防止看到明文 数据库密码,加盐(原密码+固定字符串,然后再MD5/双MD5) //2 防篡改 //急速秒传(第一次上传文件,保存md5摘要,第二次上传检查md5摘要) //文件下载(防篡改,官方发布的时候给一个md5摘要,安装的时候首先检查下摘要) //svn TFS git VSS(本地保存文件的md5摘要,任何修改都会影响md5) //3 防止抵赖 Console.WriteLine(MD5Encrypt.Encrypt("1")); Console.WriteLine(MD5Encrypt.Encrypt("1")); Console.WriteLine(MD5Encrypt.Encrypt("123456小李")); Console.WriteLine(MD5Encrypt.Encrypt("113456小李")); Console.WriteLine(MD5Encrypt.Encrypt("113456小李113456小李113456小李113456小李113456小李113456小李113456小李")); string md5Abstract1 = MD5Encrypt.AbstractFile(@"D:\ruanmou\online9\homework\1\Advanced9第一次作业优秀合集.rar"); string md5Abstract2 = MD5Encrypt.AbstractFile(@"D:\ruanmou\online9\homework\1\Advanced9第一次作业优秀合集 - 副本.rar"); #endregion #region Des //可逆对称加密 string desEn = DesEncrypt.Encrypt("王殃殃"); string desDe = DesEncrypt.Decrypt(desEn); string desEn1 = DesEncrypt.Encrypt("张三李四"); string desDe1 = DesEncrypt.Decrypt(desEn1); #endregion #region Rsa //可逆非对称加密 KeyValuePair <string, string> encryptDecrypt = RsaEncrypt.GetKeyPair(); string rsaEn1 = RsaEncrypt.Encrypt("net", encryptDecrypt.Key); //key是加密的 string rsaDe1 = RsaEncrypt.Decrypt(rsaEn1, encryptDecrypt.Value); //value 解密的 不能反过来用的 //加密钥 解密钥 钥匙的功能划分 //公钥 私钥 公开程度划分 #endregion } catch (Exception ex) { Console.WriteLine(ex.Message); } Console.Read(); }
protected void Page_Load(object sender, EventArgs e) { RsaEncrypt re = new RsaEncrypt(); string privateKey = @"<RSAKeyValue><Modulus>4KMaZkINCQhDgmoAUWt02Wy2z8pug3vB5f6hLKi2Xl2KHpawbCRoSHavOq1vYxOdOM1PLi+pJXqsQxqOvGZKrAdoAwserZG/EXaKsgDlag3O7ppBMo5vIbPLbFk3U/S69YiFjAf9nfBst7hZv6ny8csnEQ5FsCV3E45bje/n31M=</Modulus><Exponent>AQAB</Exponent><P>/r+oENJL0kBtF4tkh1cc9nvl+soPW9a7xorwB7m83LUkVmYDlss63rSKqVaZZcMOmCf0Z5slbzl1kdDTqifHzw==</P><Q>4b2U6r1gxFGTCts812xVLH4Mycl2y0A+IaV2QYnKIrsm8EHtH0RpHywY86GBTi53PBH4Q/V1aOoXbez8PmxNPQ==</Q><DP>2irNBkrzgEaIpwdLutSSC02kcZkmeiJ2gdxvIE6jPeksC4omPLgj3KKFtexiRtI753cgSrKF5rEwzQYon6qd5Q==</DP><DQ>tYRWLHNfTj0x+bbUs3x++Kna6p8/EKx1yWRdNNHxYgAPjX3ViCDgTpqM7creSNmAMyNX+H11jYk+kbvQEPnRGQ==</DQ><InverseQ>B6uXEtIT8CKWWcdrJxUqMNY7VakmYBBeH0LvDj8ExVpxDn5oI6t3/TXswNyeFT7w1pIqrQgIWAkIyrbpZJ8lWA==</InverseQ><D>TMaSHEcQ63heknEmQK2oVzN329cFJH0kzTXU4k2bXu87aK76B0v+NF4UD8r9GfC3OJW7LT7u4bdmrtyh0jRn6nW4og7pQl2WjqiiVukDERe6yYPDgvwjPh6xkkXbfr6LUVuHoTFEU7wZMjoVimrmG39el6QA3hH6rS+LLEqW0bk=</D></RSAKeyValue>"; string publisKey = @"<RSAKeyValue><Modulus>4KMaZkINCQhDgmoAUWt02Wy2z8pug3vB5f6hLKi2Xl2KHpawbCRoSHavOq1vYxOdOM1PLi+pJXqsQxqOvGZKrAdoAwserZG/EXaKsgDlag3O7ppBMo5vIbPLbFk3U/S69YiFjAf9nfBst7hZv6ny8csnEQ5FsCV3E45bje/n31M=</Modulus><Exponent>AQAB</Exponent><P>/r+oENJL0kBtF4tkh1cc9nvl+soPW9a7xorwB7m83LUkVmYDlss63rSKqVaZZcMOmCf0Z5slbzl1kdDTqifHzw==</P><Q>4b2U6r1gxFGTCts812xVLH4Mycl2y0A+IaV2QYnKIrsm8EHtH0RpHywY86GBTi53PBH4Q/V1aOoXbez8PmxNPQ==</Q><DP>2irNBkrzgEaIpwdLutSSC02kcZkmeiJ2gdxvIE6jPeksC4omPLgj3KKFtexiRtI753cgSrKF5rEwzQYon6qd5Q==</DP><DQ>tYRWLHNfTj0x+bbUs3x++Kna6p8/EKx1yWRdNNHxYgAPjX3ViCDgTpqM7creSNmAMyNX+H11jYk+kbvQEPnRGQ==</DQ><InverseQ>B6uXEtIT8CKWWcdrJxUqMNY7VakmYBBeH0LvDj8ExVpxDn5oI6t3/TXswNyeFT7w1pIqrQgIWAkIyrbpZJ8lWA==</InverseQ><D>TMaSHEcQ63heknEmQK2oVzN329cFJH0kzTXU4k2bXu87aK76B0v+NF4UD8r9GfC3OJW7LT7u4bdmrtyh0jRn6nW4og7pQl2WjqiiVukDERe6yYPDgvwjPh6xkkXbfr6LUVuHoTFEU7wZMjoVimrmG39el6QA3hH6rS+LLEqW0bk=</D></RSAKeyValue>"; string hardId = Helper.Win32Helper.GetHardID(); string text = "niejunhua"; string jiami2 = re.Encrypt(publisKey, text); Response.Write("明文:" + text + "<br/><br/>"); Response.Write("加密结果:" + jiami2 + "<br/><br/>"); //string s = re.Decrypt(publisKey, jiami2); //Response.Write("jie密结果:" + s + "<br/><br/><br/>"); }
static void Main(string[] args) { {//MD5 //非对称不可逆 Console.WriteLine("*************************************非对称不可逆 MD5****************************************"); string fileNmae = @"F:\志翔学校.rar"; string fileNmaeCopy = @"F:\志翔学校 - 副本.rar"; Console.WriteLine(MD5Encrypt.Encrypt("123")); Console.WriteLine(MD5Encrypt.Encrypt("123")); Console.WriteLine(MD5Encrypt.Encrypt("321null")); Console.WriteLine("文件MD5 Soure:" + MD5Encrypt.AbstractFile(fileNmae)); Console.WriteLine("文件MD5 Copy:" + MD5Encrypt.AbstractFile(fileNmaeCopy)); } {//DesEncrypt //对称可逆加密 //速度比较快 Console.WriteLine("*************************************对称可逆加密 DES****************************************"); string des = DesEncrypt.Encrypt("1233211234567890"); string res = DesEncrypt.Decrypt(des); Console.WriteLine("Desc:" + des); Console.WriteLine("ESC:" + res); } {//Ras //非对称可逆加密 //速度比较慢 Console.WriteLine("*************************************非对称可逆加密 RSA****************************************"); KeyValuePair <string, string> encryptDecrypt = RsaEncrypt.GetKeyPair(); string rsaEn1 = RsaEncrypt.Encrypt("222222", encryptDecrypt.Key); string rsaDe1 = RsaEncrypt.Decrypt(rsaEn1, encryptDecrypt.Value); Console.WriteLine("加密:" + rsaEn1); Console.WriteLine("解密:" + rsaDe1); Console.WriteLine("公钥:" + encryptDecrypt.Key); Console.WriteLine("私钥:" + encryptDecrypt.Value); } {//Ras test //非对称可逆加密 //速度比较慢 Console.WriteLine("*************************************非对称可逆加密 RSA****************************************"); RSAUtil rsa = new RSAUtil(); //rsa.CreateRSAKey(); //StreamReader reader1 = new StreamReader("privatekey.xml"); //XmlDocument document1 = new XmlDocument(); //document1.LoadXml(reader1.ReadToEnd()); //XmlElement element1 = (XmlElement)document1.SelectSingleNode("root"); //parameters1.Modulus = ReadChild(element1, "Modulus"); //var r1 = rsa.ToHexString(rsa.ReadChild(element1, "Exponent")); //var r2 = rsa.ToHexString(rsa.ReadChild(element1, "D")); //var r3 = rsa.ToHexString(rsa.ReadChild(element1, "Q")); //var r4 = rsa.ToHexString(rsa.ReadChild(element1, "P")); var en = rsa.EnCrypt("123"); var doEn = rsa.DoEncrypt(en); Console.WriteLine("原文:" + doEn); Console.WriteLine("密文:" + en); Console.WriteLine("解密:" + doEn); //Console.WriteLine(r1); //Console.WriteLine(r2); //Console.WriteLine(r3); //Console.WriteLine(r4); //parameters1.DP = ReadChild(element1, "DP"); //parameters1.DQ = ReadChild(element1, "DQ"); //parameters1.P = ReadChild(element1, "P"); //parameters1.Q = ReadChild(element1, "Q"); //parameters1.InverseQ = ReadChild(element1, "InverseQ"); //reader1.Close(); } Console.ReadKey(); }