java四大基本加密法只BASE64

来源:互联网 发布:淘宝客都在哪里做推广 编辑:程序博客网 时间:2024/06/06 05:52

无聊翻翻网页,看到java的四大加密算法BASE64, MD5(mwssage digest algorithm 5 信息摘要算法), SHA(secure hash algorithm 安全散列算法), HMAC(hash message authentication code 散列消息鉴别码). 摘抄下来。

BASE64 常见于邮件,http加密,截取http信息,你就会发现登录操作的用户名,密码字段通过BASE64加密的。

//导入包

import sun.misc.BASE64Decoder; 

import sun.misc.BASE64Encoder; 

public class BASE64{

//加密

           public static String encryptBASE64(byte[ ] key) throws Exception{

                                return(new BASE64Encoder()).encodeBuffer(key);

                               }

//解密

         public static byte[ ] decryptBASE64(String key) throws Exception{

                               return(new BASE64Decoder()).decodeBuffer(key);

                             }


//测试

        public static void main (String [ ] args) {

        String str=" 1234567";

      try{

       String password1=BASE64.encryptBASE64( str.getBytes());

       System.out.println(" 加密数据"+password1)

      byte password2 [ ] =BASE64.decryptBASE64(password1);

     String str2=new String(password2);

    System.out.println(" 解密数据"+str2);

    }Catch(Exception e) {

      e.printStackTrace();

               }

          }

}

0 0