java四大基本加密法只BASE64

无聊翻翻网页,看到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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值