You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've been working on a tool that need to encrypt / decrypt data that are sent through http calls to a plumber API and stumble upon something that took me a little while to debug: when trying to decrypt a message, if you don't have attr("nonce"), the function will fail.
library(sodium)
key<- sha256(charToRaw("xyz"))
msg<- charToRaw("secretthing")
cipher<- data_encrypt(msg, key)
cipher
[1] f6d629a55ac5edcd316bcf4b19193b4f569cb7021902882cbd
[26] e214
attr(,"nonce")
[1] 31d6f65190c76b3a70e3cc1494c3b5a1bfd9d6a8870f444e# works as expected
data_decrypt(cipher, key) |> rawToChar()
[1] "secretthing"# as I want to sent it via http, I use bin2hexmessage_to_send<- bin2hex(cipher)
message_to_send
[1] "f6d629a55ac5edcd316bcf4b19193b4f569cb7021902882cbde214"# on the other process, I receive a string that # I want to decryptmessage_received<- hex2bin(message_to_send)
message_received
[1] f6d629a55ac5edcd316bcf4b19193b4f569cb7021902882cbd
[26] e214orig<- data_decrypt(message_received, key)
Errorin data_decrypt(message_received, key) :Invalidkey.Keymustbeexactly24bytes
The error message here is pretty unclear because I haven't touched the key object and I don't understand why it's suddenly not the correct length, and so I spent some time trying to understand this length issue.
The issue here seem to be that the message_received doesn't have a nonce attribute :
Given that nonce in data_decrypt is attr(bin, "nonce") and that you can't encrypt with NULL (data_encrypt(msg, key, NULL) throws an error), my feature request would be that there should be a clear error message in data_decrypt ifnonce is NULL.
The text was updated successfully, but these errors were encountered:
Hey,
Thanks a lot for sodium :)
I've been working on a tool that need to encrypt / decrypt data that are sent through http calls to a plumber API and stumble upon something that took me a little while to debug: when trying to decrypt a message, if you don't have
attr("nonce")
, the function will fail.The error message here is pretty unclear because I haven't touched the
key
object and I don't understand why it's suddenly not the correct length, and so I spent some time trying to understand thislength
issue.The issue here seem to be that the message_received doesn't have a
nonce
attribute :Given that
nonce
indata_decrypt
isattr(bin, "nonce")
and that you can't encrypt withNULL
(data_encrypt(msg, key, NULL)
throws an error), my feature request would be that there should be a clear error message indata_decrypt if
nonce
isNULL
.The text was updated successfully, but these errors were encountered: