B4X Requires Chilkat v11.8.0+
B4X
Add a PEM Source of Certificates and Private Keys for IMAP
See more IMAP Examples
Demonstrates the Chilkat Imap.AddPemSource method, which adds the certificates and private keys of a Pem object to the Imap object's sources of certificates and private keys for S/MIME operations. The only argument is the Pem object.
Note: The certificate path is relative to the application's current working directory. Supply the path to your own certificate file.
Background: A
Pem object is an in-memory collection of certificates and private keys. It can be loaded from PEM text, from a .p7b, or, as in this example, from a PEM file. It is a convenient way to give an application the exact set of credentials it needs without depending on the operating system's certificate stores. Adding it makes all of its certificates available for S/MIME decryption and signature verification. AddPemSource can be called multiple times. Each call adds more certificates to the ones already added. AddPemSource was added in Chilkat v11.8.0 and replaces UseCertVault and the AddPfxSource methods.Chilkat B4X Downloads
Dim success As Boolean = False
' Demonstrates the Imap.AddPemSource method, which adds the certificates and private keys of a
' Pem object to the Imap object's sources of certificates and private keys for S/MIME
' operations. The only argument is the Pem object.
Dim imap As ChilkatImap
imap.Initialize("imap")
imap.Ssl = True
imap.Port = 993
success = imap.Connect("imap.example.com")
If success = False Then
Log(imap.LastErrorText)
Return
End If
success = imap.Login("user@example.com", "myPassword")
If success = False Then
Log(imap.LastErrorText)
Return
End If
' The password of the private key is not hard-coded in source. Insert code here to obtain it
' from an interactive prompt, environment variable, or a secrets vault.
Dim pemPassword As String
' Load a PEM file that has the certificate and its private key. The 2nd argument of LoadPemFile
' is the password of the private key.
Dim pem As ChilkatPem
pem.Initialize
success = pem.LoadPemFile("qa_data/smime.pem", pemPassword)
If success = False Then
Log(pem.LastErrorText)
Return
End If
' Add the certificates and private keys to the Imap object.
' AddPemSource can be called multiple times. Each call adds more certificates to the ones already added.
success = imap.AddPemSource(pem)
If success = False Then
Log(imap.LastErrorText)
Return
End If
success = imap.Disconnect
If success = False Then
Log(imap.LastErrorText)
Return
End If