|  | 
Chilkat  HOME  Android™  AutoIt  C  C#  C++  Chilkat2-Python  CkPython  Classic ASP  DataFlex  Delphi DLL  Go  Java  Node.js  Objective-C  PHP Extension  Perl  PowerBuilder  PowerShell  PureBasic  Ruby  SQL Server  Swift  Tcl  Unicode C  Unicode C++  VB.NET  VBScript  Visual Basic 6.0  Visual FoxPro  Xojo Plugin
| (Classic ASP) Get RSA Key Modulus from .cer or .keyDemonstrates how to get the RSA key modulus from either the certificate (.cer) or RSA key (.key). OpenSSL commands to do the same would be: openssl x509 -inform DER -in "test.cer" -modulus -nooutor openssl pkcs8 -inform DER -inβ "test.key"β -outform PEM -passin pass:"12345β678aβ" | openssl rsa -inform PEM -modulus -noout Note: This example requires Chilkat v11.0.0 or greater. 
 <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> </head> <body> <% success = 0 set privKey = Server.CreateObject("Chilkat.PrivateKey") password = "12345678a" success = privKey.LoadPkcs8EncryptedFile("qa_data/certs/test_12345678a.key",password) If (success = 0) Then Response.Write "<pre>" & Server.HTMLEncode( privKey.LastErrorText) & "</pre>" Response.End End If set xml = Server.CreateObject("Chilkat.Xml") success = xml.LoadXml(privKey.GetXml()) ' The XML contains the parts of the key in base64. Response.Write "<pre>" & Server.HTMLEncode( "Private Key XML:") & "</pre>" Response.Write "<pre>" & Server.HTMLEncode( xml.GetXml()) & "</pre>" ' We can get the base64 modulus like this: modulus = xml.GetChildContent("Modulus") Response.Write "<pre>" & Server.HTMLEncode( "base64 modulus = " & modulus) & "</pre>" ' To convert to hex: set binDat = Server.CreateObject("Chilkat.BinData") success = binDat.AppendEncoded(modulus,"base64") hexModulus = binDat.GetEncoded("hex") Response.Write "<pre>" & Server.HTMLEncode( "hex modulus = " & hexModulus) & "</pre>" ' Now get the modulus from the cert: set cert = Server.CreateObject("Chilkat.Cert") success = cert.LoadFromFile("qa_data/certs/test_12345678a.cer") If (success = 0) Then Response.Write "<pre>" & Server.HTMLEncode( cert.LastErrorText) & "</pre>" Response.End End If ' The cert contains the public key, which is composed of the ' modulus + exponent (for RSA keys). set pubKey = Server.CreateObject("Chilkat.PublicKey") success = cert.GetPublicKey(pubKey) success = xml.LoadXml(pubKey.GetXml()) Response.Write "<pre>" & Server.HTMLEncode( "Public Key XML:") & "</pre>" Response.Write "<pre>" & Server.HTMLEncode( xml.GetXml()) & "</pre>" ' Proceed in the same way as before.... modulus = xml.GetChildContent("Modulus") Response.Write "<pre>" & Server.HTMLEncode( "base64 modulus = " & modulus) & "</pre>" ' To convert to hex: success = binDat.Clear() success = binDat.AppendEncoded(modulus,"base64") hexModulus = binDat.GetEncoded("hex") Response.Write "<pre>" & Server.HTMLEncode( "hex modulus = " & hexModulus) & "</pre>" %> </body> </html> | ||||
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.