提交 e5b24c9f authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Do not create additional temporary objects in SHA256.getHash()

上级 86e3efc9
...@@ -169,13 +169,16 @@ public class SHA256 { ...@@ -169,13 +169,16 @@ public class SHA256 {
* @return the hash code * @return the hash code
*/ */
public static byte[] getHash(byte[] data, boolean nullData) { public static byte[] getHash(byte[] data, boolean nullData) {
int len = data.length; byte[] result;
SHA256 sha = new SHA256(); try {
sha.calculateHash(data, len); result = MessageDigest.getInstance("SHA-256").digest(data);
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
if (nullData) { if (nullData) {
Arrays.fill(data, (byte) 0); Arrays.fill(data, (byte) 0);
} }
return sha.result; return result;
} }
private void calculateHash(byte[] data, int len) { private void calculateHash(byte[] data, int len) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论