CertMgr Code Example: Export public key file

Shows how to export various public key formats, and how to specify a comment.

Date Entered: 03/27/2008    Last Updated: 03/27/2008

In IPWorks SSL V8 and IPWorks SSH V8 you can use the CertMgr component to export the public key in SSH2 format, OpenSSH format, and PEM format.

To export a certificate in PEM format no special action is required. This is the default behavior when calling the SaveCertificate method of the CertMgr component. This outputs a file which looks like:

-----BEGIN CERTIFICATE-----
MIIBujCCASOgAwIBAgIBFzANBgkqhkiG9w0BAQUFADAjMSEwHwYDVQQDExhudW5pdFNhdmVD
[More Certificate Data]
eUe7o3H/xeaoK57Th4M=
-----END CERTIFICATE-----

To export a public key in SSH2 format set the CertificateOutputFormat configuration setting to SSH2PublicKey. For instance this code:

C#
certmgr.Config("CertificateOutputFormat=SSH2PublicKey");
certmgr.SaveCertificate("c:\\SSH2PubKey.pub");

Java
certmgr.config("CertificateOutputFormat=SSH2PublicKey");
certmgr.saveCertificate("c:\\SSH2PubKey.pub");

will produce a public key which looks like:

---- BEGIN SSH2 PUBLIC KEY ----
AAAAB3NzaC1yc2EAAAADAQABAAAAgQC7YActy/buD+4Q2eQS29J8ceWVhKs3VgVfYklkxZjr
[More Public Key Data]
0acagI0Bdibnf+0t+Golf9Wx2AE9bLygg92eSWqBv/G2zoJta3UC2+ww0Q==
---- END SSH2 PUBLIC KEY ----

To export a public key in OpenSSH format set the CertificateOutputFormat configuration setting to OpenSSHPublicKey. For instance this code:

C#
certmgr.Config("CertificateOutputFormat=OpenSSHPublicKey");
certmgr.SaveCertificate("c:\\OpenSSHPubKey.pub");

Java
certmgr.config("CertificateOutputFormat=OpenSSHPublicKey");
certmgr.saveCertificate("c:\\OpenSSHPubKey.pub");

will produce a public key which looks like:

ssh-rsa AAAAB3Nza[More Public Key Data]diM0V7F2p19w==

You can also specify a comment when exporting a SSH2 or OpenSSH formatted public key. This is done through the CertComment configuration setting. When exporting a SSH2 public key the value should be the entire header and value pair. When exporting an OpenSSH public key the value should be only the comment. For instance:

C#
certmgr.Config("CertComment=Comment: SSH2 Public Key Comment");
certmgr.Config("CertComment=OpenSSH Public Key Comment");

Java
certmgr.config("CertComment=Comment: SSH2 Public Key Comment");
certmgr.config("CertComment=OpenSSH Public Key Comment");

We appreciate your feedback.  If you have any questions, comments, or suggestions about this entry please contact our support team at kb@nsoftware.com.