public class Zip {
public static string EncryptString(string str) {
var sourceBytes = Encoding.GetEncoding("UTF-8").GetBytes(str);
var targetBytes = EncryptBytes(sourceBytes);
string encryptStr = Convert.ToBase64String(targetBytes);
return encryptStr;
}
public static string DecryptString(string str) {
var sourceBytes = Convert.FromBase64String(str);
var targetBytes = DecryptBytes(sourceBytes);
string decryptStr = Encoding.GetEncoding("UTF-8").GetString(targetBytes);
return decryptStr;
}
private static byte[] EncryptBytes(byte[] bytes) {
try {
var ms = new MemoryStream();
var zip = new GZipStream(ms, CompressionMode.Compress, true);
zip.Write(bytes, 0, bytes.Length);
zip.Close();
var buffer = new b
C# 加密解密之Zip
最新推荐文章于 2024-09-22 13:36:42 发布