how to output the initialization vector in CBC mode here in javascript? 256 bit key is used here.
var blockSizeInBits = 128;
var keySizeInBits = 256;
function rijndaelEncrypt(plaintext, key, mode) {
var expandedKey, i, aBlock;
var bpb = blockSizeInBits / 8; // bytes per block
var ct; // ciphertext
if (!plaintext || !key)
return;
if (key.length*8 != keySizeInBits)
return;
if (mode == "CBC") {
ct = getRandomBytes(bpb); // get IV
//dump("IV", byteArrayToHex(ct));
} else {
mode = "ECB";
ct = new Array();
}
function encrypt(block, expandedKey) {
var i;
if (!block || block.length*8 != blockSizeInBits)
return;
if (!expandedKey)
return;
block = packBytes(block);
addRoundKey(block, expandedKey);
for (i=1; i<Nr; i++)
Round(block, expandedKey.slice(Nb*i, Nb*(i+1)));
FinalRound(block, expandedKey.slice(Nb*Nr));
return unpackBytes(block);
}
function Encrypt_Text(plaintext, keystr) {
if (keystr.length == 0) {
alert("Please specify a key.");
return "";
}
if (plaintext.length == 0) {
alert("Nothing to encrypt!");
return "";
}
setKey(keystr);
addEntropyTime();
prng = new AESprng(keyFromEntropy());
var v = "";
for(var i=0; i<plaintext.length % 16; i++) //pad with null to blocks of 16bytes
plaintext += '\0';
var ct = rijndaelEncrypt(plaintext, key, "CBC");
var hex_str = byteArrayToHex(ct);
var out_str = "";
hex_str = hex_str.split('');
for(var i=0; i<hex_str.length; i++) {
if(i % 64 == 0 && i > 0) out_str += '\n';
out_str += hex_str[i];
}
delete prng;
return out_str;
}
is here the initialization vector represents the 128-bit block of cipher text or random bits of plaintext?