Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(PureBasic) Write PKCS1 or PKCS8 Public Key PEMDemonstrates how to write either PKCS1 or PKCS8 format PEM files. PKCS1 public keys have this PEM format: -----BEGIN RSA PUBLIC KEY----- BASE64 ENCODED DATA -----END RSA PUBLIC KEY-----PKCS8 public keys have this PEM format: -----BEGIN PUBLIC KEY----- BASE64 ENCODED DATA -----END PUBLIC KEY-----
IncludeFile "CkPem.pb" IncludeFile "CkGlobal.pb" Procedure ChilkatExample() ; Unlock the Chilkat API. ; Starting in v9.5.0.49, all Chilkat classes can be unlocked at once at the beginning of a program ; by calling UnlockBundle. It requires a Bundle unlock code. chilkatGlob.i = CkGlobal::ckCreate() If chilkatGlob.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success.i = CkGlobal::ckUnlockBundle(chilkatGlob,"Anything for 30-day trial.") If success <> 1 Debug CkGlobal::ckLastErrorText(chilkatGlob) CkGlobal::ckDispose(chilkatGlob) ProcedureReturn EndIf pem.i = CkPem::ckCreate() If pem.i = 0 Debug "Failed to create object." ProcedureReturn EndIf ; Load a public key from a PEM file. ; (Assume the PEM contains at least one public key..) success = CkPem::ckLoadPemFile(pem,"/Users/chilkat/testData/pem/myPublicKey.pem") If success <> 1 Debug CkPem::ckLastErrorText(pem) CkGlobal::ckDispose(chilkatGlob) CkPem::ckDispose(pem) ProcedureReturn EndIf i.i numPublicKeys.i = CkPem::ckNumPublicKeys(pem) If numPublicKeys = 0 Debug ("Error: Expected the PEM to contain public keys.") CkGlobal::ckDispose(chilkatGlob) CkPem::ckDispose(pem) ProcedureReturn EndIf ; Get each public key as PEM, first in PKCS1 format, then in PKCS8. For i = 1 To numPublicKeys ; First output to PKCS1 PEM format: Debug "This is PKCS1 format:" CkPem::setCkPublicKeyFormat(pem, "pkcs1") Debug CkPem::ckToPem(pem) ; Now PKCS8 PEM format: Debug "This is PKCS8 format:" CkPem::setCkPublicKeyFormat(pem, "pkcs8") Debug CkPem::ckToPem(pem) Next CkGlobal::ckDispose(chilkatGlob) CkPem::ckDispose(pem) ProcedureReturn EndProcedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.