Esempio n. 1
0
ECBMode.prototype.updateDecrypt = function(src) {
  // Pad the source with the last bytes from last update
  if(this.lastBytes != null && this.lastBytes.length > 0) {
    src = this.lastBytes + src;
  }
  
  // Chop of the last block to ensure we can remove padding if existing
  if(src.length > this.blockSize) {
    this.lastBytes = src.substr(src.length - this.blockSize);
    src = src.substr(0, src.length - this.blockSize);
    return util.arrayToBinaryString(this.decrypt(src, true));
  } else {
    // Less than the blocksize pad it
    return util.arrayToBinaryString(this.decrypt(src));    
  }
}
Esempio n. 2
0
ECBMode.prototype.updateEncrypt = function(src) {
  // Left over bytes if any
  var leftOverBytes = src.length % this.blockSize;
  // If we have leftover bytes encrypt up to the blocksize available and save the leftover bytes for the final
  if(leftOverBytes > 0) {
    this.lastBytes = src.substr(src.length - leftOverBytes);
    src = src.substr(0, src.length - leftOverBytes);
  } else {
    this.lastBytes = "";
  }
    
  return util.arrayToBinaryString(this.encrypt(src, true));
}
Esempio n. 3
0
ECBMode.prototype.finalEncrypt = function() {
  return util.arrayToBinaryString(this.encrypt(this.lastBytes));
}