base64加解密源码(可直接调用)

package com.example.rog_pc.myapplication ;

import android.util.Base64 ;

import java.io.UnsupportedEncodingException ;

/**
 * Created by a12 on 2016/7/31.
 */
public class amBase64String {
    // char set name
    public final static String  CHARSET "UTF-8" ;

    /**
     * Base64 
     *
     *  @param  strText 
      @return  String 
     *  @throws  Exception
     */
    public static String  encode(String strText)  {
    String strRet =  null;
    byte[] bytes =  new byte[ 0] ;

    try {
        bytes = Base64. encode(strText.getBytes( CHARSET) Base64. DEFAULT) ;
        strRet =  new String(bytes CHARSET) ;
   catch (UnsupportedEncodingException e) {
        e.printStackTrace() ;
    }
    return strRet ;
}

    /**
     * Base64 
     *
     *  @param  strEncode 
      @return  String 
     *  @throws  Exception
     */
    public static String  decode(String strEncode) {

        String strRet =  null;
        try {
            byte[] bytes = Base64. decode(strEncode.getBytes( CHARSET) Base64. DEFAULT) ;
            strRet =  new String(bytes CHARSET) ;
        } catch (Exception e){
            e.printStackTrace() ;
        }
        return strRet ;
    }
}

猜你喜欢

转载自blog.csdn.net/assyiran/article/details/76442778