Php-Android cannot decode PHPbase64

Source: Internet
Author: User
I want to decode the Base64 code and then use the PHP server encoding. The program can run properly and can be decoded using PHP. However, when I use the Android mobile phone for decoding, the following error occurs: Base64DecoderException: encodedvaluehasinvalidtrailingbyteBase64Code: oLAwb6uSn2JXqAFTX + callback...

I want to decode the Base64 code and then use the PHP server encoding. The program can run properly and can be decoded using PHP. However, when I decode the program on an Android phone, the following error occurs:

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.