【发布时间】:2019-09-27 21:13:44
【问题描述】:
我无法让我的加密与我从 OpenSSL 中获得的内容相匹配。 Mk.bin文件中的输入是一个十六进制值CA46E5A885D1E016150B5B64ECC11A43
以下是我的 openssl 命令:
openssl.exe enc -des-ecb -in C:\OpenSSL\Mk.bin -out C:\OpenSSL\MkOut.bin -nosalt -k TestKey0
我尝试匹配的 C# 函数是:
public static byte[] EncryptDES(byte[] clearData, byte[] key)
{
DES desEncrypt = new DESCryptoServiceProvider();
desEncrypt.Mode = CipherMode.ECB;
desEncrypt.Key = key;
ICryptoTransform transForm = desEncrypt.CreateEncryptor();
MemoryStream encryptedStream = new MemoryStream();
CryptoStream cryptoStream = new CryptoStream(encryptedStream, transForm, CryptoStreamMode.Write);
cryptoStream.Write(clearData, 0, clearData.Length);
cryptoStream.FlushFinalBlock();
return encryptedStream.ToArray();
}
【问题讨论】: