Bases64 笔记

 @Test
    public void Bases64(){
       String s = "5b0aa3ebab"+":"+"aa2bc60e27e44e7bb23896d5d4002f79";
       System.out.println("原字符串:" + s);
       String encryptString = encryptBASE64(s);
       System.out.println("加密后:" + encryptString);
       System.out.println("解密后:" + decryptBASE64(encryptString));
   }
    /**
     * BASE64解密
     *
     * @param key
     * @return
     * @throws Exception
     */
    public static String decryptBASE64(String key) {
        byte[] bt;
        try {
            bt = (new BASE64Decoder()).decodeBuffer(key);
            return new String(bt);//如果出现乱码可以改成: String(bt, "utf-8")或 gbk
        } catch (IOException e) {
            e.printStackTrace();
            return "";
        }
    }

    /**
     * BASE64加密
     *
     * @param key
     * @return
     * @throws Exception
     */
    public static String encryptBASE64(String key) {
        byte[] bt = key.getBytes();
        return (new BASE64Encoder()).encodeBuffer(bt);
    }

猜你喜欢

转载自blog.51cto.com/357712148/2174977