cryptian icon indicating copy to clipboard operation
cryptian copied to clipboard

how to use with ecb mode without IV?

Open quanguyen opened this issue 5 years ago • 1 comments

Hi,

I am trying to port a code using MCrypt (which is now deprecated):

const pher = new MCrypt("rijndael-128", "ecb") // ECB, no IV

function encrypt(rawData, key) { pher.open(key) return pher.encrypt(rawData) // Buffer }

function decrypt(encData, key) { pher.open(key) return pher.decrypt(encData) // Buffer }

My cryptian code:

const {algorithm, mode} = require("cryptian") const aes128 = new algorithm.Rijndael128() const cipher = new mode.ecb.Cipher(aes128, null) // TypeError thrown: Value has got incorrect type. Should be Buffer or String.

function encrypt(rawData, key) { cipher.setKey(key) return cipher.encrypt(rawData) }

function decrypt(encData, key) { cipher.setKey(key) return cipher.decrypt(encData) }

How should I use cryptian with ecb mode without IV? I tried to search in examples but did not seem to find one.

Regards

quanguyen avatar Jan 20 '21 04:01 quanguyen

You can use buffer of zero bytes to skip IV. It is not recomended but It can use to be compatible with peer.

// zero bytes
const iv = Buffer.alloc(aes128.getBlockSize());

tugrul avatar Jan 20 '21 18:01 tugrul