-
Notifications
You must be signed in to change notification settings - Fork 89
use native nodejs webcrypto implementation #81
base: master
Are you sure you want to change the base?
Conversation
instead of one that depends on openssl
Thanks but it appears that this broke the hmac e2e gets |
So this exposed a fundamental flaw with the way things are architected. The TLDR is that libraries used by worker scripts (e.g. anything loaded via the Context) can't used |
A simplified example of the problem can be seen by running:
The above returns false when it should return true. |
Here's a better example of the issue.
|
I think I tried const password = 'test';
const plainText = 'foo';
const ptUtf8 = new TextEncoder().encode(plainText);
const pwUtf8 = new TextEncoder().encode(password);
const pwHash = await crypto.subtle.digest('SHA-256', pwUtf8);
const iv = crypto.getRandomValues(new Uint8Array(12));
const alg = { name: 'AES-GCM', iv: iv };
const encKey = await crypto.subtle.importKey('raw', pwHash, alg, false, ['encrypt']);
const encBuffer = await crypto.subtle.encrypt(alg, encKey, ptUtf8);
const decKey = await crypto.subtle.importKey('raw', pwHash, alg, false, ['decrypt']);
const ptBuffer = await crypto.subtle.decrypt(alg, decKey, encBuffer);
const plainText2 = new TextDecoder().decode(ptBuffer);
if (plainText !== plainText2) {
throw new Error(':(');
} |
instead of one that depends on openssl