Useful PHP with public key cryptography class sharing (every time encryption results are different OH), PHP encryption
Web Interactive security has always been a major site of the first solution, this article introduces the PHP encryption class is very practical oh, with the public key, this is the biggest bright spot, no public key is not decrypted, plus density is very high.
Class Code:
<?php/** * PHP Encryption class * Qiong Tai 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 (0,32000)); $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; } }
How to use:
<?php//first contains the encryption class require_once (' jiami.class.php '); The string to encrypt $string = ' http://www.bkjia.com '; Instantiate the cryptographic class $jiami= new Jiami (); Set the public key $jiami->setkey (' QTTC '); Encrypted string $enc = $jiami->encrypt ($string, $jiami->getpk ()); Decrypt string $dec = $jiami->decrypt ($enc, $jiami->getpk ()); Echo '
; Echo ' before encryption: '. $string. '
'; Echo ' after encryption: '. $enc. '
'; Echo ' after decryption: '. $dec;? >
Page Execution Results
Result 1:
Result 2:
As you can see from the above results, each encryption string generated is different, which is random.
Decryption requires the use of the public key when encrypting, otherwise it cannot be decrypted. If you encrypt the public key using ' QTTC ', when decrypting, also need to use this ' QTTC ' as the public key to decrypt, otherwise cannot decrypt.
What are the different manifestations of symmetric key cryptography and asymmetric key encryption technology?
Symmetric encryption is faster than asymmetric encryption, the symmetric encryption key cannot be exposed, and the asymmetric private key must be public, the public key can be disclosed, about the management and release symmetric encryption is more complex, about the algorithm symmetric encryption is usually used Des,aes,idea. RSA for asymmetric use
The following is true for asymmetric key encryption
C. Encryption keys and decryption keys are the same
http://www.bkjia.com/PHPjc/866662.html www.bkjia.com true http://www.bkjia.com/PHPjc/866662.html techarticle practical PHP with Public key cryptography class sharing (every time encryption results are different OH), PHP encrypted web interaction Security has always been a major site of the first solution, this article introduces the PHP encryption class is very real ...