Skip to content

Commit 4a0fda4

Browse files
save file
1 parent bd266a5 commit 4a0fda4

1 file changed

Lines changed: 3 additions & 23 deletions

File tree

blog/26-04-26/x509-certificates-in-js---encrypt-decrypt-data/ex/rsa-encrypt-decrypt-browser.js

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -39,27 +39,7 @@
3939

4040
}//extract_spki
4141

42-
async function pub_key(cert) {
43-
// Extract raw SPKI bytes without Node-specific modules
44-
const spki = extract_spki_der(cert);
45-
const buf = spki.buffer;
46-
47-
// Use the environment's global Web Crypto interface.
48-
// Note: We use globalThis.crypto to ensure we aren't accidentally
49-
// accessing a variable bound by a 'require' statement.
50-
const webCrypto = globalThis.crypto?.subtle || globalThis.crypto;
51-
52-
const importedKey = await webCrypto.importKey(
53-
'spki',
54-
buf,
55-
{ name: 'RSA-OAEP', hash: 'SHA-256' },
56-
true,
57-
['encrypt']
58-
);
59-
60-
return importedKey;
61-
}
62-
/*
42+
6343
async function pub_key(cert){
6444

6545
var spki = extract_spki(cert);
@@ -68,8 +48,8 @@ async function pub_key(cert) {
6848
return pub_key;
6949

7050
}//pub_key
71-
*/
72-
51+
52+
7353
async function encrypt(blob,cert){
7454

7555
var publicKey = await pub_key(cert);

0 commit comments

Comments
 (0)