我有一个字节数组.我希望将该数组的每个字节字符串转换为其对应的十六进制值.
Java中是否有任何函数将字节数组转换为十六进制?
我将用户密码存储在db上作为sha1哈希.
不幸的是,我得到了奇怪的答案.
我将字符串存储为:
MessageDigest cript = MessageDigest.getInstance("SHA-1");
cript.reset();
cript.update(userPass.getBytes("utf8"));
this.password = new String(cript.digest());
Run Code Online (Sandbox Code Playgroud)
我想要这样的东西 - >
aff - >"0c05aa56405c447e6678b7f3127febde5c3a9238"
而不是
aff - > V@ \D~fx : 8
我正在尝试模拟谷歌+按钮.在LINK的某些部分代码中,它将会话ID转换为某种哈希.我发现会话ID名称是SAPISID,转换后的哈希名称是SAPISIDHASH,任何人都可以告诉我代码的哪一部分哈希部分.任何帮助将不胜感激.我已经花了6个小时直,仍然没有线索:(
例如VUOyLIU22fNPz2ko/AbGsxW03_WHoGjaJq is SAPISID
和f17aa630b9b9a105dad437b0fedcafe429f6fca2 is SAPISIDHASH
.在PHP我尝试了所有类型的哈希..没有匹配.
我已经尝试了以下代码来生成String的SHA1摘要:
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Formatter;
public class SHA1 {
private static String encryptPassword(String password)
{
String sha1 = "";
try
{
MessageDigest crypt = MessageDigest.getInstance("SHA-1");
crypt.reset();
crypt.update(password.getBytes("UTF-8"));
sha1 = byteToHex(crypt.digest());
}
catch(NoSuchAlgorithmException e)
{
e.printStackTrace();
}
catch(UnsupportedEncodingException e)
{
e.printStackTrace();
}
return sha1;
}
private static String byteToHex(final byte[] hash)
{
Formatter formatter = new Formatter();
for (byte b : hash)
{
formatter.format("%02x", b);
}
String result = formatter.toString();
formatter.close();
return result;
}
public static void …
Run Code Online (Sandbox Code Playgroud) 当我尝试在 java gwt 中编译时,它显示以下问题
注意:使用 gwt 2.0 java 6 (jre 1.6) 的版本也在 1.8 中尝试过
public static String EncryptPassowrd(String password)
{
String encryptedPassword = "";
byte[] actualBytes = password.toString().getBytes();
byte[] newbytes = new byte[actualBytes.length * 2];
for (int i = 0; i < actualBytes.length; i++)
{
newbytes[2 * i] = actualBytes[i];
newbytes[2 * i + 1] = 0;
}
try
{
MessageDigest md = MessageDigest.getInstance("SHA-1");
md.reset();
md.update(newbytes);
byte[] encryptedbytes = md.digest();
for (int i …
Run Code Online (Sandbox Code Playgroud)