简体   繁体   中英

DOMException while decrypting RSA data

I'm trying to send encrypted data from server to client and decrypt it by using window.crypto.subtle.decrypt() . But i've got an Error without description. How can i fix it?

node.js server code:

 const sharedKey = (req, res, next) => { let crypto = require('crypto'); let buf = Buffer.from('Hello, my friend'); const key = { key: req.body.public, padding: crypto.constants.RSA_PKCS1_OAEP_PADDING } try { let encrypted = crypto.publicEncrypt(key, buf); res.send(encrypted.toString('base64')); } catch (err) { console.log('err', err) } }; 

client code:

 $.post('/register', { 'login': login, 'public': publicKeyPEM }, function(data) { console.log('data', data); data = Ocrypto.base64ToArrayBuffer(data); try { window.crypto.subtle.decrypt({ name: "RSA-OAEP", //label: Uint8Array([...]) //optional }, keyPair.privateKey, //from generateKey or importKey above data //ArrayBuffer of the data ) .then(function(decrypted) { //returns an ArrayBuffer containing the decrypted data console.log(new Uint8Array(decrypted)); }) .catch(function(err) { console.log("ERRRRRR", err); }); } catch (error) { console.log('err', err) } }); 

That what i've got in console: "ERRRRRR DOMException"

data = Ocrypto.base64ToArrayBuffer(data);

好像您那里有错字。

I don't know how to solve that problem, but i found another way how to do mu project works. I use node-rsa on server, and on client after buildin by browserify

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM