c# - C# DES ECB 加密 OpenSSL
问题描述
我在让我的加密与我从 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 put into openssl 显示它正在转换我的十六进制输入。当我在 c# 中使用转换后的键时,它输出了正确的值
推荐阅读
- makefile - 如何使用 $(info) 打印前导空格
- python - 填充 xarray 数据数组中缺少的索引位置
- python - 如何检查用户是否登录?烧瓶
- javascript - 通过使用JS单击按钮来显示div
- php - 服务帐户 - 上传的 PPTX 文件未显示在我的 Google 云端硬盘中
- embedded - 如何在 ESP32-S2 内部 ROM 中写入数据?
- apache-kafka - 在流应用程序中至少使用一次处理时,是否可以在 kafka 状态存储中丢失状态
- vue.js - Vuetify 自定义表单验证显示错误 _this.$refs[f].validate 不是函数
- testing - 带有网页界面的 SoupUI
- python - 如何将数据框转换为带有列表键的字典?