Android端Base64编码与解码

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/itlihongzhi/article/details/53185927

base64编码,函数如下:

public static String makeUidToBase64(long uid){
        Log.d(TAG,"makeUidToBase64 uid = "+uid);
        String strUid = String.valueOf(uid);
        String enUid = new String(Base64.encode(strUid.getBytes(), Base64.DEFAULT));
        Log.d(TAG,"makeUidToBase64 enUid = "+enUid);
        return enUid;
    }

base64解码,函数如下:

public static long getUidFromBase64(String base64Id){
        long uid = -1l;
        if(!TextUtils.isEmpty(base64Id)){
            Log.d(TAG,"getUidFromBase64 enUID = "+base64Id);
            String result ="";
            if(!TextUtils.isEmpty(base64Id)){
                result = new String(Base64.decode(base64Id.getBytes(),Base64.DEFAULT));
                uid = Long.parseLong(result);
            }
        }
        Log.d(TAG,"getUidFromBase64 uid = "+uid);
        return uid;
    }

注意事项:

1.加密时,可能还要配合移位,加前缀后缀等,要注意uid值不要溢出

展开阅读全文

没有更多推荐了,返回首页