What it means in practice: "The nonce MUST NOT be repeated or reused with the same key" #2
Replies: 2 comments 1 reply
-
For encryption, the nonce must be incremented or randomly generated with the same key. If you change the key each time you call If the nonce is a counter, you know it always starts at 0, so it doesn't need to be stored. However, if it's randomly generated, you should prepend it to the ciphertext using If you can maintain a counter, you can randomly generate the first nonce and then increment it each time. This means you only need to store the random nonce and not the incremented ones. For decryption, you need to specify the same inputs as those used for encryption otherwise you'll get an error. If the nonce is prepended to the ciphertext, you just slice it off and decrypt the ciphertext without the nonce. Hope that helps! I'll try and clarify it in the documentation. |
Beta Was this translation helpful? Give feedback.
-
Hello @samuel-lucas6,
I'm try using the XChaCha20-Poly1305 "Authenticated encription", and I little bit confused when read:
In my scenario I need to
encrypt
some data anddecrypt
this data in another moment, like anToken
:But when I tried to use the recommended practices in
nouce
value(increment or randomly generate) I can'tDecrypt
data(CryptographicException). In my thinking I need the suitablenounce
to do the correct data decryption, but, how will I know the appropriate one, if I generated/incremented the value? I need alwaysextern/public
thenounce
I used? Like:Some
foo
code example:What would be the proper way to deal with this scenario?
Cheers! 😁
Beta Was this translation helpful? Give feedback.
All reactions