Java中导入Base64 encode and decode包并使用

  public static byte[] base64ToByte(String data) throws IOException {      byte[] apacheBytes=Base64.decodeBase64(data);       return apacheBytes;   }
public static String byteToBase64(byte[] data){   byte[] apacheBytes=Base64.encodeBase64(data);   String fromApacheBytes = new String(apacheBytes);       return fromApacheBytes;   }

在加密算法中,比如说要对数据库中的用户名和密码加密,一般我们会使用salt和SHA1来做,这时候就要用到一些函数。

Base64.decodeBase64
Base64.encodeBase64

这两个函数如何加载呢?今天晚上正好用到了,写一下。

点击打开链接

从这个网站下下载包,解压得到

commons-codec-1.8.jar

或者其他版本也可以

然后加到你的eclipse 工程中,右键,build path, 加链接

然后就可以在Referenced Libraries中看到了

import后就搞定了。

比如输入abcdefgh, 加密,解密的结果如下:

[B@65612c8fabcdefgh

他们不计后果的彼此拥抱,握紧双手,怕天会亮,怕爱会走。

Java中导入Base64 encode and decode包并使用

相关文章:

你感兴趣的文章:

标签云: