HTML
<script language="javascript" src="cadesplugin_api.js"></script>
Приведенный пример использует синхронную версию плагина. Также см. пример работы с асинхронными обьектами.
JavaScript
function SignCreate(certSubjectName, dataToSign) { var oStore = cadesplugin.CreateObject("CAdESCOM.Store"); oStore.Open(cadesplugin.CAPICOM_CURRENT_USER_STORE, cadesplugin.CAPICOM_MY_STORE, cadesplugin.CAPICOM_STORE_OPEN_MAXIMUM_ALLOWED); var oCertificates = oStore.Certificates.Find( cadesplugin.CAPICOM_CERTIFICATE_FIND_SUBJECT_NAME, certSubjectName); if (oCertificates.Count == 0) { alert("Certificate not found: " + certSubjectName); return; } var oCertificate = oCertificates.Item(1); var oSigner = cadesplugin.CreateObject("CAdESCOM.CPSigner"); oSigner.Certificate = oCertificate; oSigner.CheckCertificate = true; oSigner.TSAAddress = "http://cryptopro.ru/tsp/"; var oSignedData = cadesplugin.CreateObject("CAdESCOM.CadesSignedData"); oSignedData.Content = dataToSign; try { var sSignedMessage = oSignedData.SignCades(oSigner, cadesplugin.CADESCOM_CADES_X_LONG_TYPE_1); } catch (err) { alert("Failed to create signature. Error: " + cadesplugin.getLastError(err)); return; } oStore.Close(); return sSignedMessage; } function Verify(sSignedMessage) { var oSignedData = cadesplugin.CreateObject("CAdESCOM.CadesSignedData"); try { oSignedData.VerifyCades(sSignedMessage, cadesplugin.CADESCOM_CADES_X_LONG_TYPE_1); } catch (err) { alert("Failed to verify signature. Error: " + cadesplugin.getLastError(err)); return false; } return true; } function run() { var oCertName = document.getElementById("CertName"); var sCertName = oCertName.value; // Здесь следует заполнить SubjectName сертификата if ("" == sCertName) { alert("Введите имя сертификата (CN)."); return; } var signedMessage = SignCreate(sCertName, "Message"); document.getElementById("signature").innerHTML = signedMessage; var verifyResult = Verify(signedMessage); if (verifyResult) { alert("Signature verified"); } }