仅使用密钥和盐使用 OpenSSL 解密文本
Decrypt a text with OpenSSL using key and salt only
我想在 MacOS 的命令行中使用 32 个字符的密钥和盐来解密文本。我已经使用程序在 Windows 中对其进行了加密。但是,每当我尝试从命令行解密它时,我都无法并得到一个错误。
echo -n PuYNZO+SLqFo6g97gxKr2uAPRUph/sZgaJ3T5YIBPIc= | openssl enc -d -a -aes-256-cbc -K TheTestKeyUsedIs32CharactersLong -S 53616c7455736564 -iv 0 -p
hex string is too short, padding with zero bytes to length
hex string is too short, padding with zero bytes to length
non-hex digit
invalid hex key value
当我尝试加密时
100836
在 MacOS 中它给了我完全不同的字符串。
U2FsdGVkX19TYWx0VXNlZA4AWDWo5nzi8p5pYyAeUMg=
使用以下命令:
openssl enc -aes-256-cbc -a -S 53616c7455736564 -iter 5 -k TheTestKeyUsedIs32CharactersLong -in input.txt -out openssl_output.txt
来自我在 Windows
中使用的应用程序
100836
is converting into
PuYNZO+SLqFo6g97gxKr2uAPRUph/sZgaJ3T5YIBPIc=
- 我的 salt 文本是 SaltUsed
- 我的 32 位字符键是 TheTestKeyUsedIs32CharactersLong
- 输入为PuYNZO+SLqFo6g97gxKr2uAPRUph/sZgaJ3T5YIBPIc=
- 应该在100836
解密
但是,结果完全出乎意料。
我也试过 java 程序来解密它,但我得到了其他字符串,所以我想先用命令行更正它,然后再跳入代码。
我也尝试了十六进制数字密钥,但响应仍然不正确,与预期不符。
@Wasif 和我花了一些时间在聊天中进行调试,最终认为这很可能是 Windows 上的 OpenSSL 1.1.1.d
和 macOS 上的 OpenSSL 1.1.1.b
之间的兼容性问题。
我们进行了多次测试和排列,使用 (Key, IV)
十六进制元组,使用密码,有盐和没有盐,最终我们的测试归结为一个简单的检查。
在 Windows 上使用 openssl enc -a -aes-256-cbc -pass pass:MYPASSWORD -p -in input.txt
我们得到:
salt=E70092FEBA619144
key=29631452F8C259DFE6FD8E9372EC4B20392395F36B7A0B11769CEBEA987E90A0
iv =93BF2E94462A43B23EF585C0F4B3F1A8
U2FsdGVkX1/nAJL+umGRRGi3ybIPFXf7qrgov7SyXnI=
在 Mac 上使用 openssl aes-256-cbc -d -a -pass pass:MYPASSWORD -in cipherText.txt (which contains 'U2FsdGVkX1/nAJL+umGRRGi3ybIPFXf7qrgov7SyXnI='
我们得到:
4593573484:error:06FFF064:digital envelope routines:CRYPTO_internal:bad decrypt
尽管这个简单的测试失败了,Mac 和 Windows 盒子在本地成功加密和解密。
奇怪,这看起来像是版本不兼容。
尝试指定摘要算法:
默认摘要在不同版本之间发生了变化。
见
How to resolve the "EVP_DecryptFInal_ex: bad decrypt" during file decryption
我想在 MacOS 的命令行中使用 32 个字符的密钥和盐来解密文本。我已经使用程序在 Windows 中对其进行了加密。但是,每当我尝试从命令行解密它时,我都无法并得到一个错误。
echo -n PuYNZO+SLqFo6g97gxKr2uAPRUph/sZgaJ3T5YIBPIc= | openssl enc -d -a -aes-256-cbc -K TheTestKeyUsedIs32CharactersLong -S 53616c7455736564 -iv 0 -p
hex string is too short, padding with zero bytes to length
hex string is too short, padding with zero bytes to length
non-hex digit
invalid hex key value
当我尝试加密时
100836
在 MacOS 中它给了我完全不同的字符串。
U2FsdGVkX19TYWx0VXNlZA4AWDWo5nzi8p5pYyAeUMg=
使用以下命令:
openssl enc -aes-256-cbc -a -S 53616c7455736564 -iter 5 -k TheTestKeyUsedIs32CharactersLong -in input.txt -out openssl_output.txt
来自我在 Windows
中使用的应用程序100836 is converting into PuYNZO+SLqFo6g97gxKr2uAPRUph/sZgaJ3T5YIBPIc=
- 我的 salt 文本是 SaltUsed
- 我的 32 位字符键是 TheTestKeyUsedIs32CharactersLong
- 输入为PuYNZO+SLqFo6g97gxKr2uAPRUph/sZgaJ3T5YIBPIc=
- 应该在100836 解密
但是,结果完全出乎意料。
我也试过 java 程序来解密它,但我得到了其他字符串,所以我想先用命令行更正它,然后再跳入代码。
我也尝试了十六进制数字密钥,但响应仍然不正确,与预期不符。
@Wasif 和我花了一些时间在聊天中进行调试,最终认为这很可能是 Windows 上的 OpenSSL 1.1.1.d
和 macOS 上的 OpenSSL 1.1.1.b
之间的兼容性问题。
我们进行了多次测试和排列,使用 (Key, IV)
十六进制元组,使用密码,有盐和没有盐,最终我们的测试归结为一个简单的检查。
在 Windows 上使用 openssl enc -a -aes-256-cbc -pass pass:MYPASSWORD -p -in input.txt
我们得到:
salt=E70092FEBA619144
key=29631452F8C259DFE6FD8E9372EC4B20392395F36B7A0B11769CEBEA987E90A0
iv =93BF2E94462A43B23EF585C0F4B3F1A8
U2FsdGVkX1/nAJL+umGRRGi3ybIPFXf7qrgov7SyXnI=
在 Mac 上使用 openssl aes-256-cbc -d -a -pass pass:MYPASSWORD -in cipherText.txt (which contains 'U2FsdGVkX1/nAJL+umGRRGi3ybIPFXf7qrgov7SyXnI='
我们得到:
4593573484:error:06FFF064:digital envelope routines:CRYPTO_internal:bad decrypt
尽管这个简单的测试失败了,Mac 和 Windows 盒子在本地成功加密和解密。
奇怪,这看起来像是版本不兼容。
尝试指定摘要算法:
默认摘要在不同版本之间发生了变化。
见 How to resolve the "EVP_DecryptFInal_ex: bad decrypt" during file decryption