【发布时间】:2017-05-17 21:07:31
【问题描述】:
我已经设法在 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;
};
};
生成的项目 (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);
然后我连接 oncomplete 和 onerror 和 onerror 触发。不幸的是,IE 的 Event 对象除了 type = "error" 之外什么也没有告诉我。
网上关于在 IE 11 中使用 AES-GCM 的信息非常少。
请不要告诉我使用其他浏览器。这一切都适用于 Chrome 和 Firefox(但不同)。我特别想让它在 IE 11 中工作。
我错过了什么?
【问题讨论】:
标签: javascript encryption internet-explorer-11 aes-gcm webcrypto-api