hashsha1string.java
来自「用HASH加密字符传」· Java 代码 · 共 36 行
JAVA
36 行
/*
* 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 + =
减小字号Ctrl + -
显示快捷键?