Sample code for 30+ languages & platforms
PowerShell

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

PowerShell
Add-Type -Path "C:\chilkat\ChilkatDotNet47-x64\ChilkatDotNet47.dll"

$success = $false

$cert = New-Object Chilkat.Cert

$success = $cert.LoadFromFile("qa_data/pem/mf_public_rsa.pem")
if ($success -eq $false) {
    $($cert.LastErrorText)
    exit
}

$pubKey = New-Object Chilkat.PublicKey
$cert.GetPublicKey($pubKey)

$rsa = New-Object Chilkat.Rsa
$rsa.UsePublicKey($pubKey)

$rsa.EncodingMode = "base64"
$encryptedStr = $rsa.EncryptStringENC("hello",$false)
$("encrypted string = " + $encryptedStr)