EncryptOAEP in Go

Posted by GoDoc
Public (Editable by Users)

EncryptOAEP encrypts the given message with RSA-OAEP.

Go
Edit
package main

import (
	"crypto/rand"
	"crypto/sha256"
	"fmt"
	"os"
)

func main() {
	secretMessage := []byte("send reinforcements, we're going to advance")
	label := []byte("orders")

	// crypto/rand.Reader is a good source of entropy for randomizing the
	// encryption function.
	rng := rand.Reader

	ciphertext, err := EncryptOAEP(sha256.New(), rng, &test2048Key.PublicKey, secretMessage, label)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error from encryption: %s\n", err)
		return
	}

	// Since encryption is a randomized function, ciphertext will be
	// different each time.
	fmt.Printf("Ciphertext: %x\n", ciphertext)
}