Skip to content

Commit

Permalink
Remove legacy mode setting + unnecessary padding functions
Browse files Browse the repository at this point in the history
crypto's createCipheriv / createDecipheriv handle the padding for you
  • Loading branch information
Jan Winter committed Aug 2, 2021
1 parent 606dc1a commit 1331afb
Showing 1 changed file with 0 additions and 12 deletions.
12 changes: 0 additions & 12 deletions lib/RNCryptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

switch(version) {
case 3:
settings.mode = 'cbc';
settings.options = 1;
settings.hmac.includes_header = true;
settings.hmac.algorithm = 'sha256';
Expand Down Expand Up @@ -108,11 +107,6 @@
return crypto.createHmac(_settings.hmac.algorithm, hmac_key).update(hmac_message).digest();
};

var _strip_pkcs7_padding = function(plain_text) {
var pad_length = plain_text.slice(-1).toString().charCodeAt();
return plain_text.slice(0, plain_text.length - pad_length);
};

var _generate_initialized_components = function(version) {
return {
headers: {
Expand Down Expand Up @@ -148,12 +142,6 @@
return Buffer.concat([data, hmac]).toString('base64');
};

var _add_pkcs7_padding = function (plain_text, block_size) {
var pad_size = block_size - (plain_text.length % block_size);
var padding = new Buffer(new Array(pad_size + 1).join(String.fromCharCode(pad_size)), 'binary');
return Buffer.concat([plain_text, padding]);
};

var RNCryptor = {};

RNCryptor.GenerateKey = _generate_key;
Expand Down

0 comments on commit 1331afb

Please sign in to comment.