Salsa20需要使用字符串常量提供的key *[32]byte
。
使用类型转换将密钥传递给切片会产生error: argument 4 has incompatible type
。我不知道将字符串(或切片)转换为数组的任何方式。
我不想每次进行加密时都创建变量byteKey [32]byte
并使用copy([:]byteKey, []byte(stringKey))
。
这是我当前的解决方案:
func createFeedbackKey() (key [32]byte) {
const s = "thesingleonegreatairfysecretword"
copy(key[:], s)
return
}
var feedbackKey = createFeedbackKey()
这是6行代码,带有一个副本,恕我直言,一个简单的类型转换就足够了。
有更短/更好的方法吗? 像这样的东西?
var key = [...]byte("0123456789ABCDEF0123456789ABCDEF")