首頁 > 後端開發 > php教程 > php-Android 不能解码 PHP base64 代码

php-Android 不能解码 PHP base64 代码

WBOY
發布: 2016-06-02 11:34:43
原創
1418 人瀏覽過

phpbase64javaandroid

我想解码Base64代码,再通过PHP服务器编码。程序能正常运行能使用PHP解码,但是当我通过Android手机解码时,有下面的错误:

<code>Base64DecoderException: encoded value has invalid trailing byte</code>
登入後複製

Base64 Code:

<code>oLAwb6uSn2JXqAFTX+qJXaOawOYF3kDDK2HlCb7ItCeimVCsDE7OYH5OgsixKpIAM6KgkCktnB4HsLQtA5Ig1fQvDrRcct9dQi4m8wPpF7a3sFHSG29j2aItKeouflTtsSZgKWvSjg0gBBGM/7PlvkuK+8W4/GXS0QrqV1jcngWrspYmAdi0GiJbPm8b/zlscOIa1z1df11SuQH5+GiUzqZ4WDFOpoH0WWVW3KmbMQ2yifBmXnhn80qZct6KiN7aL8PHEczhNrRqAKfUuEwmsWOnEOyh7UOU6FcnW3VAo2BWd5dJRGgWb5Py09l0XmrdWdzin7klKtMqXOWQRcvEVT7PKtQxQotRpOa+2IQQirVfybyuMipY9YORuW1hqmc95Tdt1WHdIzVwEtq6NXx9AC5mSklbxrcOpINfS2RPFcK0UUMV2xQKAQ+u8PzTj/KBEmb04ObBbnX6y3uL1KT58lDecA9lIbNYuttlgRMzRdxFOvkk21wou2vtMBtIxk0XFJJGjazqqcxVeSxTvQ68wdNSkRmvteowkSq2Vi09CmOhToRHemFyZgKTxSBoNaFuVuYGVggEFIR9kHVrLxoK2Q==</code>
登入後複製

Server Side

<code>echo toAES("some stringe");function pkcs5_pad($text, $blocksize) {    $pad = $blocksize - (strlen($text) % $blocksize);    return $text . str_repeat(chr($pad), $pad);} function toAES($sStr) {    error_reporting(E_ERROR | E_PARSE);    $sKey = '1234567891234567';    $size = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB);    $sStr = pkcs5_pad($sStr, $size);    $td = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_ECB, '');    $iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($td), MCRYPT_RAND);    mcrypt_generic_init($td, $sKey, $iv);    $data = mcrypt_generic($td, $sStr);    mcrypt_generic_deinit($td);    mcrypt_module_close($td);    $data = base64_encode($data);    return $data;}function fromAES($sStr) {    error_reporting(E_ERROR | E_PARSE);    $sKey = '1234567891234567';    $decrypted = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $sKey, base64_decode($sStr), MCRYPT_MODE_ECB);    $dec_s     = strlen($decrypted);    $padding   = ord($decrypted[$dec_s - 1]);    $decrypted = substr($decrypted, 0, -$padding);return $decrypted;    }</code>
登入後複製

My Java Code

<code> try    {        SecretKeySpec mSecretKeySpec = new SecretKeySpec('1234567891234567'.getBytes(), "AES");        byte[] decrypted = Base64.decode(s.getBytes("UTF-8"), Base64.Deafult);        Cipher mCipher = Cipher.getInstance("AES/ECB/PKCS5Padding");        mCipher.init(Cipher.DECRYPT_MODE, mSecretKeySpec);        return new String(mCipher.doFinal(decrypted));    }    catch (Exception e)    {        e.printStackTrace();        return null; // Always return null with the posted error    }</code>
登入後複製
相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板