CryptoAPI PUBLICKEYBLOB or RSAPublicKey to SubjectPublicKeyInfo Converter

Encodekey.c is a C console application for Win32 which converts a Microsoft CryptoAPI PUBLICKEYBLOB file,or an ASN.1 encoded RSAPublicKey file into an ASN.1 SubjectPublicKeyInfo public key. Encodekey first performs a basic test on the input file contents, using CryptDecodeObject(), to determine if the file is either a valid RSAPublicKey blob or a SubjectPublicKeyInfo blob.

A PUBLICKEYBLOB is typically generated by CryptExportKey().
The RSAPublicKey form is commonly used in CryptoAPI, whereas the higher encapsulation SubjectPublicKeyInfo is the encoded format usually more commonly used in Java, .NET, OpenSSL etc..

Sample output for a PUBLICKEYBLOB file (for a 1024 bit RSA key):

Enter CryptoAPI PUBLICKEYBLOB or RSAPublicKey file: publickeyblob

Read 'publickeyblob' file into buffer:  148 bytes.

Got RSAPublicKey encoded data: 140 bytes
Wrote 140 bytes to file 'rsapublickey'

Got SubjectPublicKeyInfo encoded data: 162 bytes
Wrote 162 bytes to file 'subjectpublickeyinfo'

encodekey.exe (signed and timestamped; 83,112 bytes)

PUBLICKEYBLOB specification.

See also: JkeyNet: Using ASN.1 encoded public keys in .NET