javascript - RSA-OEP encryption in ie11 -
i have been unable find examples of rsa-oaep encryption in ie11.
here's snippet of implementation, in given vague error.
function convertstringtoarraybufferview(str) { var bytes = new uint8array(str.length); (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) }); }; } when change algorithm rsaes-pkcs1-v1_5, works flawlessly
function convertstringtoarraybufferview(str) { var bytes = new uint8array(str.length); (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) }); }; }
this problem looks similar public key encryption in internet explorer 11
there, @fenghuang needed "to add hash field when invoking encrypt call"
var encop = cryptosubtle.encrypt( { name: "rsa-oaep", hash: { name: "sha-256" } }, key.publickey, data );
Comments
Post a Comment