// from http://www.movable-type.co.uk/scripts/aes.html var Aes = require("aes-ctr"); var password = "L0ck it up saf3"; var plaintext = "pssst ... đon’t tell anyøne!"; var ciphertext = Aes.Ctr.encrypt(plaintext, password, 256); var origtext = Aes.Ctr.decrypt(ciphertext, password, 256); // from Appendix C of http://csrc.nist.gov/archive/aes/index.html var cipher = [], key = [], i; for(i=0x1f; i>=0x10; --i) { key[i] = i; } for(i=0x0f; i>=0x00; --i) { key[i] = i; cipher[i] = i*0x11; } session.output.write( "\n"+ " Password: "+password +"\n"+ " Plaintext: "+plaintext +"\n"+ "Encrypted ...: "+ciphertext+"\n"+ "... Decrypted: "+origtext +"\n"+ "\n"+ "128-bit: "+_(Aes.cipher(cipher,Aes.keyExpansion(key.slice(0,16))))+"\n"+ "192-bit: "+_(Aes.cipher(cipher,Aes.keyExpansion(key.slice(0,24))))+"\n"+ "256-bit: "+_(Aes.cipher(cipher,Aes.keyExpansion(key )))+"\n"+ "\n" ); // convert byte array to hex string function _(a, /* aux. var */ b) { return (b = a.shift()) ? ("0"+b.toString(16)+' ').slice(b>=0x10) + _(a) : ""; }