如何输入密钥和初始化向量,包括具有OpenSSL的特殊字符

发布于 2025-02-13 16:45:00 字数 253 浏览 0 评论 0原文

我使用此命令解密文件,但它不起作用,因为我的密钥和初始化向量包括特殊字符,

openssl  enc  -nosalt   -aes-256-cbc  -d   -in input.json -out   output.json  -base64    -K qwr{@^h`h&_`50/ra7!'dvmh3!uw<&=? -iv 6/#~V).A,lY&=t5b

有人可以向我展示在哪里改进吗?

I use this command to decrypt the file but it does not work because my Key and Initialization Vector including special characters

openssl  enc  -nosalt   -aes-256-cbc  -d   -in input.json -out   output.json  -base64    -K qwr{@^h`h&_`50/ra7!'dvmh3!uw<&=? -iv 6/#~V).A,lY&=t5b

Can someone show me where to improve?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烏雲後面有陽光 2025-02-20 16:45:01

OPENSL想要这些-k-IV参数以十六进制编码的形式,可能是为了避免命令行解析问题。来自MAN OPENSL

     -iv IV  The actual IV (initialisation vector) to use: this must be represented as a string comprised
             only of hex digits.  When only the key is specified using the -K option, the IV must
             explicitly be defined.  When a password is being specified using one of the other options,
             the IV is generated from this password.

     -K key  The actual key to use: this must be represented as a string comprised only of hex digits.  If
             only the key is specified, the IV must also be specified using the -iv option.  When both a
             key and a password are specified, the key given with the -K option will be used and the IV
             generated from the password will be taken.  It probably does not make much sense to specify
             both key and password.

如何做到这一点,取决于您可以使用哪些工具。例如,如果您将键存储在文件key.raw中,则可以使用xxd -g1 -c32 -l32 -l32 -p key.raw生成它,例如:

$ xxd -g1 -c32 -l32 -p key.raw
7177727b405e686068265f6035302f726137212764766d68332175773c263d3f

一次编码一个字符(-G1),并在一行中抓住32个字节,避免在末尾意外编码newline字符。

您可以将其嵌入openssl命令中的-k $(xxd -g1 -c32 -c32 -l32 -p key.raw)。 IV参数类似。

openssl wants those -K and -iv parameters in hex-encoded form, probably to avoid problems with command line parsing. From man openssl:

     -iv IV  The actual IV (initialisation vector) to use: this must be represented as a string comprised
             only of hex digits.  When only the key is specified using the -K option, the IV must
             explicitly be defined.  When a password is being specified using one of the other options,
             the IV is generated from this password.

     -K key  The actual key to use: this must be represented as a string comprised only of hex digits.  If
             only the key is specified, the IV must also be specified using the -iv option.  When both a
             key and a password are specified, the key given with the -K option will be used and the IV
             generated from the password will be taken.  It probably does not make much sense to specify
             both key and password.

How you do that, depends on what tools are available to you. If for instance you have the key stored in a file key.raw then you can use xxd -g1 -c32 -l32 -p key.raw to generate it, like this:

$ xxd -g1 -c32 -l32 -p key.raw
7177727b405e686068265f6035302f726137212764766d68332175773c263d3f

That encodes it one character at a time (-g1), and grabs 32 bytes in one line, avoiding accidentally encoding a newline character at the end.

You can embed that in the openssl command as -K $(xxd -g1 -c32 -l32 -p key.raw). Similar for the IV parameter.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文