Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

newbie question #47

Open
MilaSy opened this issue Oct 1, 2018 · 3 comments
Open

newbie question #47

MilaSy opened this issue Oct 1, 2018 · 3 comments

Comments

@MilaSy
Copy link

MilaSy commented Oct 1, 2018

Hi TonyG
In my php I'm using sodium_bin2hex(sodium_crypto_box_publickey(sodium_crypto_box_keypair())) which I pass to the javascript:
bpkeypair='';
nacl_factory.instantiate(function(nacl){
akeypair=nacl.crypto_box_keypair();
message=nacl.encode_utf8(msg);
nonce=nacl.crypto_box_random_nonce();
});
nacl_factory.instantiate(function(acl){
ctext=acl.crypto_box(message,nonce,bpkeypair,akeypair.boxSk);
n2h=acl.to_hex(nonce);
});

when I pass "cipher text" and the "nonce to hex" back to php through ajax and try to decrypt the message using:
$jsnonce=sodium_hex2bin($n2h);
$keydc=$keysk.$pk;
$text=sodium_crypto_box_open($ctext,$jsnonce,$keydc);

I get this error:
Uncaught SodiumException: keypair size should be SODIUM_CRYPTO_BOX_KEYPAIRBYTES.

I'll attach the two files Im using to play around. Please help?
Thanks very much

test.docx
testrespoonse.docx

@RicardoSette
Copy link

Hi @EmileDew,

I had crypto_box and crypto_secretbox compatibility with PHP 5.6.

Here's an example I used for proof of concept with PHP 5.6
example.php.txt
example.ajax.php.txt

If you are using PHP 7.1 or higher replace "\Sodium" with "sodium_" in PHP code.

@MilaSy
Copy link
Author

MilaSy commented Nov 10, 2018

Thank you so much @RicardoSette :)
Going to check it out now :D

@tonyg
Copy link
Owner

tonyg commented Nov 19, 2018

Hi @EmileDew. In this snippet...

$keydc=$keysk.$pk;
$text=sodium_crypto_box_open($ctext,$jsnonce,$keydc);

... it looks like you're passing the public key to crypto_box_open? You probably need to supply the recipient's secret key (and the sender's public key).

@RicardoSette, thanks for supplying your example code!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants