Created
August 29, 2012 19:45
-
-
Save hansstimer/3517835 to your computer and use it in GitHub Desktop.
Revisions
-
hansstimer renamed this gist
Aug 29, 2012 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
hansstimer created this gist
Aug 29, 2012 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,35 @@ package main import ( "bytes" "crypto/rand" "crypto/rsa" "crypto/sha1" "fmt" ) func main() { privateKey, err := rsa.GenerateKey(rand.Reader, 512) if err != nil { fmt.Printf("rsa.GenerateKey: %v\n", err) } message := "Hello World!" messageBytes := bytes.NewBufferString(message) sha1 := sha1.New() encrypted, err := rsa.EncryptOAEP(sha1, rand.Reader, &privateKey.PublicKey, messageBytes.Bytes(), nil) if err != nil { fmt.Printf("EncryptOAEP: %s\n", err) } decrypted, err := rsa.DecryptOAEP(sha1, rand.Reader, privateKey, encrypted, nil) if err != nil { fmt.Printf("decrypt: %s\n", err) } decryptedString := bytes.NewBuffer(decrypted).String() fmt.Printf("message: %v\n", message) fmt.Printf("encrypted: %v\n", encrypted) fmt.Printf("decryptedString: %v\n", decryptedString) }