• 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);
        }
    
    
    
  • 相关阅读:
    Jmeter之定时器
    Jmeter环境部署及目录解析
    Linux之shell脚本(基础篇)
    Linux常用命令
    Nginx详细安装部署教程(转)
    lsyncd+rsync文件实时同步
    windows7下搭建robot framework环境
    Python 类和实例
    第一个自动化运维程序
    Python之 set的特点
  • 原文地址:https://www.cnblogs.com/kutsu/p/14678261.html
Copyright © 2020-2023  润新知