digitalbazaar / forge

A native implementation of TLS in Javascript and tools to write crypto-based and network-heavy webapps
https://digitalbazaar.com/
Other
5.06k stars 784 forks source link

3DES-ECB encryption doesn't return any thing #628

Open smemamian opened 5 years ago

smemamian commented 5 years ago

Hi

this is my code:

    console.log('enc', enc())
    function enc() {
        var md = forge.md.md5.create();
        md.update('a');

        var key = md.digest().getBytes();

        //3DES-ECB requires 24byte of data and key returned from md5 is 16byte
        var k1 = key.substring(0, 8);
        var key1 = key + key1;

        var input = forge.util.createBuffer(forge.util.decode64('Yg=='));
        var decTer = forge.cipher.createDecipher('3DES-ECB', "40edae4bad0e5bf6d6c2dc56");
        decTer.start();
        decTer.update(input);

        console.log('decTer.output.getBytes()',decTer.output.getBytes().toString())
        return decTer.output.getBytes();
    }

but it doesn't return anything.

andersk commented 5 years ago

You forgot to call decTer.finish(), which in this case returns false because your input has invalid padding.