Алгоритм RSA с размером ключа 256 слишком мал для создания подписи!
Алгоритм RSA с размером ключа 256 слишком мал для создания подписи!
Алгоритм RSA с размером ключа 256 слишком мал для создания подписи! strong>
Я также вижу неопределенную ошибку в подписи при открытии PDF-файла в Acrobat Reader.
Вот схема моего процесса:< /p>
- Я генерирую хеш PDF-документа с использованием SHA-256.
- Я отправляю этот хэш в API, который подписывает его с помощью закрытого ключа RSA.
- Прикрепляю вставьте подпись в PDF-файл и проверьте ее с помощью инструмента проверки подписи.
Создание подписи работает без каких-либо ошибок, но инструмент проверки отмечает указанную выше проблему.
Код: Выделить всё
private ContentSigner createContentSigner() {
return new ContentSigner() {
// This stream will be filled by the saveIncrementalForExternalSigning method. It holds the bytes of the PDF file.
private final ByteArrayOutputStream stream = new ByteArrayOutputStream();
@Override
public byte[] getSignature() {
try {
MessageDigest digest = MessageDigest.getInstance("SHA-256");
// Hash the bytes of the PDF file.
byte[] hashBytes = digest.digest(stream.toByteArray());
// The hash is encoded in Base64 as this is the format expected by the server.
String hash = Base64.getEncoder().encodeToString(hashBytes);
// Send the hash to the server and retrieve the signed hash.
// The response is Base64 encoded, so it needs to be decoded for the CMS signature.
return java.util.Base64.getDecoder().decode(webAPIService.getSignedHash(hash));
} catch (Exception e) {
throw new RuntimeException("Exception while signing", e);
}
}
@Override
public OutputStream getOutputStream() {
return stream;
}
@Override
public AlgorithmIdentifier getAlgorithmIdentifier() {
// The algorithm identifier for SHA-256.
return new AlgorithmIdentifier(new ASN1ObjectIdentifier("1.2.840.113549.1.1.11"));
}
};
}
Подробнее здесь: https://stackoverflow.com/questions/792 ... e-creation
Мобильная версия