Skip to content

Instantly share code, notes, and snippets.

@rhzs
Forked from bokwoon95/salsa20_example.go
Created September 11, 2022 07:59
Show Gist options
  • Save rhzs/52936ee29f00a0ddae2ff7bbc581c17b to your computer and use it in GitHub Desktop.
Save rhzs/52936ee29f00a0ddae2ff7bbc581c17b 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