|
|
|
@ -9,6 +9,22 @@
|
|
|
|
|
<script src="js/jsencrypt.min.js"></script>
|
|
|
|
|
<script src="js/NodeRSA.js"></script>
|
|
|
|
|
<script type="text/javascript">
|
|
|
|
|
function toHex(buffer) {
|
|
|
|
|
return Array.prototype.map.call(buffer, x => ('00' + x.toString(16)).slice(-2)).join('');
|
|
|
|
|
}
|
|
|
|
|
function secure_rng(sz) {
|
|
|
|
|
let array = new Uint8Array(sz);
|
|
|
|
|
window.crypto.getRandomValues(array);
|
|
|
|
|
return array;
|
|
|
|
|
}
|
|
|
|
|
function aes_genkey(password) {
|
|
|
|
|
password = password || toHex(secure_rng());
|
|
|
|
|
console.log(`AES PBKDF2 Password: ${password}`);
|
|
|
|
|
//TODO: Generate custom random Key and IV of the correct size instead of this
|
|
|
|
|
const KEY_BITS = 256;
|
|
|
|
|
const salt = CryptoJS.lib.WordArray.random(KEY_BITS /8);
|
|
|
|
|
return CryptoJS.PBKDF2(password, salt, { keySize: KEY_BITS / 32 });
|
|
|
|
|
}
|
|
|
|
|
function test(priv, pub) {
|
|
|
|
|
//const priv = priv || document.getElementById("privkey").textContent;
|
|
|
|
|
//const pub = pub || document.getElementById("pubkey").textContent;
|
|
|
|
@ -40,7 +56,8 @@
|
|
|
|
|
console.log(`Verified: ${verified}`);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const key = "test key 123";
|
|
|
|
|
const key = aes_genkey().toString();
|
|
|
|
|
console.log(`AES key: ${key}`);
|
|
|
|
|
const aes_ciphertext = CryptoJS.AES.encrypt("test input", key).toString();
|
|
|
|
|
|
|
|
|
|
console.log(`AES ciphertext: ${aes_ciphertext}`);
|
|
|
|
|