我正在使用此代码加密字节,我已经从 1-255 字节对其进行了测试,并且值大于 128 的每个字节都被解密为 63
AEK is a 16char string
public byte[] AE1024(byte[] __test)
{
byte[] data = __test;
byte[] rgbKey = ASCIIEncoding.ASCII.GetBytes(AEK.Substring(0, AEK.Length / 2));
byte[] rgbIV = ASCIIEncoding.ASCII.GetBytes(AEK.Substring(AEK.Length / 2, AEK.Length / 2));
MemoryStream memoryStream = new MemoryStream(1024);
DESCryptoServiceProvider desCryptoServiceProvider = new DESCryptoServiceProvider();
CryptoStream cryptoStream = new CryptoStream(memoryStream, desCryptoServiceProvider.CreateEncryptor(rgbKey, rgbIV), CryptoStreamMode.Write);
cryptoStream.Write(data, 0, data.Length);
cryptoStream.FlushFinalBlock();
byte[] result = new byte[(int)memoryStream.Position];
memoryStream.Position = 0;
memoryStream.Read(result, 0, result.Length);
cryptoStream.Close();
memoryStream.Dispose();
return result;
}
这是解密方法
public byte[] AD1024(byte[] __test)
{
byte[] data =__test;
byte[] rgbKey = ASCIIEncoding.ASCII.GetBytes(AEK.Substring(0, AEK.Length / 2));
byte[] rgbIV = ASCIIEncoding.ASCII.GetBytes(AEK.Substring(AEK.Length / 2, AEK.Length / 2));
MemoryStream memoryStream = new MemoryStream(data.Length+1);
DESCryptoServiceProvider desCryptoServiceProvider = new DESCryptoServiceProvider();
ICryptoTransform x = desCryptoServiceProvider.CreateDecryptor(rgbKey, rgbIV);
CryptoStream cryptoStream = new CryptoStream(memoryStream, x, CryptoStreamMode.Read);
memoryStream.Write(data, 0, data.Length);
memoryStream.Position = 0;
string decrypted = new StreamReader(cryptoStream).ReadToEnd();
cryptoStream.Close();
memoryStream.Dispose();
return Encoding.ASCII.GetBytes(decrypted);
}