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
+29.5k Golang : How to create new XML file ?
+17k Golang : Get input from keyboard
+4.7k Chrome : How to block socketloop.com links in Google SERP?
+7.1k Golang : Transform lisp or spinal case to Pascal case example
+10k Golang : Convert octal value to string to deal with leading zero problem
+23.5k Golang : Get ASCII code from a key press(cross-platform) example
+5.6k Python : Print unicode escape characters and string
+7.3k Golang : How to convert strange string to JSON with json.MarshalIndent
+32.7k Golang : Regular Expression for alphanumeric and underscore
+8.2k Golang : Routes multiplexer routing example with regular expression control
+13.6k Golang : Get user input until a command or receive a word to stop
+13.9k Golang : Get current time