Solution for over 1024 encryption and decryption based on php rsa ciphertext, rsa ciphertext
As follows:
<? Phpnamespace helpers; class OpensslRSA {// echo $ private_key private key; public $ private_key = '----- begin rsa private key ----- MIICXQIBAAKBgQC + encrypt/decrypt/GN + TyFWP + encrypt/wDt4FCkCala + encrypt + EW1/decrypt + encrypt/lIpyq85e/decrypt + 61 ChTFrl/ examples/examples + rnutxizjlublcxtjv61_bylykkzguqy7/ZhBPsFL4GnCUBBKhh/samples + 6ouE + samples/samples ----- end rsa private key -----'; // public key public $ public_key = '----- begin public key ----- BEGIN + L7ENzBHxKOqjuFHPFKlAt40BatVZhUAHw/notify/GN + TyFWP + BEGIN ----- END public KEY -----';
Public $ pi_key; public $ pu_key; // determine whether the public key and private key are available public function _ construct () {$ this-> pi_key = openssl_pkey_get_private ($ this-> private_key ); // this function can be used to determine whether the private key is available. The Resource id $ this-> pu_key = openssl_pkey_get_public ($ this-> public_key) can be returned ); // this function can be used to determine whether the public key is available. // print_r ($ this-> pi_key); echo "\ n"; // print_r ($ this-> pu_key ); echo "\ n";} // Private Key Encryption/* public function PrivateEncrypt ($ data) {openssl_private_encrypt ($ data, $ encrypted, $ this-> pi_key ); $ encrypted = $ this-> urlsafe_b64encode ($ encrypted); // The encrypted content usually contains special characters and requires encoding and conversion, during url transmission between networks, pay attention to whether base64 encoding is url-safe return $ encrypted;} */public function PrivateEncrypt ($ data) {// openssl_private_encrypt ($ data, $ encrypted, $ this-> pi_key); $ crypto = ''; foreach (str_split ($ data, 117) as $ chunk) {openssl_private_encrypt ($ chunk, $ encryptData, $ this-> pi_key); $ crypto. = $ encryptData;} $ encrypted = $ this-> urlsafe_b64encode ($ crypto); // The encrypted content usually contains special characters and requires encoding and conversion, during url transmission between networks, pay attention to whether base64 encoding is url-safe return $ encrypted ;}
// Replace the special symbol with the URL Content function urlsafe_b64encode ($ string) {$ data = base64_encode ($ string ); $ data = str_replace (array ('+', '/', '='), array ('-', '_', ''), $ data ); return $ data;} // Replace the converted symbol with the special symbol urlsafe_b64decode ($ string) {$ data = str_replace (array ('-','_'), array ('+', '/'), $ string); $ mod4 = strlen ($ data) % 4; if ($ mod4) {$ data. = substr ('====', $ mod4);} return base64_decode ($ data );} // The private key can be decrypted using the public key. public function PublicDecrypt ($ encrypted) {// $ encrypted = $ this-> urlsafe_b64decode ($ encrypted ); $ crypto = ''; foreach (str_split ($ this-> urlsafe_b64decode ($ encrypted), 128) as $ chunk) {openssl_public_decrypt ($ chunk, $ decryptData, $ this-> pu_key); $ crypto. = $ decryptData;} // openssl_public_decrypt ($ encrypted, $ decrypted, $ this-> pu_key); // the private key-encrypted content can be decrypted using the public key. return $ crypto ;} // public key encryption public function PublicEncrypt ($ data) {// openssl_public_encrypt ($ data, $ encrypted, $ this-> pu_key); // public key encryption $ crypto = ''; foreach (str_split ($ data, 117) as $ chunk) {openssl_public_encrypt ($ chunk, $ encryptData, $ this-> pu_key); $ crypto. = $ encryptData;} $ encrypted = $ this-> urlsafe_b64encode ($ crypto); return $ encrypted;} // Private Key decryption public function PrivateDecrypt ($ encrypted) {$ crypto = ''; foreach (str_split ($ this-> urlsafe_b64decode ($ encrypted), 128) as $ chunk) {openssl_private_decrypt ($ chunk, $ decryptData, $ this-> pi_key); $ crypto. = $ decryptData;} // $ encrypted = $ this-> urlsafe_b64decode ($ encrypted); // openssl_private_decrypt ($ encrypted, $ decrypted, $ this-> pi_key ); return $ crypto ;}}
You don't need to write more. If you have any questions, contact me directly.
The above solution, based on the php rsa ciphertext, is to share all the content with you through encryption and decryption over 1024. I hope to give you a reference and support for the customer's house.