Skip to content

Instantly share code, notes, and snippets.

@byronhe
Created May 22, 2015 08:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save byronhe/86a4d8d82c2d6f48fc20 to your computer and use it in GitHub Desktop.
Save byronhe/86a4d8d82c2d6f48fc20 to your computer and use it in GitHub Desktop.
rsa oaep 2048 sha256
package main
import (
"crypto/rand"
"crypto/rsa"
"crypto/sha256"
"log"
)
func main() {
private,err:=rsa.GenerateKey(rand.Reader,2048)
if err != nil {
log.Println("error: %s", err)
}
public := private.PublicKey
in := []byte("Hello World")
encrypted, err := rsa.EncryptOAEP(sha256.New(), rand.Reader, &public, in, nil)
if err != nil {
log.Println("error: %s", err)
}
plain, err := rsa.DecryptOAEP(sha256.New(), nil, private, encrypted, nil)
if err != nil {
log.Println("error: %s", err)
}
log.Println(string(plain))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment