Sample code for 30+ languages & platforms
B4X Requires Chilkat v11.8.0+

Example: Crypt2.AddPemSource method with PEM text in memory

Demonstrates how to call the AddPemSource method with PEM text that is held in memory.

Chilkat B4X Downloads

B4X
Dim success As Boolean = False

Dim crypt As ChilkatCrypt2
crypt.Initialize("crypt")
success = False

'  Do public-key decryption (RSA)
crypt.CryptAlgorithm = "pki"

'  ...
'  ...
'  ...

'  PEM text (a certificate and its private key) that is held in memory.
'  Here it is loaded into a StringBuilder from a file.
Dim sbPem As ChilkatStringBuilder
sbPem.Initialize
success = sbPem.LoadFile("c:/my_pem_files/a.pem", "utf-8")
'  ...

'  Load the PEM text into a Pem object.  The 2nd argument of LoadPem is the password of the
'  private key.  (Pass an empty string if the private key is not encrypted.)
Dim pemPassword As String = "secret1"
Dim pem As ChilkatPem
pem.Initialize
success = pem.LoadPem(sbPem.GetAsString, pemPassword)
If success = False Then
    Log(pem.LastErrorText)
    Return
End If

success = crypt.AddPemSource(pem)
If success = False Then
    Log(crypt.LastErrorText)
    Return
End If


'  Add as many PEM sources as desired...
'  Each call to AddPemSource adds more certificates to the ones already added.
success = sbPem.LoadFile("c:/my_pem_files/b.pem", "utf-8")
pemPassword = "secret2"
Dim pem2 As ChilkatPem
pem2.Initialize
success = pem2.LoadPem(sbPem.GetAsString, pemPassword)
If success = False Then
    Log(pem2.LastErrorText)
    Return
End If

success = crypt.AddPemSource(pem2)
If success = False Then
    Log(crypt.LastErrorText)
    Return
End If


'  ...
'  ...