Replies: 1 comment
-
It doesn't have to be as complicated as the post you linked. The accepted response that immediately follows it is more relevant. Even the README file of the PHP extension has way simpler examples. Nonces are often defined by the protocol itself. For example, if a sequence of messages is encrypted with the same key, it can be a simple counter. So they don't have to be transmitted at all. There's no need to check for Inputs and outputs are binary everywhere. There's no need to encode anything, except if you need to embed binary data in a text such as HTML code. But in that case, it's what filters in HTML template engines are for. Finally, this repository is about the library itself, not PHP. |
Beta Was this translation helpful? Give feedback.
-
It's nice libsodium takes care of many the details, but this is still too much code to get wrong.
SODIUM_CRYPTO_SECRETBOX_NONCEBYTES
exists?sodium_memzero
stuff? Seems like libsodium PHP bindings should be able to clean up after itselffalse
everywhere.For input/output options, I suggest providing a few different encodings, like binary, base64 and hex. Node providers several:
'ascii'
,'utf8'
,'utf16le'
/'ucs2'
,'base64'
,'base64url'
,'latin1'
/'binary'
, and'hex'
. https://nodejs.org/docs/latest/api/buffer.html#buffers-and-character-encodings (although utf8/16 isn't really relevant here for an output encoding)The signatures should be something like:
encryptString($unencrypted_data, $key, $output_encoding='8bit')
decryptString($encrypted_data, $key, $input_encoding='8bit')
I chose "8bit" for the binary format to match the
mb_
family of functions.Beta Was this translation helpful? Give feedback.
All reactions