TCL Tcllib DES 参数错误?

TCL Tcllib DES wrong parameters?

我想使用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 函数?

问题是 DES::des 命令中的 high-level 驱动程序代码被以 - (0x2D) 字节开头的数据混淆了。这是一个可报告的错误;请举报。

但是您可以使用 Tcllib des 包中的 low-level 接口来解决它:

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”

使用开关结束标记“--”似乎也为我修复了这个错误(使用 des 1.1.0)。

set result [DES::des -dir encrypt -key $key_b -hex -- $data_b]
puts $result 
 => 4cd33892969591b4