//如需修改
byte[] salt = new byte[]
{
(byte) 0xA9, (byte) 0x9B, (byte) 0xC8, (byte) 0x32,
(byte) 0x56, (byte) 0x35, (byte) 0xE3, (byte) 0x03
};
int md5iterations = 19;
int segments = 1;
public string Decrypt(string cipherText,String key)
{
if (string.IsNullOrEmpty(cipherText))
return cipherText;
PKCSKeyGenerator crypto = new PKCSKeyGenerator(key, salt, md5iterations, segments);
ICryptoTransform cryptoTransform = crypto.Decryptor;
byte[] cipherBytes = System.Convert.FromBase64String(cipherText);
byte[] clearBytes = cryptoTransform.TransformFinalBlock(cipherBytes, 0, cipherBytes.Length);
return Encoding.UTF8.GetString(clearBytes);
}
public string Encrypt(string cipherText, String key)
{
if (string.IsNullOrEmpty(cipherText))
return cipherText;
PKCSKeyGenerator crypto = new PKCSKeyGenerator(key, salt, md5iterations, segments);
ICryptoTransform cryptoTransform = crypto.Encryptor;
byte[] cipherBytes =Encoding.UTF8.GetBytes( cipherText);
byte[] clearBytes = cryptoTransform.TransformFinalBlock(cipherBytes, 0, cipherBytes.Length);
return Convert.ToBase64String(clearBytes);
}
private void button1_Click(object sender, EventArgs e)
{
String key = "abcdefghijk";
String enc=Encrypt("120.52903", key);
String dec = Decrypt(enc, key);
}
C#版PBEWithMD5AndDES加解密.rar
需积分: 34 10 浏览量
2019-08-14
09:45:12
上传
评论 2
收藏 2KB RAR 举报
qq_16493821
- 粉丝: 0
- 资源: 9