-
Notifications
You must be signed in to change notification settings - Fork 765
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reconstruct public and private key for re-use later #87
Comments
TL;DR: How does one give their public key to someone else, and how should one store their private key for multiple uses? |
The easiest and most compatible way to transmit public keys or to store private keys is to convert them to PEM format. Private keys may be optionally encrypted when converting them (by using a different method, see below). Converting a public key to/from PEM: // convert a Forge public key to PEM-format
var pem = pki.publicKeyToPem(publicKey);
// convert a PEM-formatted public key to a Forge public key
var publicKey = pki.publicKeyFromPem(pem); Converting a private key to/from PEM: // convert a Forge private key to PEM-format
// (preferred method if you don't want encryption)
var pem = pki.privateKeyToPem(privateKey);
// wraps and encrypts a Forge private key and outputs it in PEM format
// (preferred method if you do want encryption)
var pem = pki.encryptRsaPrivateKey(privateKey, 'password');
// encrypts a Forge private key and outputs it in PEM format using OpenSSL's
// proprietary legacy format + encapsulated PEM headers (DEK-Info)
// (perhaps more compatible with some legacy OpenSSL-based applications)
var pem = pki.encryptRsaPrivateKey(privateKey, 'password', {legacy: true});
// decrypts a PEM-formatted, encrypted private key
var privateKey = pki.decryptRsaPrivateKey(pem, 'password'); |
Hopefully this isn't too basic a question to ask, however I am having a difficult time figuring out how to reconstruct a the private and public keys after I have used them. I have attempted the following:
Which outputs: "Arbitrary Message Here" as expected. I have tried to reconstruct the public key this way:
When I try to encrypt the message again, I get an error:
"TypeError: Object #<Object> has no method 'bitLength'"
I'm not sure why though, as I believe I have used the method correctly:
And I haven't even tried reconstructing the private key yet. I'm not sure what I'm not doing correctly, could you please help me?
Additionally here are the files I'm importing in my html page, I believe I've resolved all dependency issues, but I am unsure:
The text was updated successfully, but these errors were encountered: