Sample code for 30+ languages & platforms
Go

Use Base64 RSA Key to Encrypt

See more RSA Examples

Loads a Base64 RSA key and uses it to encrypt a string, returning the result in base64.

Chilkat Go Downloads

Go
    success := false

    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    pubkey := chilkat.NewPublicKey()

    success = pubkey.LoadBase64("MIICdgIBADA ... A9PXLk+j5A==")
    if success == false {
        fmt.Println(pubkey.LastErrorText())
        pubkey.DisposePublicKey()
        return
    }

    rsa := chilkat.NewRsa()

    success = rsa.UsePublicKey(pubkey)
    if success == false {
        fmt.Println(rsa.LastErrorText())
        pubkey.DisposePublicKey()
        rsa.DisposeRsa()
        return
    }

    rsa.SetEncodingMode("base64")

    encryptedStr := rsa.EncryptStringENC("12345678",false)

    fmt.Println(*encryptedStr)

    pubkey.DisposePublicKey()
    rsa.DisposeRsa()