File tree Expand file tree Collapse file tree
blog/26-04-26/x509-certificates-in-js---encrypt-decrypt-data/ex Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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 ) ;
You can’t perform that action at this time.
0 commit comments