Skip to content
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

Unable to get PEM using KEYUTIL.getPEM. #53

Closed
trusktr opened this issue Apr 21, 2014 · 3 comments
Closed

Unable to get PEM using KEYUTIL.getPEM. #53

trusktr opened this issue Apr 21, 2014 · 3 comments
Assignees
Labels

Comments

@trusktr
Copy link

trusktr commented Apr 21, 2014

This is my code:

var rsa = require("jsrsasign");
var keypair = rsa.KEYUTIL.generateKeypair("RSA", 256);
console.log(keypair.prvKeyObj);
console.log(rsa.KEYUTIL.getPEM(keypair.prvKeyObj)); // ERROR

It results in this error:

Uncaught unsupported object nor format

keypair.prvKeyObj is a RSAKey object, and I believe that is what the rsa.KEYUTIL.getPEM method accepts basedon the docs. Why might I be getting this error?

@trusktr trusktr changed the title Unable to get PEM using KEYUTIL. Uncaught unsupported object nor format Unable to get PEM using KEYUTIL.getPEM. Apr 21, 2014
@Sloy
Copy link

Sloy commented May 13, 2014

I had the same issue. After struggling with it for an hour or so I found that one requirement in KEYUTIL's code was not being satisfied: keyObjOrHex.isPublic == true. By printing the prvKeyObj you can see it doesn't have that attribute at all. I added it manually as a workaround and it seems to work:

var keyPair = r.KEYUTIL.generateKeypair("RSA", "512");
keyPair.prvKeyObj.isPrivate = true;
var privateKey = r.KEYUTIL.getPEM(keyPair.prvKeyObj, "PKCS1PRV");

Not sure if it's a bug in generateKeypair or what, but man that was annoying to find.

@kjur
Copy link
Owner

kjur commented May 14, 2014

I've fixed it today on version 4.2.3. Thanks.

@kjur kjur closed this as completed May 14, 2014
@kjur kjur added the bug label May 14, 2014
@kjur kjur self-assigned this May 14, 2014
@animalillo
Copy link

bumps

I think this is back in 4.7.1-all-min

var kp = KEYUTIL.generateKeypair("RSA", 1024);
<< undefined
kp
<<Object {prvKeyObj: RSAKey, pubKeyObj: RSAKey}
KEYUTIL.getPEM(kp.prvKeyObj, "PKCS1PRV")
<< Uncaught TypeError: KJUR.asn1.ASN1Util.newObject is not a functionp @ jsrsasign-4.7.1-all-min.js?v=cf866614b6b18cda13fe699a3a65661b:249KEYUTIL.getPEM @ jsrsasign-4.7.1-all-min.js?v=cf866614b6b18cda13fe699a3a65661b:249(anonymous function) @ VM8562:2InjectedScript._evaluateOn @ VM8247:883InjectedScript._evaluateAndWrap @ VM8247:816InjectedScript.evaluate @ VM8247:682

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

No branches or pull requests

4 participants