使用 openssl 加密 Apple 的 HTTP Live Streaming - 问题
这是当 static.key
包含我的随机密钥时我的 shell 脚本的代码。
hexKey=$(cat static.key | hexdump -e '16/1 "%02x"')
echo $hexKey
hexIV="0"
echo $hexIV
openssl aes-128-cbc -e -in logo-1.ts -out logo-enc-1.ts -p -nosalt -K ${he-iv ${hexIV}
我在运行时遇到一些错误。
(output:
non-hex digit
invalid hex iv value
: command not found
)
也许有人知道这个问题。我已经连续几天了。
This is my code of my shell script when static.key
contains my random key.
hexKey=$(cat static.key | hexdump -e '16/1 "%02x"')
echo $hexKey
hexIV="0"
echo $hexIV
openssl aes-128-cbc -e -in logo-1.ts -out logo-enc-1.ts -p -nosalt -K ${he-iv ${hexIV}
I get some error when running it.
(output:
non-hex digit
invalid hex iv value
: command not found
)
Maybe someone knows the problem. I'm on it for days now.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
该错误意味着 OpenSSL 看到的 IV 值包含非十六进制字符(即 0123456789abcdefABCDEF 以外的字符)。
AES128 密钥为
128/8 = 16
字节,因此密钥应有 32 个字符。 IV 为 16 个字节,对应于 AES 块大小,OpenSSL 将为您将单个“0”转换为 16 个零字节。这是一个好的命令的示例:现在将 IV 的最后一个字符替换为非十六进制字符,您会看到与所得到的错误相同。
如果您粘贴的是您正在运行的真实代码,那么问题就很明显了。首先,
-K ${he-iv ${hexIV}
是什么意思?其次,参数-K
是给出密钥。您缺少-iv
来提供 IV。你甚至缺少一个右大括号。假设
static.key
有 16 个字节,这可能会解决您的问题:作为最后一个提示,如果您使用的是 bash,请使用
-x
作为参数运行脚本bash ,它会在扩展变量后打印它执行的每一行,以便您可以准确地看到它在做什么:That error means that the value OpenSSL sees for the IV contains a non-hexadecimal character (i.e., something other than 0123456789abcdefABCDEF).
An AES128 key is
128/8 = 16
bytes, so you should have 32 characters for the key. An IV is 16 bytes, corresponding to the AES block size, and OpenSSL will covert a single "0" into 16 zero bytes for you. This is an example of a good command:Now replace the last character of the IV with a non-hex character, and see that you get the same error you're getting.
If what you've pasted is the real code you're running, the problem is obvious. First, what is
-K ${he-iv ${hexIV}
supposed to mean? Second, the argument-K
is to give the key. You're missing-iv
to give the IV. You're even missing a closing brace.This will probably fix your problem assuming
static.key
has 16 bytes:As a last tip, if you're using bash, run your script with
-x
as the argument to bash and it will print every line it executes after it expands the variables so you can see exactly what it's doing:在 bash shell 中存储键值的过程中,包含了一些尾随垃圾(空值或换行符),这些垃圾被传递给 openssl 并导致它抱怨非十六进制字符。
要修复 128 位/32 个 ascii 字符十六进制键和 IV 的问题,请告诉 bash 仅传递前 32 个字符,如下所示(对于其他键或 iv 长度,将值从 32 更改为键中位数的 1/4 或iv)
要验证是否传递了正确的值,请使用 openssl 的“打印键”-P 选项(注意大写“-P”)
In the process of storing the key value in the bash shell, some trailing garbage got included (either a null or newline) which is being passed to openssl and causing it to complain about non hex characters.
To fix this for 128 bit / 32 ascii character hex keys and IVs, tell bash to pass ONLY the first 32 characters like this (for other key or iv lengths change the value from 32 to 1/4 the number of bits in the key or iv)
To verify that the correct values are being passed, use openssl's 'print keys' -P option (note UPPER CASE "-P")
我一直在努力解决这个问题,基本上我找到了这个解决方案:
加密:
解密:
我希望它有用
I have been struggling with this, basically I found this solution:
Encrypt:
Decrypt:
I hope it can be useful