相关疑难解决方法(0)

Microsoft Edge中的公钥加密

我有以下JavaScript代码使用Web Cryptography API实现公钥加密.它适用于Firefox和Chrome,但Microsoft Edge失败.我从Edge获得的错误是"由于错误80700011无法完成操作".我错过了什么?

<script>
    var data = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);

    var crypto = window.crypto || window.msCrypto;
    var cryptoSubtle = crypto.subtle;

    cryptoSubtle.generateKey(
        {
            name: "RSA-OAEP",
            modulusLength: 2048, 
            publicExponent: new Uint8Array([0x01, 0x00, 0x01]),
            hash: { name: "SHA-256" }, 
        },
        true, 
        ["encrypt", "decrypt"]
    ).then(function (key) { 
        console.log(key);
        console.log(key.publicKey);
        return cryptoSubtle.encrypt(
            {
                name: "RSA-OAEP"
            },
            key.publicKey,
            data
            );
    }).then(function (encrypted) { 
        console.log(new Uint8Array(encrypted));
    }).catch(function (err) {
        console.error(err);
    });
</script>
Run Code Online (Sandbox Code Playgroud)

encryption public-key-encryption webcrypto-api microsoft-edge

5
推荐指数
1
解决办法
803
查看次数

在 IE 11 中使用 SubtleCrypto

我试图让 SubtleCrypto 与 IE 11 一起工作。具体来说,我只是想简单地加密一些东西,让我开始,我已经能够为 AES-CBC 生成一个密钥,但是当我尝试做加密我收到一个错误:“类型不匹配错误”。

我有一个 JSFiddle:https ://jsfiddle.net/tuwzsyyp/

        try {
            //Asynchronous crypto
            window.msCrypto.subtle.generateKey(
                { name: 'AES-CBC', length: 256 },
                false,
                ['encrypt']
                )
                .oncomplete = function (key) {
                    try {
                        window.msCrypto.subtle.encrypt(
                            {
                                name: "AES-CBC",
                                iv: initialisationVector
                            },
                            key, //from generateKey or importKey above
                            new Uint16Array(currentArrayBuffer) //ArrayBuffer of data you want to encrypt
                            ).oncomplete = function (encrypted) {
                                alert(3 + "; " + new Uint16Array(encrypted));
                            };
                    } catch (err) {
                        alert(err);
                    }
                };
        } catch (err) {
            alert(err); …
Run Code Online (Sandbox Code Playgroud)

javascript

4
推荐指数
1
解决办法
2653
查看次数