CertToKey.exe takes one or two arguments:
certtokey.exe <certfile | cert-store name > [M | m]where the first argument can be:
Extracting the Public Key:
An X509Certificate object is created and X509Certificate.GetPublicKey() returns the asn.1 encoded RSA public key. This public key blob is parsed directly. It is possible to use P/Invoke techniques (see references at bottom). However the method used here uses only managed code as implemented in :
private static String CertToXMLKey(X509Certificate cert)
This function extracts the modulus and exponent, creates an RSACryptoServiceProvider object and initializes it using the modulus and exponent. Finally, the XML b64 encoded public key is exported using RSA.ToXmlString(false) and returned.
The user is then prompted to save the public key data to files. The output key files are named, e.g. for an input
search string "devcert1":
"RSApubkey_devcert1" "XMLpubkey_devcert1.txt" If the files already exist, no files are saved.
Download CertToKey.exe v18.104.22.168 ( (13,544 bytes .NET Framework 2, Digitally Signed)
Other Techniques Using Platform Invoke:
How to use certificates to sign and to verify SignedXml objects by using Visual C# .NET
Michel I. Gallant