import java.math.BigInteger;
import java.security.MessageDigest;
public class Authenticate {
public static final String KEY_SHA = "SHA";
public static final String KEY_SALT = "FJLA2345&^";
userId:用户ID
password:用户明文密码
shaPassword:用户加密后密文
*/
public boolean checkPW(String userId,String password,String shaPassword){
boolean bl = false;
String shaPwd = getPasswordSHA(userId,password);
if(shaPwd.equals(shaPassword)){
bl=true;
}
return bl;
}
userId:用户ID
password:用户明文密码
*/
public String getPasswordSHA(String userId,String password){
String salt = SHA(KEY_SALT+userId);
String shaPwd = SHA(SHA(password)+salt);
return shaPwd;
}
inputStr:加密字符串
*/
public String SHA(String inputStr)
{
BigInteger sha =null;
byte[] inputData = inputStr.getBytes();
try {
MessageDigest messageDigest = MessageDigest.getInstance(KEY_SHA);
messageDigest.update(inputData);
sha = new BigInteger(messageDigest.digest());
} catch (Exception e) {e.printStackTrace();}
return sha.toString(32);
}
评论