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

问题描述 投票:0回答:1

尝试使用密码加密 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 
javascript node.js encryption cryptojs
1个回答
0
投票

错字。要列出所有可用的密码

const { getCiphers, } = require('node:crypto');

console.log(getCiphers()); // ['aes-128-cbc', 'aes-128-ccm', ...]

© www.soinside.com 2019 - 2024. All rights reserved.