This package implements "crypto/rsa" lib wrapper which encrypt and decrypt messages
type OAEP struct {
hash hash.Hash
random io.Reader
}
hash
hash functionrandom
random parameter is used as a source of entropy to ensure that encrypting
go get github.com/lorenzodisidoro/rsa-oaep
oaep := NewRSAOaep(sha256.New())
The following code is used to encrypt and decrypt message
// you will import "crypto/rsa" and "crypto/rand"
privateKey, err := rsa.GenerateKey(rand.Reader, keySize)
if err != nil {
t.Fatal(err)
}
message := []byte("Love bitcoin!")
label := []byte("bitcoin")
oaep := NewRSAOaep(sha256.New())
cipherText, err := oaep.Encrypt(&privateKey.PublicKey, message, label)
if err != nil {
t.Fatal(err)
}
decriptedMessage, err := oaep.Dencrypt(privateKey, cipherText, label)
if err != nil {
t.Fatal(err)
}
fmt.Printf(string(decriptedMessage))