Reputation: 105
I have this python 2.7 code with AES from Crypto.Cipher:
self.cipher_down = AES.new(key, AES.MODE_CFB, self.iv, segment_size=128)
How can I set cfb segment size (also known as feedback size) in node.js crypto lib? Here is my node.js snippet:
let cph = crypto.createCipheriv('aes-256-cfb', this.key, this.iv);
Upvotes: 2
Views: 497
Reputation: 49351
The crypto
module of NodeJS is based on OpenSSL and therefore uses the same names, see here. Whether a mode is supported in NodeJS depends therefore also on OpenSSL, see here.
OpenSSL and thus NodeJS append the number of bits n
encrypted per encryption step to the name, i.e. ...-cfbn
(e.g. aes-128-cfb8
). ...-cfb8
therefore corresponds to segment_size = 8
, with the exception of n = 128
or segment_size = 128
, which is simply referred to as ...-cfb
.
Since in Python n
must be a multiple of 8 (at least for PyCryptodome) there is no counterpart to ...-cfb1
.
There is a bug in the legacy PyCrypto library in the context of CFB mode that requires the plaintext to have a length that is an integer multiple of the segment length. Otherwise the following error occurs: Input strings must be a multiple of the segment size 16 in length.
Upvotes: 2