开发者

Algorithm To be used for communications and generating keys?

I want to send some data to the client server as they will be using our services. Th开发者_StackOverflow中文版ere will be some communication about the player details. Which encryption should be used and how to generate the key for that encryption algorithm. Our code is in php.

Thanks In advance.


You can use the OpenSSL functions. This is how you generate a new public/private key pair:

$res = openssl_pkey_new();

openssl_pkey_export($res, $privatekey); // Get private key

$publickey = openssl_pkey_get_details($res); // Get public key
$publickey = $publickey["key"];

Store the private key on server and send the public key to clients, then on server:

openssl_private_encrypt( $data, $encrypted, $privatekey );

in client:

openssl_public_decrypt( $encrypted, $data, $publickey );


If you want to encrypt the data send from the client to your server or vice-versa, you should use SSL. You can get a cheap certificate for your website. If you don't have a certificate the encryption will still work but people visititng the website will see a warning regarding the invalid certificate.

Paying for a certificate will be around $10 (based on a Dutch company which sells them).


Maybe have a look at phpseclib, which includes an RSA implementation

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜