Автор: Андрей * Здравствуйте.
Без примера -не понятно.
В любом случае, есть
демо-страница, проверяли?
Snimok ehkrana ot 2023-01-17 17-26-15.png
(13kb) загружен 4 раз(а). Код:var CAPICOM_CURRENT_USER_STORE = 2;
var CAPICOM_MY_STORE = "My";
var CAPICOM_STORE_OPEN_MAXIMUM_ALLOWED = 2;
var CAPICOM_CERTIFICATE_FIND_SUBJECT_NAME = 1;
var CADESCOM_XML_SIGNATURE_TYPE_ENVELOPED = 0;
var CADESCOM_XML_SIGNATURE_TYPE_ENVELOPING = 1;
var CADESCOM_BASE64_TO_BINARY = 1;
var XmlDsigGost3411Url2012256 = "urn:ietf:params:xml:ns:cpxmlsec:algorithms:gostr34112012-256";
var XmlDsigGost3410Url2012256 = "urn:ietf:params:xml:ns:cpxmlsec:algorithms:gostr34102012-gostr34112012-256";
function CP_SignCreate(CertName) {
cadesplugin.async_spawn(function* (args) {
var oCertName = document.getElementById(CertName);
var sCertName = oCertName.value; // Здесь следует заполнить SubjectName сертификата
if ("" === sCertName) {
alert("Введите имя сертификата (CN).");
return;
}
// Ищем сертификат для подписи
var oStore = yield cadesplugin.CreateObjectAsync("CAdESCOM.Store");
yield oStore.Open(CAPICOM_CURRENT_USER_STORE, CAPICOM_MY_STORE,
CAPICOM_STORE_OPEN_MAXIMUM_ALLOWED);
var oStoreCerts = yield oStore.Certificates;
var oCertificates = yield oStoreCerts.Find(
CAPICOM_CERTIFICATE_FIND_SUBJECT_NAME, sCertName);
var certsCount = yield oCertificates.Count;
if (certsCount === 0) {
alert("Certificate not found: " + sCertName);
return;
}
var oCertificate = yield oCertificates.Item(1);
yield oStore.Close();
var dataToSign = document.getElementById(CP_counter_name("DataToSignTxtBox")).value;
// Создаем объект CAdESCOM.CPSigner
var oSigner = yield cadesplugin.CreateObjectAsync("CAdESCOM.CPSigner");
yield oSigner.propset_Certificate(oCertificate);
yield oSigner.propset_CheckCertificate(true);
// Создаем объект CAdESCOM.SignedXML
var oSignedXML = yield cadesplugin.CreateObjectAsync("CAdESCOM.SignedXML");
yield oSignedXML.propset_Content(dataToSign);
// Указываем тип подписи - в данном случае вложенная
yield oSignedXML.propset_SignatureType(CADESCOM_XML_SIGNATURE_TYPE_ENVELOPED);
// Указываем алгоритм подписи
yield oSignedXML.propset_SignatureMethod(XmlDsigGost3410Url2012256);
// Указываем алгоритм хэширования
yield oSignedXML.propset_DigestMethod(XmlDsigGost3411Url2012256);
var sSignedMessage = "";
try {
sSignedMessage = yield oSignedXML.Sign(oSigner);
} catch (err) {
alert("Failed to create signature. Error: " + cadesplugin.getLastError(err));
return;
}
//alert(sSignedMessage);
document.getElementById(CP_counter_name("SignatureTxtBox")).innerHTML = sSignedMessage;
// Создаем объект CAdESCOM.SignedXML
var oSignedXML2 = yield cadesplugin.CreateObjectAsync("CAdESCOM.SignedXML");
try {
yield oSignedXML2.Verify(sSignedMessage);
CP_end_sign(); alert("Signature verified");
} catch (err) {
alert("Failed to verify signature. Error: " + cadesplugin.getLastError(err));
return;
}
});
}
Код почти без изменений из примера.
Вот результат подписи
var dataToSign =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<!-- \n" +
" Original XML doc file for sign example. \n" +
"-->\n" +
"<Envelope xmlns=\"urn:envelope\">\n" +
" <Data>\n" +
" Hello, World!\n" +
" </Data>\n" +
" <Node xml:id=\"nodeID\">\n" +
" Hello, Node!\n" +
" </Node>\n" +
" \n" +
"</Envelope>";
PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPCEtLSAKIE9y
aWdpbmFsIFhNTCBkb2MgZmlsZSBmb3Igc2lnbiBleGFtcGxlLiAKLS0+CjxFbnZl
bG9wZSB4bWxucz0idXJuOmVudmVsb3BlIj4KICA8RGF0YT4KICAgSGVsbG8sIFdv
cmxkIQogIDwvRGF0YT4KICA8Tm9kZSB4bWw6aWQ9Im5vZGVJRCI+CiAgIEhlbGxv
LCBOb2RlIQogIDwvTm9kZT4KIAo8U2lnbmF0dXJ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