关于使用 RC4 使用十六进制密钥加密文件的问题
我必须使用 RC4 算法为我的脚本加密一个二进制文件(用 bash 编写)
密钥也是二进制格式
以下是我正在做的事情:
echo -n -e $bPacketh > /tmp/packet
echo -n -e $clientWriteKeyb > /tmp/cwkey
mach=`openssl dgst -binary -hmac -md5 /tmp/cwkey /tmp/packet`
pkth=`openssl enc -e -rc4 -K /tmp/cwkey -in /tmp/packet`
/tmp/packet 和 /tmp/cwkey 的内容如下:
>cat /tmp/packet | od -t x1
0000000 86 09 94 8b cf 2d d3 99 94 9f 72 60 dd 3f a6 b6
0000020 01 00 00 00 13 0b 05 00 00 00 0c 73 73 68 2d 75
0000040 73 65 72 61 75 74 68 22 68 fb ab 5e 4d 1b 2b 61
0000060 bd 38
0000062
>cat /tmp/cwkey | od -t x1
0000000 5d c5 45 a8 2b 44 5d 2f 49 67 f5 71 73 a8 51 5c
0000020
MAC计算命令成功,但加密包计算命令出现以下错误:
>openssl enc -e -rc4 -K /tmp/cwkey -in /tmp/packet
non-hex digit
invalid hex key value
我通过论坛搜索,发现密钥的格式应该是“0001020304...”,但我不知道如何转换我的密钥(上面的/tmp/cwkey)为该格式
请求您帮助我
I am having to encrypt a binary file using RC4 algorithm for my script (written in bash)
The key is also in binary format
The following is what I am doing:
echo -n -e $bPacketh > /tmp/packet
echo -n -e $clientWriteKeyb > /tmp/cwkey
mach=`openssl dgst -binary -hmac -md5 /tmp/cwkey /tmp/packet`
pkth=`openssl enc -e -rc4 -K /tmp/cwkey -in /tmp/packet`
The contents of /tmp/packet and /tmp/cwkey are as follows:
>cat /tmp/packet | od -t x1
0000000 86 09 94 8b cf 2d d3 99 94 9f 72 60 dd 3f a6 b6
0000020 01 00 00 00 13 0b 05 00 00 00 0c 73 73 68 2d 75
0000040 73 65 72 61 75 74 68 22 68 fb ab 5e 4d 1b 2b 61
0000060 bd 38
0000062
>cat /tmp/cwkey | od -t x1
0000000 5d c5 45 a8 2b 44 5d 2f 49 67 f5 71 73 a8 51 5c
0000020
The MAC calculation command succeeds, but the encrypted packet calculation command gives the following error:
>openssl enc -e -rc4 -K /tmp/cwkey -in /tmp/packet
non-hex digit
invalid hex key value
I searched through forums and found that the format of key should be "0001020304..." but I am not sure how to convert my key (/tmp/cwkey above) to that format
Request you to please help me out
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要获得 od 以这种格式给出的内容:
用英语:获取十六进制转储,剪切掉每行的第一个字段(计数),剪切掉最后一行,将剩余的换行符更改为空格,然后删除所有空间。
To get what od is giving you in that format:
In English: get the hex dump, cut out the first field of each line (the count), cut off the last line, change the remaining newlines to spaces, and then remove all the spaces.