如何使用 AES-GCM 从 IE 11 加密操作的结果中解密数据

How to decrypt data from the result of an IE 11 encrypt operation using AES-GCM

我已经在 Windows10 上使用 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 触发。不幸的是,除了 type = "error".

之外,IE 的 Event 对象没有什么可以告诉我的。

网上关于在 IE 11 中使用 AES-GCM 的信息非常少。

请不要告诉我使用不同的浏览器。这一切都适用于 Chrome 和 Firefox(但不同)。我特别想让它在 IE 11 中运行。

我错过了什么?

我发现这个 shim(模糊地)表明标签值进入算法对象,而密文单独进入第三个参数。例如

let decryptOp = window.msCrypto.subtle.decrypt({
    name: 'AES-GCM',
    iv: iv,
    additionalData: additionalData,
    tag: new Uint8Array(encResult.tag)
    }, key, new Uint8Array(encResult.ciphertext));

为什么这么难找?为什么没有关于此功能的博客文章?为什么 MS 的文档在细节上这么短?