Salsa20 requires a key *[32]byte
which I want to provide using a string constant.
Passing the key using a type-cast to a slice yield error: argument 4 has incompatible type
. I don't know of any way to cast a string (or a slice) as an array.
I don't want to create variable byteKey [32]byte
and use copy([:]byteKey, []byte(stringKey))
every time the encryption takes place.
This is my current solution:
func createFeedbackKey() (key [32]byte) {
const s = "thesingleonegreatairfysecretword"
copy(key[:], s)
return
}
var feedbackKey = createFeedbackKey()
That's 6 lines of code with a copy where, imho, a mere typecast should suffice.
Is there a shorter/better way? Something like this maybe?
var key = [...]byte("0123456789ABCDEF0123456789ABCDEF")