This article mainly introduces data encryption, decryption, and signature verification on the php interface. if you need more information, you can refer to the code below. it is very simple.
The code is as follows:
<? Php
// Header ('content-Type: text/xml; charset = utf-8 ');
Include_once (dirname (_ FILE _). DIRECTORY_SEPARATOR. 'phpsec '. DIRECTORY_SEPARATOR. 'math'. DIRECTORY_SEPARATOR. 'biginteger. php ');
Include_once (dirname (_ FILE _). DIRECTORY_SEPARATOR. 'phpsec '. DIRECTORY_SEPARATOR. 'Crypt'. DIRECTORY_SEPARATOR. 'aes. php ');
Include_once (dirname (_ FILE _). DIRECTORY_SEPARATOR. 'phpsec '. DIRECTORY_SEPARATOR. 'Crypt'. DIRECTORY_SEPARATOR. 'RSA. php ');
// Ciphertext
$ Crypttext = 'encrypt/decrypt/k/encrypt/decrypt/xGb0g2XE/encrypt + qB7P/EMII/encrypt + 0 lujNgxIq/encrypt/hBT1UvIUml + encrypt/JcDCrdy0Co/decrypt + decrypt /release + btyn1_v/release + nQjj1THk0XHFc69N9g2 + Release/QVVU2julTeKunvgAAEc3n + Release/revgpasTOzDQa5NqR1B + release + CA ';
$ Aeskey = base64_decode ('qze60qzfxuirub2ey4 + 7 + Q = ');
// AES decryption, in ECB mode
$ Aes = new Crypt_AES (CRYPT_MODE_ECB );
// Set the AES key
$ Aes-> setKey ($ aeskey );
// Decrypt the AES ciphertext
$ Plaintext = $ aes-> decrypt (base64_decode ($ crypttext ));
Echo $ plaintext;
Echo'
';
// AES encrypted plaintext
// Echo $ aes-> encrypt ($ plaintext );
// Rsa public key
$ Publickey = 'prop + rDknXLqMT + DXeQAqGo4hBmcbej1aoMzn6hIJHk3/large/A0Vfb0 + xm8mnf46ddhhrrycerbsbyrcwidaqab ';
// Echo base64_decode ($ publickey );
// Rsa signature
$ Signature = 'xhin4uufqrkdehkbd/signature + Q0eqwsoAdywsVQDEceG5stas1CkPtrznAIW2eBGXCWspOj + aumEAcPyYDxLhDN646Krzw = ';
// Echo base64_decode ($ signature );
$ Rsa = new Crypt_RSA ();
// Set the RSA signature mode CRYPT_RSA_SIGNATURE_PSS or CRYPT_RSA_SIGNATURE_PKCS1
$ Rsa-> setSignatureMode (CRYPT_RSA_SIGNATURE_PKCS1 );
// Var_dump ($ rsa-> createKey ());
// Generate the RSA public key and private key
// Extract ($ rsa-> createKey ());
// Use the RSA private key to generate a signature
// $ Rsa-> loadKey ($ privatekey );
// $ Signature = $ rsa-> sign ($ plaintext );
// Use the RSA public key to verify the signature
Echo $ plaintext;
$ Rsa-> loadKey (base64_decode ($ publickey ));
Echo $ rsa-> verify ($ plaintext, base64_decode ($ signature ))? 'Verified ': 'unverified ';
Echo' ';
// Generate the RSA public key and private key
// Var_dump ($ rsa-> createKey ());
Extract ($ rsa-> createKey ());
// Use the RSA private key to encrypt data
$ Rsa-> loadKey ($ privatekey );
$ Ciphertext = $ rsa-> encrypt ($ plaintext );
// Use the RSA public key to decrypt data
$ Rsa-> loadKey ($ publickey );
Echo $ rsa-> decrypt ($ ciphertext );
The above is all the content described in this article. I hope this code can help you learn more about encryption and decryption in php.