Php-android cannot decode PHP base64 code

Source: Internet
Author: User
Keywords PHP Base64 Java Android
Phpbase64javaandroid

I want to decode the BASE64 code and then encode it via PHP server. The program works correctly and can use PHP decoding, but when I decode it via my Android phone, I have the following error:

Base64DecoderException: encoded value has invalid trailing byte

Base64 Code:

oLAwb6uSn2JXqAFTX+qJXaOawOYF3kDDK2HlCb7ItCeimVCsDE7OYH5OgsixKpIAM6KgkCktnB4HsLQtA5Ig1fQvDrRcct9dQi4m8wPpF7a3sFHSG29j2aItKeouflTtsSZgKWvSjg0gBBGM/7PlvkuK+8W4/GXS0QrqV1jcngWrspYmAdi0GiJbPm8b/zlscOIa1z1df11SuQH5+GiUzqZ4WDFOpoH0WWVW3KmbMQ2yifBmXnhn80qZct6KiN7aL8PHEczhNrRqAKfUuEwmsWOnEOyh7UOU6FcnW3VAo2BWd5dJRGgWb5Py09l0XmrdWdzin7klKtMqXOWQRcvEVT7PKtQxQotRpOa+2IQQirVfybyuMipY9YORuW1hqmc95Tdt1WHdIzVwEtq6NXx9AC5mSklbxrcOpINfS2RPFcK0UUMV2xQKAQ+u8PzTj/KBEmb04ObBbnX6y3uL1KT58lDecA9lIbNYuttlgRMzRdxFOvkk21wou2vtMBtIxk0XFJJGjazqqcxVeSxTvQ68wdNSkRmvteowkSq2Vi09CmOhToRHemFyZgKTxSBoNaFuVuYGVggEFIR9kHVrLxoK2Q==

Server Side

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; }

My Java 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    }
  • 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.