PHP interface Data encryption, decryption, verification of signature Code instances

Source: Internet
Author: User
Tags crypt
PHP interface Data encryption, decryption, verification of signature Code instances

PHP interface Data encryption, decryption, authentication signature

The code is very simple, there is no more nonsense, directly on the code

 Setkey ($aeskey);//decrypt AES Ciphertext $plaintext = $aes->decrypt (Base64_decode ($crypttext)); echo $plaintext; Echo '
 
  
 ';//aes encrypted plaintext//echo $aes->encrypt ($plaintext);//rsa public key $publickey = ' migfma0gcsqgsib3dqebaquaa4gnadcbiqkbgqcffoeivyut9jw5w1l5ukx4advd837a8jhawm5s8yqnqfgemfd9t+rdknxlqmt+ dxeqaqgo4hbmcbej1aomzn6hijhk3/tftatonn8fgwdothewstcbbvkqwtdtby3gouwtovsri1i/a0vfb0+ Xm8mnf46ddhhrnzrycerbsbyrcwidaqab ';//echo base64_decode ($publickey);//rsa signature $signature = ' xhin4uufqrkdehkbd/ hqisxlffsxm6ezcvcpqnwcqjq3uep3ayxmfuugve0xoh4aiwjiisowdnatol1bxvafkwjctxnkarwupvwrk+ Q0eqwsoadywsvqdeceg5stas1ckptrznaiw2ebgxcwspoj+aumeacpyydxlhdn646krzw= ';//echo base64_decode ($signature); $rsa = New Crypt_rsa ();//Set RSA signature mode CRYPT_RSA_SIGNATURE_PSS or Crypt_rsa_signature_pkcs1$rsa->setsignaturemode (CRYPT_ RSA_SIGNATURE_PKCS1);//var_dump ($rsa->createkey ());//Generate RSA public key, private key//extract ($rsa->createkey ());// Use RSA private key to generate signature//$rsa->loadkey ($privatekey);//$signature = $rsa->sign ($plaintext);//Use RSA Public key to verify signature echo $plaintext; $rsa->loadkey (Base64_decode ($publickey)); Echo $rsa->verify ($plaintext, Base64_decode ($signature))? ' Verified ': ' UNverified '; Echo ' 
 
  
 ';//Generate RSA public key, private key//var_dump ($rsa->createkey ()), Extract ($rsa->createkey ());//Encrypt data with RSA private key $rsa->loadkey ($ Privatekey); $ciphertext = $rsa->encrypt ($plaintext);//Use RSA public key to decrypt data $rsa->loadkey ($publickey); Echo $rsa Decrypt ($ciphertext);

whenever you talk about transactions such as money issues, you need to pay particular attention to security considerations, such as developing a forum or a shopping cart.

Extended Reading

"PHP Practical Problem Solving case" series of technical Articles to organize the collection

1PHP Chinese pinyin conversion and Gregorian lunar calendar conversion

2php Shopping Cart Realization method

3PHP method for formatting file data size display

4php+jquery real-time display of online site numbers

5PHP realizes whether the user is mobile Access

6PHP function to escape special characters in JSON

7php socket-based SMTP method for sending mail

8PHP How to Query Express information

9PHP simple way to get a video preview

10php interface Data encryption, decryption, authentication signature

11php method for calculating file footprint in a specified directory

12php methods for replicating directories and subdirectories recursively

How to delete an entire directory in 13php by Directoryiterator

14PHP Generate Thunder, Express, Cyclone and other software download link code example

15PHP Chinese garbled classification and solving methods Daquan

16php random selection of several non-repeating elements from an array

17PHP File Upload Problem Summary--file size detection and large file upload processing

18 How to modify the PHP memory_limit limit

19php determine whether a request is an AJAX request or a normal request method

20PHP super-good infinite pole classification spanning tree method

21 Long Micro Boshengchen (convert HTML to picture) principle analysis

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

1 floor qq2291738886 yesterday 20:51
2291738886
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.