ie11中的RSA-OEP加密

时间:2015-09-30 20:28:40

标签: javascript encryption rsa internet-explorer-11 webcryptoapi

我无法在IE11中找到任何RSA-OAEP加密的例子。

这是我实施的一个片段,我的错误很明显。



hg log -r "bisect(good) or bisect(bad)" --template "{rev}:{node|short} {bisect}\n"




当我将算法更改为RSAES-PKCS1-v1_5时,一切都完美无缺



function convertStringToArrayBufferView(str) {
      var bytes = new Uint8Array(str.length);
      for (var iii = 0; iii < str.length; iii++) {
        bytes[iii] = str.charCodeAt(iii);
      }

      return bytes;
    }

    
    var crypto = window.crypto || window.msCrypto;
    var config = {
      name: 'RSA-OAEP',
      modulusLength: 2048,
      publicExponent: new Uint8Array([0x01, 0x00, 0x01]),
      hash: {
        name: 'SHA-256'
      }
    };

    var keyOp = crypto.subtle.generateKey(config, false, ['encrypt', 'decrypt']);
    keyOp.onerror = function(e) {
      console.error(e);
    };
    keyOp.oncomplete = function(e) {
      encrypt(e.target.result);
    };

    function encrypt(keypair) {
      var data = "abc1234444"

      var encOp = crypto.subtle.encrypt({
        name: config.name,
        iv: config.iv || crypto.getRandomValues(new Uint8Array(16)),
        key: keypair.publicKey
      }, keypair.publicKey, convertStringToArrayBufferView(data));

      encOp.onerror = function(e) {
        console.error(e);
      };
      encOp.oncomplete = function(e) {
        console.log({
          data: new Uint8Array(e.target.result)
        });
      };
    }
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

此问题与Public key encryption in Internet Explorer 11

类似

在那里,@fenghuang需要“在调用加密调用时添加哈希字段”

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