Sample code for 30+ languages & platforms
Go

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

Go
    success := false

    cert := chilkat.NewCert()

    success = cert.LoadFromFile("qa_data/pem/mf_public_rsa.pem")
    if success == false {
        fmt.Println(cert.LastErrorText())
        cert.DisposeCert()
        return
    }

    pubKey := chilkat.NewPublicKey()
    cert.GetPublicKey(pubKey)

    rsa := chilkat.NewRsa()
    rsa.UsePublicKey(pubKey)

    rsa.SetEncodingMode("base64")
    encryptedStr := rsa.EncryptStringENC("hello",false)
    fmt.Println("encrypted string = ", *encryptedStr)

    cert.DisposeCert()
    pubKey.DisposePublicKey()
    rsa.DisposeRsa()