2017-01-30 8 views
1

私はTcllibからDES関数を使いたいですが、正しい方法で 変数を処理していないようです。TCL Tcllib DESの間違ったパラメータ?

set key DAAE57F813459B3B 
set key_b [binary format H* $key] 

set data 2D7A99F520D684B4 
set data_b [binary format H* $data] 

set result [DES::des -dir encrypt -key $key_b -hex $data_b] 

私は誤りだ、これらの値を使用して:「として

bad option "-z...": must be one of -chunksize, -dir, -hex, -in, -iv, -key, -mode, -out, -weak 

DES機能が解釈しているようだ '2Dを...' -zここ

コードです... '、したがってオプションとして(許可されない)。

私は値(キー< - >データ、< - >キー)を交換するときにエラーは発生しません。
また、データ1D ...、3D ...などを使用すると機能は正常に動作します。

私はTcllib V1.18とパッケージdes、sha1、pki、asn、aes、math :: bignum、md5、base64を使用しています。

誰かが、データをオプションとして解釈せずに、変数 'data'をDES関数に引き渡す方法を知っていますか?

答えて

1

DES::desコマンドのハイレベルドライバコードが、-(0x2D)バイトで始まるデータで混乱するという問題があります。これは報告可能なバグです。それを報告してください。

しかし、あなたはTcllibデパッケージに低レベルインタフェースを使用して、それを回避することができます。

package require des 

set key DAAE57F813459B3B 
set key_b [binary format H* $key] 

set data 2D7A99F520D684B4 
set data_b [binary format H* $data] 

# The [binary format] below is for the initialisation vector (IV) which should usually be 
# 64 zero bits to start with if you're using simple encryption. 
set d [DES::Init cbc $key_b [binary format I* {0 0}]] 
set encBytes [DES::Encrypt $d $data_b] 
DES::Final $d 

# We've got the bytes out; let's convert to hex for printing 

binary scan $encBytes H* encHex 
puts $encHex; # --> “4cd33892969591b4” 

逆方向に行くにはあまりにも非常に簡単です:

package require des 

set key DAAE57F813459B3B 
set key_b [binary format H* $key] 

set encHex 4cd33892969591b4 
set encBytes [binary format H* $encHex] 

set d [DES::Init cbc $key_b [binary format I* {0 0}]] 
set decBytes [DES::Decrypt $d $encBytes] 
DES::Final $d 

binary scan $decBytes H* decHex 
puts $decHex; # --> “2d7a99f520d684b4” 
+0

あなたの場合これを大いにしていると、コア暗号化/復号化を手続きで包むことはおそらく良い考えです。 '' DES :: des''が本当に何をするのかはそれほど違いはありませんが、もっと一般的な(そして - 明らかに - バギー) –

関連する問題