如何使用AES-GCM从IE 11加密操作的结果中解密数据 [英] How to decrypt data from the result of an IE 11 encrypt operation using AES-GCM

查看:438
本文介绍了如何使用AES-GCM从IE 11加密操作的结果中解密数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经设法使用AES-GCM在Windows 10上使用IE 11加密了一些数据,但是我无法使解密工作。示例加密JS代码:

I've managed to encrypt some data with AES-GCM using IE 11 on Windows 10 but I can't get decryption to work. Example encryption JS code:

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个不同属性。据我了解,我需要连接这些密码并将其作为解密密码传递,如:

The resulting item (encResult) is an AesGcmEncryptResult, which has the encrypted value and the tag in 2 different properties. As I understand it, I need to concatenate these and pass them as the cipher text to decrypt, as in:

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 fire。不幸的是,IE的Event对象没有什么可以告诉我的,而不是type =error。

I then wire up oncomplete and onerror and onerror fires. Unfortunately, IE's Event object has nothing to tell me, other than type = "error".

在IE 11中使用AES-GCM的网络信息很少。

There is very little information on the web on using AES-GCM in IE 11.

请不要告诉我使用其他浏览器。 Chrome和Firefox都能正常工作(但不同)。我正在试图让它在IE 11中工作。

Please don't tell me to use a different browser. This all works fine (but differently) with Chrome and Firefox. I'm specifically trying to get this to work in IE 11.

我缺少什么?

推荐答案

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

I found this shim that (vaguely) shows that the tag value goes in the algorithm object and the cipher text alone goes in the third argument. E.g.

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

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

Why was this so hard to find? Why are there no blog posts about this feature? Why are MS's docs so short on details?

这篇关于如何使用AES-GCM从IE 11加密操作的结果中解密数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆