ByteArrayWrapper.wrap(String) no longer uses SHA256 hash of string, it
uses the UTF8 bytes of the string directly.
This commit is contained in:
parent
b129364ee0
commit
47e73efb52
@ -15,8 +15,6 @@
|
|||||||
*/
|
*/
|
||||||
package dorkbox.util.bytes;
|
package dorkbox.util.bytes;
|
||||||
|
|
||||||
import org.bouncycastle.crypto.digests.SHA256Digest;
|
|
||||||
|
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
@ -83,6 +81,9 @@ class ByteArrayWrapper {
|
|||||||
return new ByteArrayWrapper(data, false);
|
return new ByteArrayWrapper(data, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the UTF8 bytes from the string, and wraps them in a ByteArrayWrapper.
|
||||||
|
*/
|
||||||
public static
|
public static
|
||||||
ByteArrayWrapper wrap(String data) {
|
ByteArrayWrapper wrap(String data) {
|
||||||
if (data == null) {
|
if (data == null) {
|
||||||
@ -90,13 +91,7 @@ class ByteArrayWrapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
byte[] bytes = data.getBytes(UTF_8);
|
byte[] bytes = data.getBytes(UTF_8);
|
||||||
|
return ByteArrayWrapper.wrap(bytes);
|
||||||
SHA256Digest digest = new SHA256Digest();
|
|
||||||
digest.update(bytes, 0, bytes.length);
|
|
||||||
byte[] hashBytes = new byte[digest.getDigestSize()];
|
|
||||||
digest.doFinal(hashBytes, 0);
|
|
||||||
|
|
||||||
return ByteArrayWrapper.wrap(hashBytes);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public
|
public
|
||||||
|
Loading…
Reference in New Issue
Block a user