JavaScript'hex'未知的行为

当试图传递一个hex值给节点js中的encryption密码时,我正在密文上得到一个空的返回,而在密文2上正确返回。 无法解释这两种情况之间有什么区别。

var secret = 'YmcNFa37DrT+0p10pnSpQSytWxlqNCyU'; var cipher = crypto.createCipher('des3', secret); var plaintext = '3b9ac9ff'; var ciphertext = cipher.update(plaintext, 'hex', 'hex'); var ciphertext2 = cipher.update('3b9ac9ff', 'hex', 'hex'); console.log(plaintext + ' , ' +ciphertext + ' , '+ ciphertext2); 

给我一个输出

 3b9ac9ff , , 0472620ba5ddf690 

发现问题。 指向@安德烈亚斯。

 var ciphertext = cipher.update(plaintext, 'hex', 'hex'); 

应该

 var ciphertext = cipher.update(plaintext, 'ascii', 'hex'); 

导致混淆的两个原因(虽然没有愚蠢的理由)1.节点js不会给你一个运行时exception。 相反,只是performance得很糟糕。 2.输出被允许作为hex使我相信,即使input将被允许。