package jnpf.elnService.impl;
|
|
import java.nio.charset.StandardCharsets;
|
import java.security.MessageDigest;
|
import java.security.NoSuchAlgorithmException;
|
|
final class ElnRepeatAuditEventIds {
|
private static final int MAX_CLIENT_EVENT_ID_LENGTH = 70;
|
|
private ElnRepeatAuditEventIds() {
|
}
|
|
static String of(String operationCode, String phase) {
|
String candidate = operationCode + ":" + phase;
|
if (candidate.length() <= MAX_CLIENT_EVENT_ID_LENGTH) return candidate;
|
return "RPT-" + sha256(candidate);
|
}
|
|
private static String sha256(String source) {
|
try {
|
byte[] digest = MessageDigest.getInstance("SHA-256")
|
.digest(source.getBytes(StandardCharsets.UTF_8));
|
StringBuilder result = new StringBuilder(64);
|
for (byte value : digest) result.append(String.format("%02x", value & 0xff));
|
return result.toString();
|
} catch (NoSuchAlgorithmException exception) {
|
throw new IllegalStateException("SHA-256 不可用", exception);
|
}
|
}
|
}
|