Статус: Новичок
Группы: Участники
Зарегистрирован: 23.11.2023(UTC) Сообщений: 2 Сказал(а) «Спасибо»: 1 раз
|
На основе примеров и ответов на форуме получился такой код на Котлин для создания подписи: Код:val keyStore = KeyStore.getInstance(JCSP.HD_STORE_NAME, JCSP.PROVIDER_NAME)
keyStore.load(null, null)
val certificate = keyStore.getCertificate(alias) as X509Certificate
val privateKey = keyStore.getKey(alias, password.toCharArray()) as PrivateKey
// Формируем цепочку для подписи
val chain: MutableList<X509Certificate> = mutableListOf()
for (certificate in keyStore.getCertificateChain(alias)) {
chain.add(certificate as X509Certificate)
}
val cAdESSignature = CAdESSignature(detached, signHash)
if (disableOnlineValidation) {
cAdESSignature.setOptions((Options()).disableCertificateValidation());
}
var exception: Exception? = null;
val gfgThread = Thread {
try {
cAdESSignature.addSigner(
JCSP.PROVIDER_NAME, null, null, privateKey, chain,
CAdESType.CAdES_BES, null, false, null, null, null,
true
)
} catch (e: Exception) {
exception = e
}
}
gfgThread.start()
gfgThread.join();
if (exception != null) {
return getErrorResponse(exception.toString(), exception!!)
}
val signatureStream = ByteArrayOutputStream()
cAdESSignature.open(signatureStream)
cAdESSignature.update(contentToSign)
cAdESSignature.close()
signatureStream.close()
val enc = Encoder()
val base64 = enc.encode(signatureStream.toByteArray())
val response = JSONObject()
response.put("success", true)
response.put("signBase64", base64)
return response
Каждый раз получаю следующую ошибку: Root certificate: serial 37418882f539a5924ad44e3de002ea3c, subject CN=CRYPTO-PRO Test Center 2, O=CRYPTO-PRO LLC, L=Moscow, C=RU, EMAILADDRESS=support@cryptopro.ru, issuer CN=CRYPTO-PRO Test Center 2, O=CRYPTO-PRO LLC, L=Moscow, C=RU, EMAILADDRESS=support@cryptopro.ru, not before Mon May 27 10:24:26 GMT+03:00 2019, not after Sun May 26 10:34:05 GMT+03:00 2024 is untrusted; error codes: [32] 'Root certificate is in the certificate chain but not in cacerts', Не могу понять что я делаю не так
|