小编Fen*_*ang的帖子

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
查看次数

Internet Explorer 11中的公钥加密

我正在尝试使用IE11的JavaScript通过以下代码实现公钥加密:

<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;

    var genOp = cryptoSubtle.generateKey(
        {
            name: "RSA-OAEP",
            modulusLength: 2048,
            publicExponent: new Uint8Array([0x01, 0x00, 0x01]),
            hash: { name: "SHA-256" },
        },
        true,
        ["encrypt", "decrypt"]
    );

    genOp.onerror = function (e) {
        console.error(e);
    };

    genOp.oncomplete = function (e) {
        var key = e.target.result;
        console.log(key);
        console.log(key.publicKey);

        var encOp = cryptoSubtle.encrypt(
            {
                name: "RSA-OAEP"
            },
            key.publicKey,
            data
        );

        encOp.onerror …
Run Code Online (Sandbox Code Playgroud)

encryption internet-explorer public-key-encryption internet-explorer-11 webcrypto-api

2
推荐指数
1
解决办法
1027
查看次数