I have to generate a nonce in Go's crypto/nacl/box package with the condition that for same data, the nonce remains the same. I have used the following code in Libsodium package.
const nonce = sodium.crypto_generichash(
sodium.crypto_secretbox_NONCEBYTES,
data
);
This gives me the same value for nonce for same value of data. However, when I use Go's crypto/nacl/box package, it seems that the only way to generate a nonce is as follows.
var nonce [24]byte
if _, err := io.ReadFull(crypto_rand.Reader, nonce[:]); err != nil {
panic(err)
}
encrypted := box.SealAfterPrecomputation(nonce[:], data, &nonce ,&secretkey)
The value of encrypted variable changes even with same value of data because the nonce changes everytime. My ultimate goal is to generate the same value of the encrypted variable if data and secretkey remain the same.
question from:
https://stackoverflow.com/questions/65898460/what-is-the-replacement-of-libsodiums-crypto-generichashsize-data-in-crypto-n 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…