zoukankan      html  css  js  c++  java
  • Base64加密

    package com.kaishengit.security;
    
    import java.util.Base64;
    
    /**
     * base64位的加密,不算做是正常的加密
     * @author kdj
     * 创建时间:2018年4月11日
     */
    public class Base64Test {
    
        
        /**
         * 应用场景:可以用于url的转码
         */
        
        
        private static String securityStr = "测试";
        
        public static void main(String[] args) {
            jdkBase64();
            commonBase64();
            bouncyBase64();
        }
        
        /**
         * jdk自带
         */
        public static void jdkBase64(){
            byte[] encode = Base64.getEncoder().encode(securityStr.getBytes());
            String encodeStr = new String(encode);
            System.out.println("encode:"+encodeStr);
            
            byte[] decode = Base64.getDecoder().decode(encodeStr);
            String decodeStr = new String(decode);
            System.out.println("decode:"+decodeStr);
        }
        
        /**
         * common自带
         */
        public static void commonBase64(){
            byte[] encode = org.apache.commons.codec.binary.Base64.encodeBase64(securityStr.getBytes());
            String encodeStr = new String(encode);
            System.out.println("encode:"+encodeStr);
            
            byte[] decode = org.apache.commons.codec.binary.Base64.decodeBase64(encodeStr);
            String decodeStr = new String(decode);
            System.out.println("decode:"+decodeStr);
        }
        
        /**
         * bouncy自带
         */
        public static void bouncyBase64(){
            byte[] encode = org.bouncycastle.util.encoders.Base64.encode(securityStr.getBytes());
            String encodeStr = new String(encode);
            System.out.println("encode:"+encodeStr);
            
            byte[] decode = org.bouncycastle.util.encoders.Base64.decode(encodeStr);
            String decodeStr = new String(decode);
            System.out.println("decode:"+decodeStr);
        }
        
        
    }

    列出来三种实现方式,JDK,Bouncy,Common

  • 相关阅读:
    多个tomcat配置,解决冲突问题
    多态-重载和覆载
    静态成员、静态类和枚举
    重复使用类--继承和组合
    建立更可靠的OOP程序-类和成员的访问控制
    用ps画一个Gif的小房子(1)
    在h5页面上添加音乐播放
    使用Object类为实例定义方法和属性
    使用 prototype 定义方法和属性
    使用 this 关键字定义方法和属性
  • 原文地址:https://www.cnblogs.com/fucktom/p/8853977.html
Copyright © 2011-2022 走看看