And*_*rei 0 java blackberry sha256
在BlackBerry应用程序中,我使用此代码以从密码获取哈希:
SHA256Digest sha256d = new SHA256Digest();
byte[] passwordData = null;
try {
passwordData = password.getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
DigestOutputStream outputStream = new DigestOutputStream(sha256d, null);
try {
outputStream.write(passwordData);
} catch (IOException e) {
e.printStackTrace();
}
byte[] hashedValue = sha256d.getDigest();
tempSHA256Password = new String(hashedValue);
System.out.println(tempSHA256Password);
Run Code Online (Sandbox Code Playgroud)
在这个代码块的末尾,tempSHA256Password它将是这样的东西:ëÇ#ÎiGê8óq =ßÝ÷<rê¨_FR»ã...所以绝不是我所期待的.我期待一个看起来像这样的字符串:ebc723ce6947ea38f371a03d0cdfddf73c840f7215eaa85f031446529bbb16e3
我究竟做错了什么?
的insted的tempSHA256Password = new String(hashedValue);
试试这个代码:
StringBuffer buffer = new StringBuffer();
for(byte b : hashedValue)
{
buffer.append(String.format("%02x",b<0 ? b+256 : b));
}
tempSHA256Password = buffer.toString();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
398 次 |
| 最近记录: |