2018-02-22 00:37:41 -08:00

29 lines
670 B
JavaScript

/**
* @requires asmcrypto.js
* @module crypto/cipher/aes
*/
import { AES_ECB } from 'asmcrypto.js';
// TODO use webCrypto or nodeCrypto when possible.
export default function aes(length) {
const c = function(key) {
this.key = Uint8Array.from(key);
this.encrypt = function(block) {
block = Uint8Array.from(block);
return Array.from(AES_ECB.encrypt(block, this.key, false));
};
this.decrypt = function(block) {
block = Uint8Array.from(block);
return Array.from(AES_ECB.decrypt(block, this.key, false));
};
};
c.blockSize = c.prototype.blockSize = 16;
c.keySize = c.prototype.keySize = length / 8;
return c;
}