Sample code for 30+ languages & platforms
VBScript

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 VBScript Downloads

VBScript
Dim fso, outFile
Set fso = CreateObject("Scripting.FileSystemObject")
'Create a Unicode (utf-16) output text file.
Set outFile = fso.CreateTextFile("output.txt", True, True)

success = 0

set cert = CreateObject("Chilkat.Cert")

success = cert.LoadFromFile("qa_data/pem/mf_public_rsa.pem")
If (success = 0) Then
    outFile.WriteLine(cert.LastErrorText)
    WScript.Quit
End If

set pubKey = CreateObject("Chilkat.PublicKey")
success = cert.GetPublicKey(pubKey)

set rsa = CreateObject("Chilkat.Rsa")
success = rsa.UsePublicKey(pubKey)

rsa.EncodingMode = "base64"
encryptedStr = rsa.EncryptStringENC("hello",0)
outFile.WriteLine("encrypted string = " & encryptedStr)

outFile.Close