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
Hello I'm having some issues getting encrypted data from c++ application to decrypt inside PHP code.
#define MESSAGE (const unsigned char *) "test"
#define MESSAGE_LEN 4
#define CIPHERTEXT_LEN (crypto_box_MACBYTES + MESSAGE_LEN)
unsigned char alice_publickey[crypto_box_PUBLICKEYBYTES];
unsigned char alice_secretkey[crypto_box_SECRETKEYBYTES];
crypto_box_keypair(alice_publickey, alice_secretkey);
unsigned char bob_publickey[crypto_box_PUBLICKEYBYTES];
unsigned char bob_secretkey[crypto_box_SECRETKEYBYTES];
crypto_box_keypair(bob_publickey, bob_secretkey);
unsigned char nonce[crypto_box_NONCEBYTES];
unsigned char ciphertext[CIPHERTEXT_LEN];
randombytes_buf(nonce, sizeof nonce);
if (crypto_box_easy(ciphertext, MESSAGE, MESSAGE_LEN, nonce,
bob_publickey, alice_secretkey) != 0) {
/* error */
}
unsigned char decrypted[MESSAGE_LEN];
if (crypto_box_open_easy(decrypted, ciphertext, CIPHERTEXT_LEN, nonce,
alice_publickey, bob_secretkey) != 0) {
/* message for Bob pretending to be from Alice has been forged! */
}
Following that basic snippet everything works fine in the cpp side and the php side individually encrypting / decrypting data but for whatever reason I seem to find why it's not working going from cpp to php.
I'm sending the nonce and encrypted text as hex encoded values and decoding them back to binary on the PHP side, along with the correct secret and private keys, but the sodium_crypto_box_open always returns false.
Just looking for some advice as I've been debugging this for hours. Thanks.
This discussion was converted from issue #1295 on August 09, 2023 17:35.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello I'm having some issues getting encrypted data from c++ application to decrypt inside PHP code.
Following that basic snippet everything works fine in the cpp side and the php side individually encrypting / decrypting data but for whatever reason I seem to find why it's not working going from cpp to php.
I'm sending the nonce and encrypted text as hex encoded values and decoding them back to binary on the PHP side, along with the correct secret and private keys, but the
sodium_crypto_box_open
always returns false.Just looking for some advice as I've been debugging this for hours. Thanks.
Beta Was this translation helpful? Give feedback.
All reactions