我正在尝试加密字符串消息,以便在我的应用中为相同的字符串消息获取相同的加密代码。如何使用相同的密钥获得相同的加密代码?
以下是我的代码。它正在生成加密代码,但它与在服务器
生成的代码不匹配 public String SHAsum(String convertme) {
MessageDigest md = null;
byte[] data;
try {
md = MessageDigest.getInstance("SHA-1");
data=convertme.getBytes("utf8");
md.update(data);
md.hashCode();
//md.update( key.getBytes() );
return new BigInteger( 1, md.digest() ).toString(16);
} catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} //This could also be SHA1withDSA, no exception handling
catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return "";
}
String password="qqqqq";
byte[] salt="guVoUubWwvniR2G0FgaC9".getBytes();
String abc="";
try
{
abc = getHash( password, salt);
System.out.println("Encypted password is -------------->"+abc);
}
catch (NoSuchAlgorithmException e1)
{
// TODO Auto-generated catch block
e1.printStackTrace();
}
catch (UnsupportedEncodingException e1)
{
// TODO Auto-generated catch block
e1.printStackTrace();
}