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

RSA Import Public Key from Certificate PEM

See more RSA Examples

Uses a certificate's public key for RSA encryption. The public key from the certificate .pem file is used.

Chilkat B4X Downloads

B4X
Dim success As Boolean = False

Dim cert As ChilkatCert
cert.Initialize("cert")

success = cert.LoadFromFile("qa_data/pem/mf_public_rsa.pem")
If success = False Then
    Log(cert.LastErrorText)
    Return
End If


Dim pubKey As ChilkatPublicKey
pubKey.Initialize
cert.GetPublicKey(pubKey)

Dim rsa As ChilkatRsa
rsa.Initialize
rsa.UsePublicKey(pubKey)

rsa.EncodingMode = "base64"
Dim encryptedStr As String = rsa.EncryptStringENC("hello", False)
Log("encrypted string = " & encryptedStr)