|
|
@ -82,7 +82,20 @@ CBC.pkcs7pad = function(buf, blocksize) { |
|
|
|
var padbytesize = bytesize - buf.length; |
|
|
|
var pad = new Buffer(padbytesize); |
|
|
|
pad.fill(padbytesize); |
|
|
|
return Buffer.concat([buf, pad]); |
|
|
|
var paddedbuf = Buffer.concat([buf, pad]); |
|
|
|
return paddedbuf; |
|
|
|
}; |
|
|
|
|
|
|
|
CBC.pkcs7unpad = function(paddedbuf, blocksize) { |
|
|
|
var bytesize = blocksize / 8; |
|
|
|
var padbytesize = bytesize - paddedbuf.length; |
|
|
|
var padlength = paddedbuf[paddedbuf.length - 1]; |
|
|
|
var padbuf = paddedbuf.slice(paddedbuf.length - padlength, paddedbuf.length); |
|
|
|
var padbuf2 = new Buffer(padlength); |
|
|
|
padbuf2.fill(padlength); |
|
|
|
if (padbuf.toString('hex') !== padbuf2.toString('hex')) |
|
|
|
throw new Error('invalid padding'); |
|
|
|
return paddedbuf.slice(0, paddedbuf.length - padlength); |
|
|
|
}; |
|
|
|
|
|
|
|
CBC.xorbufs = function(buf1, buf2) { |
|
|
|