public static string encrypt(string source)
{
md5cryptoserviceprovider md5 = new md5cryptoserviceprovider();
byte[] bytes = encoding.utf8.getbytes(source);
byte[] output = md5.computehash(bytes);
return bitconverter.tostring(output);
}
最常见的md5加密,但不带解密。
des加解密。
public class des
{
private const string key = "av&6^3*e";
public static string encrypt(string source)
{
descryptoserviceprovider des = new descryptoserviceprovider();
byte[] bytes = encoding.utf8.getbytes(source);
des.key = asciiencoding.ascii.getbytes(key);
des.iv = asciiencoding.ascii.getbytes(key);
memorystream ms = new memorystream();
cryptostream cs = new cryptostream(ms, des.createencryptor(), cryptostreammode.write);
cs.write(bytes, 0, bytes.length);
cs.flushfinalblock();
stringbuilder sb = new stringbuilder();
foreach (byte b in ms.toarray())
{
sb.appendformat("{0:x2}", b);
}
return sb.tostring();
}
public static string decrypt(string source)
{
if (source == null || source.length == 0)
{
return source;
}
descryptoserviceprovider des = new descryptoserviceprovider();
byte[] bytes = new byte[source.length / 2];
for (int x = 0; x {
int i = (convert.toint32(source.substring(x * 2, 2), 16));
bytes[x] = (byte)i;
}
des.key = asciiencoding.ascii.getbytes(key);
des.iv = asciiencoding.ascii.getbytes(key);
memorystream ms = new memorystream();
cryptostream cs = new cryptostream(ms, des.createdecryptor(), cryptostreammode.write);
cs.write(bytes, 0, bytes.length);
cs.flushfinalblock();
return encoding.utf8.getstring(ms.toarray());
}
}
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号