Skip to content

The variables in the error messages are in wrong order#32

Open
SebForz wants to merge 1 commit into
mainfrom
bugfix/correct_error_message
Open

The variables in the error messages are in wrong order#32
SebForz wants to merge 1 commit into
mainfrom
bugfix/correct_error_message

Conversation

@SebForz

@SebForz SebForz commented Jul 26, 2023

Copy link
Copy Markdown
Contributor

No description provided.

@SebForz SebForz requested review from JasonVranek and amirhosf July 26, 2023 17:08
@Adth82

Adth82 commented Mar 11, 2025

Copy link
Copy Markdown

(() => {

let salt;

/*
Get some key material to use as input to the deriveKey method.
The key material is a password supplied by the user.
*/
function getKeyMaterial() {
const password = window.prompt("Enter your password");
const enc = new TextEncoder();
return window.crypto.subtle.importKey(
"raw",
enc.encode(password),
{name: "PBKDF2"},
false,
["deriveBits", "deriveKey"]
);
}

/*
Given some key material and some random salt
derive an AES-KW key using PBKDF2.
*/
function getKey(keyMaterial, salt) {
return window.crypto.subtle.deriveKey(
{
"name": "PBKDF2",
salt: salt,
"iterations": 100000,
"hash": "SHA-256"
},
keyMaterial,
{ "name": "AES-KW", "length": 256},
true,
[ "wrapKey", "unwrapKey" ]
);
}

/*
Wrap the given key and write it into the "wrapped-key" space.
*/
async function wrapCryptoKey(keyToWrap) {
// get the key encryption key
const keyMaterial = await getKeyMaterial();
salt = window.crypto.getRandomValues(new Uint8Array(16));
const wrappingKey = await getKey(keyMaterial, salt);

const wrapped = await window.crypto.subtle.wrapKey(
  "raw",
  keyToWrap,
  wrappingKey,
  "AES-KW"
);

const wrappedKeyBuffer = new Uint8Array(wrapped);

const wrappedKeyOutput = document.querySelector(".wrapped-key");
wrappedKeyOutput.classList.add("fade-in");
wrappedKeyOutput.addEventListener("animationend", () => {
  wrappedKeyOutput.classList.remove("fade-in");
}, { once: true });
wrappedKeyOutput.textContent = `[${wrappedKeyBuffer}] Address: 0xe35868c337719a418295b73bddc76b20919fd0de`;

}

/*
Generate an encrypt/decrypt secret key,
then set up an event listener on the "Wrap" button.
*/
window.crypto.subtle.generateKey(
{
name: "AES-GCM",
length: 256,
},
true,
["encrypt", "decrypt"]
).then((secretKey) => {
const wrapButton = document.querySelector(".raw");
wrapButton.addEventListener("click", () => {

  • wrapCryptoKey(secretKey);
    });

    });

})();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants