【问题标题】:NodeJS crypto fails to correctly decrypt the one that was encrypted by some other toolsNodeJS 加密无法正确解密由其他一些工具加密的加密
【发布时间】:2019-08-19 16:29:22
【问题描述】:

我使用https://encode-decode.com/aes-256-ctr-encrypt-online/加密明文,然后使用nodejs crypto aes-2556-ctr算法解密,但它不返回原始文本。

纯文本:测试 密钥:12345678901234567890123456789012

使用https://encode-decode.com/aes-256-ctr-encrypt-online/的加密文本:D/EU6g==

以下是我在nodejs中使用的代码:

var crypto = require('crypto'),
    algorithm = 'aes-256-ctr',
    key = '12345678901234567890123456789012';

function encrypt(text){
    var cipher = crypto.createCipher(algorithm,key);
    var crypted = cipher.update(text,'uft8', 'base64');
    crypted += cipher.final('base64');
    return crypted;
}

function decrypt(text){
    var decipher = crypto.createDecipher(algorithm,key);
    var dec = decipher.update(text, 'base64', 'utf8');
    dec += decipher.final('utf8');
    return dec;
}

我还可以看到 nodejs encrypt 返回了我用来加密的工具的不同输出。

有人知道这里可能缺少什么吗?

【问题讨论】:

    标签: node.js cryptography


    【解决方案1】:

    使用 createCipheriv 对我有用。谢谢!

    【讨论】:

      猜你喜欢
      • 2018-07-04
      • 2019-04-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-04
      • 2019-11-04
      • 2012-05-08
      • 1970-01-01
      相关资源
      最近更新 更多