NodeJS 使用加密模块获取未知密码?

vu8f3i0k  于 5个月前  发布在  Node.js
关注(0)|答案(1)|浏览(45)

试图加密AES-256使用密码,但它是抛出错误未知密码任何想法是什么在下面的代码丢失.
index.js

function paymenIdEncryption(specialtyID,paymentId) {
            const convertToString = `${paymentId}_${specialtyID}`;
            const secret_key = "EiE0BVQle0xFjZvYOupKjHJKAcAwBaTjlZ7G7rryNos=";
            const iv = crypto.randomBytes(16);
    
            const cipher = crypto.createCipheriv('aes-256-cbs', Buffer.from(secret_key, 'base64'), iv);
            let encrypted = cipher.update(Buffer.from(convertToString, 'utf-8'));
            encrypted = Buffer.concat([encrypted, cipher.final()]);

            const encryptedData = {
          iv: iv.toString('base64'),
          encrypted: encodeURIComponent(encrypted),
      }

    return encryptedData;;
        }
    
    console.log(paymenIdEncryption(13780298 ,"8018928"))

字符串
错误:

'Error: Unknown cipher\n    at Cipheriv.createCipherBase (node:internal/crypto/cipher:116:19)\n    at Cipheriv.createCipherWithIV (node:internal/crypto/cipher:135:3)\n    at new Cipheriv (node:internal/crypto/cipher:243:3)\n    at Object.createCipheriv (node:crypto:138:10)\n

cwdobuhd

cwdobuhd1#

键入错误。要列出所有可用的密码,请执行以下操作:
const { getCiphers,} = require('node:crypto');
console.log(getCiphers()); //调用'aes-128-cbc','aes-128-ccm',.]

相关问题