Skip to content

Instantly share code, notes, and snippets.

@byronhe byronhe/rsa_oaep.go
Created May 22, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.