1

Reciever:

$secureRandom = openssl_random_pseudo_bytes(32, $strong);
$private = curve25519_private($secureRandom);
$public = curve25519_public($private);

the reciever sends $public to the sender.

The sender encrypt the message 'Hello'

$x = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $public, 'Hallo', MCRYPT_MODE_CBC, 9999)

and send the encrypted message to the reciever.

the reciever can now decrypt the message with his private key

$result = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $private, DECRYPTED_MESSAGE, MCRYPT_MODE_CBC, 9999);

i await that $result has 'Hallo' but that do not work at me.

can you help?

user7396065
  • 39
  • 1
  • 7
  • what's your php version and does there any errors ? – hassan Mar 03 '17 at 13:53
  • 1
    shouldn't `DECRYPTED_MESSAGE` be just `$x`? – ewcz Mar 03 '17 at 13:56
  • phpinfo says: 5.5.9-1ubuntu4.21 – user7396065 Mar 03 '17 at 14:25
  • there are no errors, the result from mcrypt_encrypt is ,ÛíB­q4¬&ð¶Y» and that is right because the message is encrypted, but the result from mcrypt_decrypt is ;ô"©èeß2$:¸d| also encrypted, i await Hallo – user7396065 Mar 03 '17 at 14:28
  • 1
    [Mcrypt doesn't support public key encryption](http://stackoverflow.com/questions/2649672/does-mcrypt-support-asymmetric-encryption). You're encrypting with a symmetric cypher using one key and decrypting it with a different key. You're already on the right track using `openssl` functions but you're only using it to generate your key, look at [openssl_public_encrypt](http://php.net/manual/en/function.openssl-public-encrypt.php) and openssl_public_decrypt functions. – Lucas Krupinski Mar 03 '17 at 14:36
  • i have learned that one encrypt a message with the public key von reciever, the reciever gets the encrypted message and decrypt it with his private key, therefor two different keys. or is that not right? – user7396065 Mar 03 '17 at 15:20

0 Answers0