jsp怎么把数据加密

968
2021/1/20 11:44:58
栏目: 编程语言
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

jsp怎么把数据加密

jsp使用MD5对数据进行加密,具体方法如下:

import java.security.MessageDigest;

import java.security.NoSuchAlgorithmException;


public class MD5Digest{

private MessageDigest __md5 = null;

private StringBuffer __digestBuffer = null;

public MD5Digest()


throws NoSuchAlgorithmException{

__md5 = MessageDigest.getInstance("MD5");

__digestBuffer = new StringBuffer();

}


public String md5crypt(String s){

__digestBuffer.setLength(0);

byte abyte0[] = __md5.digest(s.getBytes());

for(int i = 0; i < abyte0.length; i++)

__digestBuffer.append(toHex(abyte0[i]));

return __digestBuffer.toString();

}


public String toHex(byte one){

String HEX="0123456789ABCDEF";

char[] result=new char[2];

result[0]=HEX.charAt((one & 0xf0) >> 4);

result[1]=HEX.charAt(one & 0x0f);

String mm=new String(result);

return mm;

}

}



辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读: post提交数据如何加密