(Go) Use Base64 RSA Key to Encrypt
Loads a Base64 RSA key and uses it to encrypt a string, returning the result in base64. Note: This example requires Chilkat v11.0.0 or greater.
success := false
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
pubkey := PublicKey_Ref.html">chilkat.NewPublicKey()
success = pubkey.LoadBase64("MIICdgIBADA ... A9PXLk+j5A==")
if success == false {
fmt.Println(pubkey.LastErrorText())
pubkey.DisposePublicKey()
return
}
rsa := Rsa_Ref.html">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()
|