Jam*_*lan 5 javascript encryption aes-gcm internet-explorer-11 webcrypto-api
我已经在Windows 10上使用IE 11设法使用AES-GCM加密了一些数据,但无法进行解密。加密JS代码示例:
let plainText = new Uint8Array([1]);
let key;
let keyBuf = window.msCrypto.getRandomValues(new Uint8Array(32));
let iv = window.msCrypto.getRandomValues(new Uint8Array(12));
let additionalData = window.msCrypto.getRandomValues(new Uint8Array(16));
let encResult;
let importOp = window.msCrypto.subtle.importKey('raw',
keyBuf,
{ name: 'AES-GCM' },
false,
['encrypt', 'decrypt']);
importOp.oncomplete = function(e) {
key = e.target.result;
let encryptOp = window.msCrypto.subtle.encrypt({
name: 'AES-GCM',
iv: iv,
tagLength: 128,
additionalData: additionalData
}, key, plainText);
encryptOp.oncomplete = function (e) {
encResult = e.target.result;
};
};
Run Code Online (Sandbox Code Playgroud)
结果项目(encResult)是AesGcmEncryptResult,它具有2个不同属性的加密值和标记。据我了解,我需要将它们连接起来,并将它们作为要解密的密文传递,如下所示:
let cipherText = new Uint8Array(plainText.length + 16); // tagLength / 8
cipherText.set(new Uint8Array(encResult.ciphertext), 0);
cipherText.set(new Uint8Array(encResult.tag), plainText.length);
let decryptOp = window.msCrypto.subtle.decrypt({
name: 'AES-GCM',
iv: iv,
tagLength: 128,
additionalData: additionalData
}, key, cipherText);
Run Code Online (Sandbox Code Playgroud)
然后,我连接oncomplete和onerror以及onerror火灾。不幸的是,除了type =“ error”之外,IE的Event对象什么也没告诉我。
IE 11中使用AES-GCM的网络信息很少。
请不要告诉我使用其他浏览器。所有这些在Chrome和Firefox上都可以正常工作(但有所不同)。我特别想让它在IE 11中正常工作。
我想念什么?
我发现此填充程序(模糊地)表明,标记值位于算法对象中,而密文仅位于第三个参数中。例如
let decryptOp = window.msCrypto.subtle.decrypt({
name: 'AES-GCM',
iv: iv,
additionalData: additionalData,
tag: new Uint8Array(encResult.tag)
}, key, new Uint8Array(encResult.ciphertext));
Run Code Online (Sandbox Code Playgroud)
为什么这么难找到?为什么没有关于此功能的博客文章?为什么MS的文档细节如此之短?
| 归档时间: |
|
| 查看次数: |
832 次 |
| 最近记录: |