-
Notifications
You must be signed in to change notification settings - Fork 790
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
How can I extract the public key from the x.509 certificate ? #278
Comments
// this string format is base64-encoded DER bytes
var certString = 'MIIB+jCCAWOgAwIBAgIB...';
// base64-decode DER bytes
var certDerBytes = forge.util.decode64(certString);
// parse DER to an ASN.1 object
var obj = forge.asn1.fromDer(certDerBytes);
// convert ASN.1 object to forge certificate object
var cert = forge.pki.certificateFromAsn1(obj);
// get forge public key object
var publicKey = cert.publicKey;
// `publicKey` can now be used to verify, encrypt, etc.
publicKey.verify(...);
publicKey.encrypt(...);
// if you did want to convert it to PEM format for transport:
var pem = forge.pki.publicKeyToPem(publicKey); |
It works, thanks very much. |
Works great! Thanks. |
@dlongley I must be missing something, because I am getting an error when calling
I am able to get the public key with the directions above. I have used this public key via the I have tried
and
both are failing. Am I using the |
The message digest |
Cannot read public key. OID is not RSA. *( |
I have a x.509 certificate in string format, e.g. MIIB+jCCAWOgAwIBAgIB...
How can I extract the public key just using the string, without saving it as .pem manually first.
The text was updated successfully, but these errors were encountered: