Created
May 22, 2015 08:14
-
-
Save byronhe/86a4d8d82c2d6f48fc20 to your computer and use it in GitHub Desktop.
rsa oaep 2048 sha256
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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