Struchkov Mark
bd6b7c1492
All checks were successful
continuous-integration/drone/push Build is passing
1.8 KiB
1.8 KiB
aliases | tags | date | zero-link | parents | linked | ||||
---|---|---|---|---|---|---|---|---|---|
|
2024-09-14 |
|
|
Преобразование строки в ../cryptography/SHA-256:
public class SHA {
public static String hashSha256(String data) {
try {
final MessageDigest digest = MessageDigest.getInstance("SHA-256");
byte[] encodedHash = digest.digest(data.getBytes(StandardCharsets.UTF_8));
return bytesToHex(encodedHash);
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException("Cannot find SHA-256 algorithm", e);
}
}
private static String bytesToHex(byte[] hash) {
final StringBuilder hexString = new StringBuilder();
for (byte b : hash) {
String hex = Integer.toHexString(0xff & b);
if (hex.length() == 1) {
hexString.append('0');
}
hexString.append(hex);
}
return hexString.toString();
}
}
Мета информация
Область:: ../../meta/zero/00 Снипеты для Java, ../../meta/zero/00 Криптография Родитель:: ../cryptography/SHA-256 Источник:: Создана:: 2024-09-14 Автор::