Skip to content

Commit 6e1a166

Browse files
save file
1 parent 2d445fb commit 6e1a166

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ aes encrypt / decrypt browser
1919
var blob = new Blob(['hello world']);
2020

2121
var key = await generateAesKey();
22-
var encrypted = await aesEncrypt(key,'hello world');
22+
var encrypted = await aesEncrypt(key,blob);
23+
var b64 = blob_b64(encrypted);
2324
console.log('encrypted :');
24-
console.log(' iv :',enrypted.iv);
25-
console.log(' data :',encrypted.data);
25+
console.log(b64);
2626
console.log();
2727
var blob = await aesDecrypt(key,encrypted);
2828

@@ -84,7 +84,7 @@ aes encrypt / decrypt browser
8484

8585
buf = new Uint8Array(buf);
8686

87-
var blob = iv_buf_blob(iv,blob);
87+
var blob = iv_buf_blob(iv,buf);
8888
return blob;
8989

9090
}//aesEncrypt
@@ -116,12 +116,13 @@ aes encrypt / decrypt browser
116116
var uint8 = new Uint8Array(n);
117117
uint8.set(iv,0);
118118
uint8.set(buf,n1);
119-
return uint8;
119+
var blob = new Blob([uint8]);
120+
return blob;
120121

121122
}//iv_buf
122123

123124

124-
function blob_iv_buf(blob,iv_bits=96){
125+
async function blob_iv_buf(blob,iv_bits=96){
125126

126127
var n = blob.size;
127128
var buf = await blob.arrayBuffer();

0 commit comments

Comments
 (0)