首页 > 解决方案 > 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();
    }

标签: c#openssldesecb

解决方案


我发现答案 -p put into openssl 显示它正在转换我的十六进制输入。当我在 c# 中使用转换后的键时,它输出了正确的值


推荐阅读