使用 openssl 命令行加密字符串 [英] Encrypt a string using openssl command line

查看:24
本文介绍了使用 openssl 命令行加密字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆