【问题标题】:Encrypting using 64-bit DES with openssl使用 64 位 DES 和 openssl 进行加密
【发布时间】:2011-11-15 01:02:58
【问题描述】:

我正在尝试做一件非常简单的事情,即使用 64 位密码和 64 位明文(均为十六进制)并使用简单的旧 DES 对其进行加密。

我的脚本如下所示:

plaintext=`echo -n "$2" | sed 's/\(..\)/\\\x\1/g'`
key=$1
printf "$plaintext" | openssl enc -nosalt -e -des -nopad -K "$key" -iv "0000000000000000" | od --format=x1 --width=32 --address-radix=n | sed 's/ //g'

我执行并得到以下结果:

./des_enc 5B5A57676A56676E 675A69675E5A6B5A
b617e2c84a4fba2149dd7132433031392257b99d9284b1031c351c15825aca52

问题是从 openssl 返回的数据太多,我希望只获得 64 位数据而不是 512。我不知道如何显式请求 64 位版本的 DES,甚至可能吗?

注意:以上使用的值来自“H. Katzan, The Standard Data Encryption Algorithm, pp75-94, Petrocelli Books Inc., New York, 1977”:

Key:        5B5A57676A56676E
Plaintext:  675A69675E5A6B5A
Ciphertext: 974AFFBF86022D1F

【问题讨论】:

    标签: bash encryption openssl


    【解决方案1】:

    使用-des-ecb。此外,xxd 使这个管道更加干净,如果你有它方便的话(它是 vim 包的一部分):

    sh % echo 675A69675E5A6B5A | xxd -r -ps | openssl enc -des-ecb -nopad -K 5B5A57676A56676E | xxd -ps
    974affbf86022d1f
    

    【讨论】:

    • 效果很好,而且 xxd 提示确实使它更具可读性,谢谢!
    猜你喜欢
    • 2020-12-04
    • 2011-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多