support jwk keys to encrypt
This commit is contained in:
parent
e2dd9b9f77
commit
e9324ad678
2 changed files with 6 additions and 4 deletions
|
@ -62,7 +62,7 @@ export async function encryptAttachment(platform, blob) {
|
|||
const iv = await crypto.aes.generateIV();
|
||||
const key = await crypto.aes.generateKey("jwk", 256);
|
||||
const buffer = await blob.readAsBuffer();
|
||||
const ciphertext = await crypto.aes.encryptCTR({key, iv, data: buffer});
|
||||
const ciphertext = await crypto.aes.encryptCTR({jwkKey: key, iv, data: buffer});
|
||||
const digest = await crypto.digest("SHA-256", ciphertext);
|
||||
return {
|
||||
blob: platform.createBlob(ciphertext, blob.mimeType),
|
||||
|
|
|
@ -199,17 +199,19 @@ class AESCrypto {
|
|||
}
|
||||
}
|
||||
|
||||
async encryptCTR({key, iv, data}) {
|
||||
async encryptCTR({key, jwkKey, iv, data}) {
|
||||
const opts = {
|
||||
name: "AES-CTR",
|
||||
counter: iv,
|
||||
length: 64,
|
||||
};
|
||||
let aesKey;
|
||||
const selectedKey = key || jwkKey;
|
||||
const format = jwkKey ? "jwk" : "raw";
|
||||
try {
|
||||
aesKey = await subtleCryptoResult(this._subtleCrypto.importKey(
|
||||
"raw",
|
||||
key,
|
||||
format,
|
||||
selectedKey,
|
||||
opts,
|
||||
false,
|
||||
['encrypt'],
|
||||
|
|
Reference in a new issue