使用openssl命令行加密字符串 [英] Encrypt a string using openssl command line
问题描述
我有一个16字节的字符,我想使用openssl加密成16字节的加密字符串.
I have a 16 byte character that I would like to encrypt using openssl into a 16 byte encrypted string.
然后需要将此加密的字符串(人类可读格式)提供给使用它的用户,然后将该字符串解密为原始的16字节格式以进行比较和认证.任何人都可以告诉我,使用openssl命令行怎么可能.
This encrypted string ( in human readable format ) then needs to be supplied to a user who would use it, and the string would be decrypted to its original 16-byte form for comparison and authentication. Could anyone please tell me how this would be possible with openssl commandline.
先谢谢了.
推荐答案
这是在命令行上使用openssl加密字符串的一种方法(必须输入两次密码):
Here's one way to encrypt a string with openssl on the command line (must enter password twice):
echo -n "aaaabbbbccccdddd" | openssl enc -e -aes-256-cbc -a -salt
enter aes-256-cbc encryption password:
Verifying - enter aes-256-cbc encryption password:
输出内容如下:
U2FsdGVkX1/6LATntslD80T2HEIn3A0BqxarNfwbg31D2kI00dYbmBo8Mqt42PIm
据我所知,您无法控制输出的字节数.您可以对其进行b64或十六进制编码,仅此而已.另外,如果要将该字符串保存到文件而不是stdout中,请使用-out选项.
To my knowledge, you can't control the number of bytes out. You can b64 or hex encode it, but that's about it. Also, if you want to save that string to a file rather than stdout, use the -out option.
这篇关于使用openssl命令行加密字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!