Обновил примеры

This commit is contained in:
Vitalii Goma 2017-01-17 15:25:57 +03:00
parent d2f48758ef
commit da95f14c1a
3 changed files with 52 additions and 11 deletions

21
example/cert-list.js Normal file
View File

@ -0,0 +1,21 @@
;(function () {
'use strict';
var $certs = document.querySelector('#certList');
/**
* Пример получения списка сертификатов
* */
window.CryptoPro.call('getCertsList').then(function (list) {
list.forEach(function (cert) {
var $certOption = document.createElement('option');
$certOption.innerText = cert.label;
$certOption.value = cert.thumbprint;
$certs.appendChild($certOption);
});
}, function (error) {
console.error(error);
});
}());

24
example/create-sign.js Normal file
View File

@ -0,0 +1,24 @@
;(function () {
'use strict';
/**
* Пример создания подписи данных, сгенерированных по ГОСТ Р 34.11-94
* https://ru.wikipedia.org/wiki/%D0%93%D0%9E%D0%A1%D0%A2_%D0%A0_34.11-94
* */
var $certs = document.querySelector('#certList'),
$createSignBtn = document.querySelector('#createSign'),
$signatureCnt = document.querySelector('#createdSign'),
// Вычислинный hash по ГОСТ Р 34.11-94 для строки: "abc"
hash = 'b285056dbf18d7392d7677369524dd14747459ed8143997e163b2986f92fd42c',
hashBase64 = window.btoa(hash);
$createSignBtn.addEventListener('click', function () {
var thumbprint = $certs.value;
window.CryptoPro.call('signData', thumbprint, hashBase64).then(function (signature) {
$signatureCnt.value = signature;
});
});
}());

View File

@ -6,22 +6,18 @@
<script src="https://cdn.polyfill.io/v2/polyfill.js"></script>
</head>
<body>
<select id="certList"></select>
<button id="createSign" type="button">Создать подпись</button>
<br>
<textarea id="createdSign" cols="90" rows="30"></textarea>
<script>
window.CryptoProConfig = {
publicPath: '../dist/'
};
</script>
<pre id="certList"></pre>
<script src="../dist/crypto-pro.js"></script>
<script>
CryptoPro.call('getCertsList').then(function (list) {
document.querySelector('#certList').innerHTML = JSON.stringify(list, null, ' ');
}, function (error) {
console.error(error);
});
</script>
<script src="cert-list.js"></script>
<script src="create-sign.js"></script>
</body>
</html>