zoukankan      html  css  js  c++  java
  • Java base64 编码、解码

    public class uploadServletTest {
    
        @Test
        public void name() throws IOException {
    
            String content = "这里是Base64编码的内容";
    
            //编码
            BASE64Encoder base64Encoder = new BASE64Encoder();
            String encodeStr = base64Encoder.encode(content.getBytes("utf-8"));
            System.out.println(encodeStr);
    
            //解码
            BASE64Decoder base64Decoder = new BASE64Decoder();
            byte[] bytes = base64Decoder.decodeBuffer(encodeStr);
            String s = new String(bytes, "utf-8");
            System.out.println(s);
        }
    }
    

    手动。。

    
        public static String decipher(String s) {
            int[] a = {4, 9, 6, 2, 8, 7, 3};
            char[] res = new char[s.length()];
    
            for (int i = 0, j = 0; j < s.length(); j++, i = (i + 1) % 7) {
                res[j] = (char) ((byte) s.charAt(j) + a[i]);
                if ((byte) res[j] > 122)
                    res[j] = (char) ((byte) res[j] - 90);
            }
            return String.valueOf(res);
        }
        public static String encipher(String s) {
            int[] a = {4, 9, 6, 2, 8, 7, 3};
            char[] res = new char[s.length()];
    
            for (int i = 0, j = 0; j < s.length(); j++, i = (i + 1) % 7) {
                res[j] = (char) ((byte) s.charAt(j) - a[i]);
                if ((byte) res[j] < 32)
                    res[j] = (char) ((byte) res[j] + 90);
            }
            return String.valueOf(res);
        }
    
    
    
  • 相关阅读:
    序列化 Serialization
    http soap关系
    sql 查询
    返回最后插入到标识列的值(scope_identity.ident_current.@@identity)
    匿名方法
    九、volatile与Java内存模型
    八、Java内存模型JMM
    十、CAS
    CUSTOM ROUTE CONSTRAINTS
    获取本地数据库
  • 原文地址:https://www.cnblogs.com/kutsu/p/14678261.html
Copyright © 2011-2022 走看看