我在使加密与从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();
}
我找到了答案-p放入openssl告诉我它正在转换我的十六进制输入。当我在c#中使用转换后的键时,它输出正确的值