function newcredentialblock (pass,key,fileiv) {
		var keyiv, hashkey, keyblock, enckeyblk,tblock;
		var buffer=new Uint8Array(96);
		var d=new Date();
		forge.random.collectInt(d.getTime(),32);
		
		//encrypt the iv-key combination (those used to encrypt file data)
		// and chop off the padding

		keyiv=forge.random.getBytesSync(16);
		hashkey=ivpasstokey(keyiv,pass);
		if (fileiv===undefined) fileiv=forge.random.getBytesSync(16);
		if (key===undefined) key=forge.random.getBytesSync(32);
		keyblock= fileiv+key;

		enckeyblk=cipherblock(hashkey,keyiv,keyblock).slice(0,48);

		//this appears to be no longer a problem when using decipherblock(,,,true)
		//i.e. dont finish(), and skip padding removal which we don't have
		tblock=decipherblock(hashkey,keyiv,enckeyblk,true);
		if (tblock != keyblock) {
			//console.log("failed to find keys and ivs that forge liked...");
			//console.log("keyblock=" + forge.util.bytesToHex(keyblock));
			return "";
		}

		//console.log("keyiv="+forge.util.bytesToHex(keyiv));console.log("hashkey=" + forge.util.bytesToHex(hashkey));console.log("keyblock=" + forge.util.bytesToHex(keyblock));console.log("fileiv=" + forge.util.bytesToHex(fileiv));console.log("key=" + forge.util.bytesToHex(key));console.log("aes-cbc enckeyblock  ="+forge.util.bytesToHex(enckeyblk));console.log("encrypted iv+key length=" + enckeyblk.length);

		// 16 + 48 + 32 bytes = 96 for entire record.
		copyToArray( ( keyiv+enckeyblk+hmacblock(hashkey,enckeyblk) )  ,buffer,0)
		return { buffer: buffer, key: key, fileiv: fileiv };
	}
/*  pass required, will generate key and fileiv if not provided                        */
pass required, will generate key and fileiv if not provided
pass required will generate key and fileiv if not provided
function newcredentialblock (pass,key,fileiv) {
		var keyiv, hashkey, keyblock, enckeyblk,tblock;
		var buffer=new Uint8Array(96);
		var d=new Date();
		forge.random.collectInt(d.getTime(),32);
		keyiv=forge.random.getBytesSync(16);
		hashkey=ivpasstokey(keyiv,pass);
		if (fileiv===undefined) fileiv=forge.random.getBytesSync(16);
		if (key===undefined) key=forge.random.getBytesSync(32);
		keyblock= fileiv+key;
		enckeyblk=cipherblock(hashkey,keyiv,keyblock).slice(0,48);
		tblock=decipherblock(hashkey,keyiv,enckeyblk,true);
		if (tblock != keyblock) {
			return "";
		}
		copyToArray( ( keyiv+enckeyblk+hmacblock(hashkey,enckeyblk) )  ,buffer,0)
		return { buffer: buffer, key: key, fileiv: fileiv };
	}
function newcredentialblock ( pass , key , fileiv ) { var keyiv , hashkey , keyblock , enckeyblk , tblock ; var buffer = new Uint8Array ( 96 ) ; var d = new Date ( ) ; forge . random . collectInt ( d . getTime ( ) , 32 ) ; keyiv = forge . random . getBytesSync ( 16 ) ; hashkey = ivpasstokey ( keyiv , pass ) ; if ( fileiv === undefined ) fileiv = forge . random . getBytesSync ( 16 ) ; if ( key === undefined ) key = forge . random . getBytesSync ( 32 ) ; keyblock = fileiv + key ; enckeyblk = cipherblock ( hashkey , keyiv , keyblock ) . slice ( 0 , 48 ) ; tblock = decipherblock ( hashkey , keyiv , enckeyblk , true ) ; if ( tblock != keyblock ) { return "" ; } copyToArray ( ( keyiv + enckeyblk + hmacblock ( hashkey , enckeyblk ) ) , buffer , 0 ) return { buffer : buffer , key : key , fileiv : fileiv } ; }
pass required, will generate key and fileiv if not provided
pass required will generate key and fileiv if not provided
//encrypt the iv-key combination (those used to encrypt file data) // and chop off the padding //this appears to be no longer a problem when using decipherblock(,,,true) //i.e. dont finish(), and skip padding removal which we don't have //console.log("failed to find keys and ivs that forge liked..."); //console.log("keyblock=" + forge.util.bytesToHex(keyblock)); //console.log("keyiv="+forge.util.bytesToHex(keyiv));console.log("hashkey=" + forge.util.bytesToHex(hashkey));console.log("keyblock=" + forge.util.bytesToHex(keyblock));console.log("fileiv=" + forge.util.bytesToHex(fileiv));console.log("key=" + forge.util.bytesToHex(key));console.log("aes-cbc enckeyblock  ="+forge.util.bytesToHex(enckeyblk));console.log("encrypted iv+key length=" + enckeyblk.length); // 16 + 48 + 32 bytes = 96 for entire record.