3

IE11 で RSA-OAEP 暗号化の例を見つけることができませんでした。

これは私の実装のスニペットです。非常にあいまいなエラーが表示されます。

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

アルゴリズムを 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: 'RSAES-PKCS1-v1_5',
      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)
        });
      };
    }

4

1 に答える 1

0

この問題は、Internet Explorer 11 の公開キー暗号化に似ています。

そこで、@fenghuangは「暗号化呼び出しを呼び出すときにハッシュ フィールドを追加する」必要がありました。

    var encOp = cryptoSubtle.encrypt(
        {
            name: "RSA-OAEP",
            hash: { name: "SHA-256" }
        },
        key.publicKey,
        data
    );
于 2016-01-02T19:34:25.923 に答える