Golang crypto/rsa EncryptOAEP() and DecryptOAEP() functions example
package crypto/rsa
EncryptOAEP encrypts the given message with RSA-OAEP. The message must be no longer than the length of the public modulus less twice the hash length plus 2.
DecryptOAEP decrypts ciphertext using RSA-OAEP. If random != nil, DecryptOAEP uses RSA blinding to avoid timing side-channel attacks.
Golang crypto/rsa EncryptOAEP() and DecryptOAEP() functions usage example
// EncryptOAEP
msg := []byte("The secret message!")
label := []byte("")
md5hash := md5.New()
encryptedmsg, err := rsa.EncryptOAEP(md5hash, rand.Reader, publickey, msg, label)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Printf("OAEP encrypted [%s] to \n[%x]\n", string(msg), encryptedmsg)
fmt.Println()
// DecryptOAEP
decryptedmsg, err := rsa.DecryptOAEP(md5hash, rand.Reader, privatekey, encryptedmsg, label)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Printf("OAEP decrypted [%x] to \n[%s]\n",encryptedmsg, decryptedmsg)
fmt.Println()
Please see RSA package functions example for full example.
References :
Advertisement
Something interesting
Tutorials
+13.1k Golang : How to get a user home directory path?
+15.2k Golang : Accurate and reliable decimal calculations
+11.5k Use systeminfo to find out installed Windows Hotfix(s) or updates
+6k Golang : Convert Chinese UTF8 characters to Pin Yin
+16.8k Golang : read gzipped http response
+9.7k Golang : interface - when and where to use examples
+6.3k Golang : How to get capacity of a slice or array?
+20.8k Golang : Underscore or snake_case to camel case example
+22.2k Golang : Securing password with salt
+12k Golang : Clean formatting/indenting or pretty print JSON result
+4.1k Javascript : Empty an array example
+19.9k Golang : How to get time from unix nano example