openssl 命令行来加密 RC4,不是预期的结果,不明白

I a*_*ttt 5 encryption openssl rc4-cipher

这可能是一个愚蠢的问题,但我无法弄清楚。目前,我正在使用这个网站:http : //www.fyneworks.com/encryption/rc4-encryption/ 来加密 rc4 以获得概念证明。例如,我输入“a”作为明文,“a”作为密码,我得到“71”作为密文(这是“q”的ascii表示)。我想从命令行使用 openssl 做同样的事情:

> echo a | openssl rc4 -nosalt  -out /tmp/uuu 
enter rc4 encryption password:
Verifying - enter rc4 encryption password:

> cat /tmp/uuu | xxd
0000000: 5896                                     X.
Run Code Online (Sandbox Code Playgroud)

所以我们得到的是“5896”而不是“71”,这是我不明白的。如果有人可以向我解释,我将不胜感激。

谢谢 !

I a*_*ttt 5

感谢一位朋友,我们弄清楚出了什么问题。他让我打印钥匙

echo -ne "a" |  openssl  rc4 -pass pass:a -e  -nopad    -nosalt -p
key=0CC175B9C0F1B6A831C399E269772661
Run Code Online (Sandbox Code Playgroud)

我们看到添加了一些填充,我们在最后输入了 0x61。事实证明,openssl 从通行证中生成了一个密钥。

相反,如果我们使用 -K 选项直接输入密钥:

echo -ne "a" |  openssl  rc4 -K 61 -e  -nopad    -nosalt -p
key=61000000000000000000000000000000
Run Code Online (Sandbox Code Playgroud)

我们看到有一个带有“0”的填充。实际上,它不希望我们使用太小的密钥(因为对于 rc4,密钥必须至少有 40 位长)。现在,让我们尝试使用 128b 密钥:

echo -ne "foobar" |  openssl  rc4 -K "6162636465666768696A6B6C6D6E6F70" -e  -nopad    -nosalt  | xxd
0000000: caaf 2cbf d334                           ..,..4
Run Code Online (Sandbox Code Playgroud)

结果和网页上的一样:)


Wil*_*ord 0

工作正在进行中

这是一个有趣的模式。使用“0”作为加密密钥,我们在明文和密文之间得到了一些明显的趋势。见下文。

我对这两种实现之间的差异感兴趣的是 fyne 单调增加,而 OpenSSL 有点阶梯式增加。稍后我会再看一遍 - 我将其标记为社区维基,因为我还不认为这是一个答案,但我认为分析可能会有所帮助。

法恩:

0(0) = B8
0(1) = B9
0(2) = BA
0(3) = BB
0(4) = BC
0(5) = BD
0(6) = BE
0(7) = BF
0(8) = B0
0(9) = B1
Run Code Online (Sandbox Code Playgroud)

OpenSSL:

0(0) = 72
0(1) = 73
0(2) = 70
0(3) = 71
0(4) = 76
0(5) = 77
0(6) = 74
0(7) = 75
0(8) = 7A
0(9) = 7B
Run Code Online (Sandbox Code Playgroud)

使用的命令

cat -n N > /tmp/test #Where n is a number
openssl rc4 -e -nosalt -in /tmp/test -out /tmp/uuu
cat /tmp/uuu |xxd
Run Code Online (Sandbox Code Playgroud)