|  | 
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
| (Go) Get Public Key from CSRDemonstrates how to get the public key from a CSR. 
 // This requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. pem := chilkat.NewPem() // No password is required. Pass an empty password string.. noPassword := "" success := pem.LoadPemFile("qa_data/csr/csr2.pem",noPassword) if success != true { fmt.Println(pem.LastErrorText()) pem.DisposePem() return } strBase64 := pem.GetEncodedItem("csr","","base64",0) asn := chilkat.NewAsn() success = asn.LoadEncoded(*strBase64,"base64") if success != true { fmt.Println(asn.LastErrorText()) pem.DisposePem() asn.DisposeAsn() return } // Convert the ASN.1 to XML. xml := chilkat.NewXml() success = xml.LoadXml(*asn.AsnToXml()) fmt.Println(*xml.GetXml()) fmt.Println("----") strModulusHex := xml.GetChildContent("bits") fmt.Println("strModulusHex = ", *strModulusHex) fmt.Println("----") // We need the modulus as base64. bd := chilkat.NewBinData() bd.AppendEncoded(*strModulusHex,"hex") modulus64 := bd.GetEncoded("base64") fmt.Println("modulus64 = ", *modulus64) fmt.Println("----") // Build the XML for the public key. xmlPubKey := chilkat.NewXml() xmlPubKey.SetTag("RSAPublicKey") xmlPubKey.UpdateChildContent("Modulus",*modulus64) // The RSA exponent will always be decimal 65537 (base64 = AQAB) xmlPubKey.UpdateChildContent("Exponent","AQAB") fmt.Println("RSA public key as XML:") fmt.Println(*xmlPubKey.GetXml()) fmt.Println("----") // Load the XML into a Chilkat public key object. pubkey := chilkat.NewPublicKey() success = pubkey.LoadFromString(*xmlPubKey.GetXml()) if success != true { fmt.Println(pubkey.LastErrorText()) pem.DisposePem() asn.DisposeAsn() xml.DisposeXml() bd.DisposeBinData() xmlPubKey.DisposeXml() pubkey.DisposePublicKey() return } // Show the public key as PEM. preferPkcs1 := true fmt.Println(*pubkey.GetPem(preferPkcs1)) pem.DisposePem() asn.DisposeAsn() xml.DisposeXml() bd.DisposeBinData() xmlPubKey.DisposeXml() pubkey.DisposePublicKey() | ||||
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.