(Go) RSA Import Public Key from Certificate PEM
Uses a certificate's public key for RSA encryption. The public key from the certificate .pem file is used.
cert := chilkat.NewCert()
success := cert.LoadFromFile("qa_data/pem/mf_public_rsa.pem")
if success == false {
fmt.Println(cert.LastErrorText())
cert.DisposeCert()
return
}
pubKey := cert.ExportPublicKey()
if cert.LastMethodSuccess() != true {
fmt.Println(cert.LastErrorText())
cert.DisposeCert()
return
}
rsa := chilkat.NewRsa()
success = rsa.ImportPublicKeyObj(pubKey)
if success == false {
fmt.Println(rsa.LastErrorText())
cert.DisposeCert()
rsa.DisposeRsa()
return
}
pubKey.DisposePublicKey()
rsa.SetEncodingMode("base64")
encryptedStr := rsa.EncryptStringENC("hello",false)
fmt.Println("encrypted string = ", *encryptedStr)
cert.DisposeCert()
rsa.DisposeRsa()
|