php base64不能解码_php-Android 不能解码 PHP base64 代码

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

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

Server Sideecho 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 Codetry { 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 }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值