心事如莲,心静如水。驾一叶轻舟,吹一支长笛,自池塘深处,揽一朵莲花入怀,似红粉佳人,晶莹剔透,亭亭玉立,娇俏动人,喜一分,爱一分,怜一分,朵朵幽香入心田,丝丝柔情潜心底。
usingSystem; usingSystem.Collections.Generic; usingSystem.Linq; usingSystem.Text; usingSystem.Security.Cryptography; usingSystem.IO; namespaceWindowsFormsApplication1 { #regionTripleDES算法 publicclassClassTripleDES { publicClassTripleDES() { } //加密,使用密码产生加密算法的公钥,并使用TripleDES对密码进行加密。 publicstaticstringEncrypt(stringpass) { try { byte[]bt=(newSystem.Text.UnicodeEncoding()).GetBytes(pass); PasswordDeriveBytespdb=newPasswordDeriveBytes(pass,null); byte[]key=pdb.GetBytes(24); byte[]iv=pdb.GetBytes(8); MemoryStreamms=newMemoryStream(); TripleDESCryptoServiceProvidertdesc=newTripleDESCryptoServiceProvider(); CryptoStreamcs=newCryptoStream(ms,tdesc.CreateEncryptor(key,iv),CryptoStreamMode.Write); cs.Write(bt,0,bt.Length); cs.FlushFinalBlock(); returnConvert.ToBase64String(ms.ToArray()); } catch(Exceptionex) { throwex; } } //解密,使用密码产生加密算法的公钥,并使用TripleDES对加密数据进行解密。 publicstaticstringDecrypt(stringstr,stringpass) { try { byte[]bt=Convert.FromBase64String(str); PasswordDeriveBytespdb=newPasswordDeriveBytes(pass,null); byte[]key=pdb.GetBytes(24); byte[]iv=pdb.GetBytes(8); MemoryStreamms=newMemoryStream(); TripleDESCryptoServiceProvidertdesc=newTripleDESCryptoServiceProvider(); CryptoStreamcs=newCryptoStream(ms,tdesc.CreateDecryptor(key,iv),CryptoStreamMode.Write); cs.Write(bt,0,bt.Length); cs.FlushFinalBlock(); return(newSystem.Text.UnicodeEncoding()).GetString(ms.ToArray()); } catch(Exceptionex) { throwex; } } //使用: //stringstr=Encrypt("bbb"); //Console.WriteLine(Decrypt(str,"bbb")); //加密,使用密码产生加密算法的公钥,并使用TripleDES对密码进行加密。 publicstaticstringEncryptWithKey(stringpass,stringp_key) { try { byte[]bt=(newSystem.Text.UnicodeEncoding()).GetBytes(pass); PasswordDeriveBytespdb=newPasswordDeriveBytes(p_key,null); byte[]key=pdb.GetBytes(24); byte[]iv=pdb.GetBytes(8); MemoryStreamms=newMemoryStream(); TripleDESCryptoServiceProvidertdesc=newTripleDESCryptoServiceProvider(); CryptoStreamcs=newCryptoStream(ms,tdesc.CreateEncryptor(key,iv),CryptoStreamMode.Write); cs.Write(bt,0,bt.Length); cs.FlushFinalBlock(); returnConvert.ToBase64String(ms.ToArray()); } catch(Exceptionex) { throwex; } } //解密,使用密码产生加密算法的公钥,并使用TripleDES对加密数据进行解密。 publicstaticstringDecryptWithKey(stringstr,stringp_key) { try { byte[]bt=Convert.FromBase64String(str); PasswordDeriveBytespdb=newPasswordDeriveBytes(p_key,null); byte[]key=pdb.GetBytes(24); byte[]iv=pdb.GetBytes(8); MemoryStreamms=newMemoryStream(); TripleDESCryptoServiceProvidertdesc=newTripleDESCryptoServiceProvider(); CryptoStreamcs=newCryptoStream(ms,tdesc.CreateDecryptor(key,iv),CryptoStreamMode.Write); cs.Write(bt,0,bt.Length); cs.FlushFinalBlock(); return(newSystem.Text.UnicodeEncoding()).GetString(ms.ToArray()); } catch(Exceptionex) { throwex; } } } #endregion } 到此这篇关于asp.net TripleDES加密、解密算法就介绍到这了。我希望,离别的离别的离别之后,我们总能再相聚。更多相关asp.net TripleDES加密、解密算法内容请查看相关栏目,小编编辑不易,再次感谢大家的支持!