Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
321 views
in Technique[技术] by (71.8m points)

go - What is the replacement of Libsodium's crypto_generichash(size,data) in crypto/nacl/box?

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...