【问题标题】:How to decrypt data from the result of an IE 11 encrypt operation using AES-GCM如何使用 AES-GCM 从 IE 11 加密操作的结果中解密数据
【发布时间】: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


    【解决方案1】:

    我发现这个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 的文档在细节上这么短?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-02-18
      • 1970-01-01
      • 1970-01-01
      • 2017-10-21
      • 2020-07-03
      • 1970-01-01
      • 2023-01-31
      相关资源
      最近更新 更多