Practical PHP shared with public key encryption class (different encryption results every time), php encrypted. Practical PHP shared with public key encryption (different encryption results every time), php encrypted WEB interaction security has always been the primary solution for major websites, the PHP encryption class introduced in this article is a very practical PHP shared with public key encryption class (different encryption results every time), php encryption
WEB interaction security has always been the primary solution for every major website. The PHP encryption class introduced in this article is very practical. it has a public key. this is the biggest highlight and cannot be decrypted without a public key, the addition density is very high.
Class code:
<? Php/*** PHP encryption class * Qiongtai blog */class Jiami {// public key protected $ key = 'Lee '; private function keyED ($ txt, $ encrypt_key) {$ encrypt_key = md5 ($ encrypt_key); $ ctr = 0; $ tmp = ''; for ($ I = 0; $ I
Key;} srand (double) microtime () * 1000000); $ encrypt_key = md5 (rand (); $ ctr = 0; $ tmp = ''; for ($ I = 0; $ I
KeyED ($ tmp, $ key);} public function decrypt ($ txt, $ key = '') {if (empty ($ key )) {$ key = $ this-> key;} $ txt = $ this-> keyED ($ txt, $ key); $ tmp = ''; for ($ I = 0; $ I
Key = $ key;} public function getPK () {return $ this-> key ;}}
Usage:
<? Php // contains the encryption class require_once ('jiami. class. php '); // The string to be encrypted $ string = 'http: // www.bkjia.com'; // instantiate the encryption class $ jiami = new Jiami (); // set the public key $ jiami-> setKey ('qttc '); // encrypted string $ enc = $ jiami-> encrypt ($ string, $ jiami-> getPK ()); // decrypt the string $ dec = $ jiami-> decrypt ($ enc, $ jiami-> getPK (); echo'
'; Echo' before encryption: '. $ string .'
'; Echo 'encrypted:'. $ enc .'
'; Echo': '. $ dec;?>
Page execution result
Result 1:
Result 2:
From the above results, we can see that each encryption produces different encrypted strings, which are random.
You must use the public key to decrypt the data. Otherwise, the data cannot be decrypted. For example, if you use 'qttc 'as the encryption public key, you also need to use this 'qttc' as the public key for decryption. Otherwise, the decryption will fail.
What are the differences between symmetric key encryption technology and asymmetric key encryption technology?
Symmetric encryption is faster than asymmetric encryption. symmetric encryption keys cannot be made public, while asymmetric private keys must be kept public. it is complicated to manage and publish symmetric encryption, DES, AES, and IDEA are usually used for symmetric encryption of algorithms. Asymmetric RSA
Which of the following statements about asymmetric key encryption is true?
C. identical encryption keys and encryption keys
Encryption (the encryption results are different every time). php encrypted WEB interaction security has always been the primary solution for every major website. The PHP encryption class introduced in this article is very practical...