Skip to content
This repository has been archived by the owner on Aug 5, 2022. It is now read-only.

store javascript object rsa private key #28

Open
inlikefletch opened this issue Jun 12, 2017 · 2 comments
Open

store javascript object rsa private key #28

inlikefletch opened this issue Jun 12, 2017 · 2 comments

Comments

@inlikefletch
Copy link

Hi,
Is there a way to store the private key object in a javascript session? I've tried JSON.stringify, but when I parse the object, the decryption fails. The object seems to lose part of the object.

Thanks,
Jason

@zwisler-a
Copy link

zwisler-a commented Aug 3, 2017

In case it is still needed,

Issue #3

  function serializeRSAKey(key) {
    return JSON.stringify({
      coeff: key.coeff.toString(16),
      d: key.d.toString(16),
      dmp1: key.dmp1.toString(16),
      dmq1: key.dmq1.toString(16),
      e: key.e.toString(16),
      n: key.n.toString(16),
      p: key.p.toString(16),
      q: key.q.toString(16)
    })
  }

  function deserializeRSAKey(key) {
    let json = JSON.parse(key);
    let rsa = new RSAKey();
    rsa.setPrivateEx(json.n, json.e, json.d, json.p, json.q, json.dmp1, json.dmq1, json.coeff);
    return rsa;
  }

@inlikefletch
Copy link
Author

Thanks for the response! I will have to give that a try. I was able to get a work around by using a window object with the window dot format
e.g.
var privateKey = cryptico.generateRSAKey(passPhrase, bits);
window.privateKey = privateKey;

and then use the window.privateKey in another function when called in the session.

Not sure if one is better or more secure than the other.

Thanks,
Jason

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants