2

我正在编写一个程序来与另一个用 python 编写的程序交互。我发现加密的结果是不同的。

在 ghci 中,使用 HsOpenSSL,加密结果是\GS\n\197:

import OpenSSL
import OpenSSL.EVP.Cipher 
import Data.Maybe
method <- fmap fromJust $ withOpenSSL $ getCipherByName "bf-cfb"
cipher method "\x90\x01\x50\x98\x3c\xd2\x4f\xb0\xd6\x96\x3f\x7d\x28\xe1\x7f\x72" "\xcc\x88\xa5\x26\x85\xaf\x7f\x8d" Encrypt "abcd"

在python中,加密的结果是K\x10<Q

import M2Crypto
M2Crypto.EVP.Cipher("bf_cfb", "\x90\x01\x50\x98\x3c\xd2\x4f\xb0\xd6\x96\x3f\x7d\x28\xe1\x7f\x72", "\xcc\x88\xa5\x26\x85\xaf\x7f\x8d", 1).update("abcd")

在 shell 中,abcd.txt包含字符串“abcd”,abcd.bin在 vi​​m 中显示为K^P<Q}

openssl bf-cfb -in abcd.txt -out abcd.bin -pass pass:abc -K 900150983cd24fb0d6963f7d28e17f72 -iv cc88a52685af7f8d -nosalt

我假设 M2Crypto 结果等同于命令行结果,为什么 HsOpenSSL 结果不同?

4

0 回答 0