Sha256: b9f0d4864c76699b8451ecb6a23c47b0deaf7c7eb3e06fb24509418f7446cc83
Contents?: true
Size: 1.33 KB
Versions: 19
Compression:
Stored size: 1.33 KB
Contents
/** * CBCMode * * An ActionScript 3 implementation of the CBC confidentiality mode * Copyright (c) 2007 Henri Torgemane * * See LICENSE.txt for full license information. */ package com.hurlant.crypto.symmetric { import flash.utils.ByteArray; /** * CBC confidentiality mode. why not. */ public class CBCMode extends IVMode implements IMode { public function CBCMode(key:ISymmetricKey, padding:IPad = null) { super(key, padding); } public function encrypt(src:ByteArray):void { padding.pad(src); var vector:ByteArray = getIV4e(); for (var i:uint=0;i<src.length;i+=blockSize) { for (var j:uint=0;j<blockSize;j++) { src[i+j] ^= vector[j]; } key.encrypt(src, i); vector.position=0; vector.writeBytes(src, i, blockSize); } } public function decrypt(src:ByteArray):void { var vector:ByteArray = getIV4d(); var tmp:ByteArray = new ByteArray; for (var i:uint=0;i<src.length;i+=blockSize) { tmp.position=0; tmp.writeBytes(src, i, blockSize); key.decrypt(src, i); for (var j:uint=0;j<blockSize;j++) { src[i+j] ^= vector[j]; } vector.position=0; vector.writeBytes(tmp, 0, blockSize); } padding.unpad(src); } public function toString():String { return key.toString()+"-cbc"; } } }
Version data entries
19 entries across 19 versions & 4 rubygems