Created
February 22, 2021 02:39
-
-
Save bokwoon95/c441f5682a71a7cbd32cf55ddc3d46d3 to your computer and use it in GitHub Desktop.
golang x/crypto/salsa20 example
This file contains 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
// https://play.golang.org/p/UPn9o_AMpmr | |
package main | |
import ( | |
"fmt" | |
"golang.org/x/crypto/salsa20" | |
) | |
var key = [32]byte{} | |
var nonce = [8]byte{} | |
func main() { | |
in := []byte("abcd") | |
out := make([]byte, len(in)) | |
salsa20.XORKeyStream(out, in, nonce[:], &key) | |
fmt.Println(in, out) // [97 98 99 100] [251 245 149 63] | |
in2 := make([]byte, len(out)) | |
copy(in2, out) | |
out2 := make([]byte, len(in2)) | |
salsa20.XORKeyStream(out2, in2, nonce[:], &key) | |
fmt.Println(in2, out2) // [251 245 149 63] [97 98 99 100] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment