Skip to content

Instantly share code, notes, and snippets.

@bokwoon95
Created February 22, 2021 02:39
Show Gist options
  • Save bokwoon95/c441f5682a71a7cbd32cf55ddc3d46d3 to your computer and use it in GitHub Desktop.
Save bokwoon95/c441f5682a71a7cbd32cf55ddc3d46d3 to your computer and use it in GitHub Desktop.
golang x/crypto/salsa20 example
// 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