2011-09-07 107 views
3

我在使用RC4算法我的腳本(寫在bash)關於使用RC4使用十六進制密鑰文件的加密問題

關鍵是還以二進制格式加密的二進制文件

以下是我在做什麼:

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 /包和/ 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)轉換成格式

請你,請幫我出

回答

2

得到什麼OD是給你在格式:

od -t x1 | cut -d' ' -f2- | head -n -1 | tr "\n" ' ' | tr -d ' ' 

英文:得到十六進制轉儲,刪除每行的第一個字段(計數),切斷最後一行,將剩餘的換行符更改爲空格,然後刪除所有空格。

相關問題