Encrypted data transmission between Android and PHP

Source: Internet
Author: User

1    mcrypt = 2    3    String encrypted = MCrypt.bytesToHex( mcrypt.encrypt("Text to Encrypt"4    5    String decrypted = 1    $mcrypt = 23    $encrypted = $mcrypt->encrypt("Text to encrypt"45    $decrypted = $mcrypt->001    002    003     004        005     006        007        008        009        010     011         012     013             String iv = "fedcba9876543210";014            015            016            017            018             String SecretKey = "0123456789abcdef";019            020            021022                ivspec = 023     024                keyspec =  SecretKeySpec(SecretKey.getBytes(), "AES"025                026                027                    cipher = Cipher.getInstance("AES/CBC/NoPadding"028                } 029                    030031                } 032                    033034035036            037             [] encrypt(String text) 038039                (text ==  || text.length() == 0040                      Exception("Empty string"041                042                [] encrypted = 043     044                045046     047                    encrypted =048                } 049050                      Exception("[encrypt] " +051052                053                054055            056             [] decrypt(String code) 057058                (code ==  || code.length() == 0059                      Exception("Empty string"060                061                [] decrypted = 062     063                064065                    066                    decrypted =067                } 068069                      Exception("[decrypt] " +070071                072073            074     075            076              String bytesToHex(077078                 (data==079080                     081082                083                 len =084                String str = ""085                 ( i=0; i<len; i++086                     ((data[i]&amp;0xFF)&lt;16087                        str = str + "0" + java.lang.Integer.toHexString(data[i]&amp;0xFF088                    089                        str = str + java.lang.Integer.toHexString(data[i]&amp;0xFF090091                092093            094                095              096                 (str==097                     098                }   (str.length() &lt; 2099                     100                } 101                     len = str.length() / 2102                    [] buffer =  103                     ( i=0; i&lt;len; i++104                        buffer[i] = () Integer.parseInt(str.substring(i*2,i*2+2),16105106                    107108109            110            111     112             113114               paddingChar = ' '115               size = 16116               x = source.length() %117               padLength = size -118     119               ( i = 0; i &lt; padLength; i++120121                  source +=122123     124              12512601    02    03     04    &lt;?05     06    0708         $iv = 'fedcba9876543210'09         $key = '0123456789abcdef'10     11     12131415     1617     18          19          $iv = $-&20     21          $td = mcrypt_module_open('rijndael-128', '', 'cbc'22     23          mcrypt_generic_init($td, $-&24          $encrypted =25     262728     29          3031     3233          34          $code = $-&35          $iv = $-&36     37          $td = mcrypt_module_open('rijndael-128', '', 'cbc'38     39          mcrypt_generic_init($td, $-&40          $decrypted =41     424344     45          4647     48        49          $bindata = ''50     51           ($i = 0; $i &lt; strlen($hexdata); $i += 252            $bindata .= chr(hexdec(substr($hexdata, $i, 25354     55          5657     5859    

 

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.