1
votes

I am trying to use Bookshelf-encrypted-columns for aes encrypt my data, for that I need key, and cipher. Key is not a problem but while creating "cipher" I am getting this error below:

"Error: Invalid cipher: 78c2527b394d0d4016571fea85e40c52"

Code below requires cipher:

bookshelf.plugin(encryptColumns, {
    cipher: getCipher(config.encrypt.aesKey),
    key: config.encrypt.aesKey
});

Function that creates cipher using nodejs crypto createCipheriv

function getCipher (key) { 
        // generate initialization vector
        let iv = new Buffer.alloc(16); // fill with zeros

        // encrypt data
        return crypto.createCipheriv('aes-256-cbc', key, iv);
}

Is there a solution to create cipher?

1

1 Answers

1
votes

The cipher value is supposed to be a string describing the algorithm to use, not an instance of a Cipher object.

For reference, see the default cipher value and the value passed to the plugin instantiation call for the unit tests.

In your code, try using this:

bookshelf.plugin(encryptColumns, {
    cipher: 'aes-256-cbc',
    key: config.encrypt.aesKey
});