首页 > Windows开发 > 详细

C#NET字符编码加解密的参考代码

时间:2020-03-04 23:40:31      阅读:110      评论:0      收藏:0      [点我收藏+]
 //C#NET字符编码加解密的参考代码我是从老外程序里面拷贝出来的希望对大家有所用
1
public string Encrypt(string name) { 2 byte ivId = GetIVId(name); 3 cipher.IV = GetIV(ivId); 4 var buf = Encoding.UTF8.GetBytes(name); 5 6 using (var ms = new MemoryStream()) { 7 ms.WriteByte(ivId); 8 using (var stream = new CryptoStream(ms, cipher.CreateEncryptor(), CryptoStreamMode.Write)) 9 stream.Write(buf, 0, buf.Length); 10 11 buf = ms.ToArray(); 12 return Base64Encode(buf); 13 } 14 } 15 16 public string Decrypt(string name) { 17 using (var ms = new MemoryStream(Base64Decode(name))) { 18 byte ivId = (byte)ms.ReadByte(); 19 cipher.IV = GetIV(ivId); 20 21 var result = new MemoryStream(); 22 using (var stream = new CryptoStream(ms, cipher.CreateDecryptor(), CryptoStreamMode.Read)) 23 stream.CopyTo(result); 24 25 return Encoding.UTF8.GetString(result.ToArray()); 26 } 27 }

 

C#NET字符编码加解密的参考代码

原文:https://www.cnblogs.com/wz2988/p/12416558.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!