国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

c#加密 可逆與不可逆MD5 加密

2019-11-17 03:02:24
字體:
供稿:網(wǎng)友
c#加密 可逆與不可逆md5 加密

1、方法一 (不可逆加密)srxljl

publicstringEncryptPassWord(stringPasswordString,stringPasswordFormat ) {   stringencryptPassword=null;   if(PasswordFormat="SHA1"){    encryptPassword=FormsAuthortication.HashPasswordForStoringInConfigFile(PasswordString ,"SHA1"); } elseif (PasswordFormat="MD5")   {

      encryptPassword=FormsAuthortication.HashPasswordForStoringInConfigFile(PasswordString ,"MD5"); }     returnencryptPassword ; }

2、方法二 (可逆加密)srxljl

publicinterfaceIBindesh { stringencode(stringstr); stringdecode(stringstr); } publicclassEncryptionDecryption : IBindesh { publicstringencode(stringstr) { stringhtext=""; for(inti=0; i<str.Length; i++) { htext=htext+(char) (str[i]+10-1*2); } returnhtext; } publicstringdecode(stringstr) { stringdtext=""; for(inti=0; i<str.Length; i++) { dtext=dtext+(char) (str[i]-10+1*2); } returndtext; }

3、方法三 (可逆加密)srxljl

conststringKEY_64="VavicApp";//注意了,是8個(gè)字符,64位 conststringIV_64="VavicApp"; publicstringEncode(stringdata) { byte[] byKey=System.Text.ASCIIEncoding.ASCII.GetBytes(KEY_64); byte[] byIV=System.Text.ASCIIEncoding.ASCII.GetBytes(IV_64); DESCryptoServicePRovider cryptoProvider=newDESCryptoServiceProvider(); inti=cryptoProvider.KeySize; MemoryStream ms=newMemoryStream(); CryptoStream cst=newCryptoStream(ms, cryptoProvider.CreateEncryptor(byKey, byIV), CryptoStreamMode.Write); StreamWriter sw=newStreamWriter(cst); sw.Write(data); sw.Flush(); cst.FlushFinalBlock(); sw.Flush(); returnConvert.ToBase64String(ms.GetBuffer(),0, (int)ms.Length); } publicstringDecode(stringdata) { byte[] byKey=System.Text.ASCIIEncoding.ASCII.GetBytes(KEY_64); byte[] byIV=System.Text.ASCIIEncoding.ASCII.GetBytes(IV_64); byte[] byEnc; try { byEnc=Convert.FromBase64String(data); } catch { returnnull; } DESCryptoServiceProvider cryptoProvider=newDESCryptoServiceProvider(); MemoryStream ms=newMemoryStream(byEnc); CryptoStream cst=newCryptoStream(ms, cryptoProvider.CreateDecryptor(byKey, byIV), CryptoStreamMode.Read); StreamReader sr=newStreamReader(cst); returnsr.ReadToEnd(); }

4,md5(32位加密)srxljl

publicstringGetMD5(strings,string_input_charset) { ///<summary> ///與asp兼容的MD5加密算法 ///</summary> MD5 md5=newMD5CryptoServiceProvider(); byte[] t=md5.ComputeHash(Encoding.GetEncoding(_input_charset).GetBytes(s)); StringBuilder sb=newStringBuilder(32); for(inti=0; i<t.Length; i++) { sb.Append(t[i].ToString("x").PadLeft(2,'0')); } returnsb.ToString(); }

(16位加密)srxljl

publicstaticstringGetMd5Str(stringConvertString) { MD5CryptoServiceProvider md5=newMD5CryptoServiceProvider(); stringt2=BitConverter.ToString(md5.ComputeHash(UTF8Encoding.Default.GetBytes(ConvertString)),4,8); t2=t2.Replace("-",""); returnt2; }

5、加解文本文件srxljl

//加密文件 privatestaticvoidEncryptData(String inName, String outName,byte[] desKey,byte[] desIV) { //Create the file streams to handle the input and output files. FileStream fin=newFileStream(inName, FileMode.Open, Fileaccess.Read); FileStream fout=newFileStream(outName, FileMode.OpenOrCreate, FileAccess.Write); fout.SetLength(0); //Create variables to help with read and write. byte[] bin=newbyte[100];//This is intermediate storage for the encryption. longrdlen=0;//This is the total number of bytes written. longtotlen=fin.Length;//This is the total length of the input file. intlen;//This is the number of bytes to be written at a time. DES des=newDESCryptoServiceProvider(); CryptoStream encStream=newCryptoStream(fout, des.CreateEncryptor(desKey, desIV), CryptoStreamMode.Write); //Read from the input file, then encrypt and write to the output file. while(rdlen<totlen) { len=fin.Read(bin,0,100); encStream.Write(bin,0, len); rdlen=rdlen+len; } encStream.Close(); fout.Close(); fin.Close(); } //解密文件 privatestaticvoidDecryptData(String inName, String outName,byte[] desKey,byte[] desIV) { //Create the file streams to handle the input and output files. FileStream fin=newFileStream(inName, FileMode.Open, FileAccess.Read); FileStream fout=newFileStream(outName, FileMode.OpenOrCreate, FileAccess.Write); fout.SetLength(0); //Create variables to help with read and write. byte[] bin=newbyte[100];//This is intermediate storage for the encryption. longrdlen=0;//This is the total number of bytes written. longtotlen=fin.Length;//This is the total length of the input file. intlen;//This is the number of bytes to be written at a time. DES des=newDESCryptoServiceProvider(); CryptoStream encStream=newCryptoStream(fout, des.CreateDecryptor(desKey, desIV), CryptoStreamMode.Write); //Read from the input file, then encrypt and write to the output file. while(rdlen<totlen) { len=fin.Read(bin,0,100); encStream.Write(bin,0, len); rdlen=rdlen+len; } encStream.Close(); fout.Close(); fin.Close(); }


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 张北县| 大悟县| 连江县| 白玉县| 奇台县| 富平县| 营山县| 唐河县| 吴堡县| 英吉沙县| 全南县| 河源市| 榆中县| 宽甸| 尉氏县| 乐昌市| 三亚市| 湘潭县| 雅安市| 大新县| 梅河口市| 安泽县| 尼勒克县| 和硕县| 利津县| 阿拉尔市| 竹山县| 康乐县| 肃宁县| 滕州市| 金门县| 罗山县| 应城市| 连城县| 周宁县| 兴义市| 南开区| 镇江市| 贵州省| 青河县| 湟源县|