📄 hashsha1string.java
字号:
/*
* Created on 2007-6-29
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package com.ai.get24;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import sun.misc.BASE64Encoder;
/**
* @author Vincent.Zhang
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class HashSHA1String {
public String hashSHA1String(String dataToHash) {
String tmp = null;
String salt = "abcedefghijklmnopqrstuvwxyz";
try {
//One-way hash
MessageDigest md = MessageDigest.getInstance("SHA1");
md.update(salt.getBytes());
byte[] byteTmpe = md.digest(dataToHash.getBytes());
//base 64 encoding, using sun's internal lib
BASE64Encoder b64encoder = new BASE64Encoder();
tmp = b64encoder.encode(byteTmpe);
} catch (NoSuchAlgorithmException e) {
// silence and return null
}
return tmp;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -