java的Base64加密

1.java安全组成

  • JCA(Java Cryptography Architecture)

  • JCE(Java Cryptography Extension)

  • JSSE(Java Secure Socket Extension)

  • JAAS(Java Authentication and Authentication Service)

    DES AES RSA算法通过jce提供,jsse提供基于ssl的加密功能,主要用于网络传输

2.相关java包 类

  • java.security –消息摘要

  • java.crypto –安全消息摘要,消息认证(鉴别)码

  • java.net.ssl –安全套接字

3.java第三方的扩展
    Bouncy Castle
    –两种支持方案:1)文件配置;2)代码调用
    Commons Codec
    –Apache
    –Base64,二进制,十六进制,字符集编码
    –Url编码/解码
4.Base64算法的产生和定义
    产生:解决邮件的历史问题
    定义:基于64个字符的编码算法
5.实现Base64加密

public static void jdkBase64()
    {
        try
        {
            BASE64Encoder encoder = new BASE64Encoder();
            String result = encoder.encode(str.getBytes());
            System.out.println("jdk base64 encode:"+result);

            BASE64Decoder decoder = new BASE64Decoder();
            byte[] mystr = decoder.decodeBuffer(result);
            System.out.println("jdk base64 decode:"+new String(mystr));
        }
        catch (Exception e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    public static void ccBase64()
    {
        byte[] encodeBytes = Base64.encode(str.getBytes());
        System.out.println("cc base64 encode:"+new String(encodeBytes));

        byte[] decodeBytes = Base64.decode(encodeBytes);
        System.out.println("cc base64 decode:"+new String(decodeBytes));
    }
    public static void bcBase64()
    {
        byte[] encodeBytes = org.bouncycastle.util.encoders.Base64.encode(str.getBytes());
        System.out.println("bc base64 encode:"+new String(encodeBytes));

        byte[] decodeBytes = org.bouncycastle.util.encoders.Base64.decode(encodeBytes);
        System.out.println("bc base64 decode:"+new String(decodeBytes));
    }

6.应用场景
e-mail,秘钥,证书文件

你可能感兴趣的:(加密,base64)