Skip to content

AES-ECB decryption error - tmp.length is not a function #552

@karthage-spartacus

Description

@karthage-spartacus

Hi,
I'm trying to use the AES_ECB decryption as mentionned in the doc.
the key is a string (the key is 256bit long) in a file and the encrypted data is also in an other file.
These were generated with openSsl.
forge keep throwing the same error which is

TypeError: tmp.length is not a function at forge.aes.Algorithm.initialize (path_to_app/node_modules/node-forge/lib/aes.js:203:19)
at new forge.cipher.BlockCipher (path_to_app/node_modules/node-forge/lib/cipher.js:118:18)
at Object.forge.cipher.createDecipher (path_to_app/node_modules/node-forge/lib/cipher.js:75:10)
at Object.<anonymous> (path_to_app/main.js:179:29)

and there's the code

const fs = require('fs')
const forge = require('node-forge')
let aes_key = fs.readFileSync(AES_KEY_PATH, 'utf8')
let encrypted = fs.readFileSync('test/a.encrypted.jpg', 'utf8')
let decipher = forge.cipher.createDecipher('AES-ECB', aes_key)
decipher.mode.unpad = false;
decipher.start(); //line 179, where the error is thrown
decipher.update(forge.util.createBuffer(encrypted));
decipher.finish();
let decrypted = decipher.output.getBytes();
fs.writeFileSync('test/a.decrypted.jpg', decrypted)

Could you tell me what i'm doing wrong ? Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions