Android 和 PHP 之間進行資料加密傳輸

來源:互聯網
上載者: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    

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.