-
Notifications
You must be signed in to change notification settings - Fork 3
/
iscapi.xml
392 lines (356 loc) · 9.75 KB
/
iscapi.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
<?xml version="1.0" encoding="UTF-8"?>
<Export generator="Cache" version="25" zv="Cache for Windows (x86-64) 2013.1 (Build 443U)" ts="2013-10-01 18:22:19">
<Class name="iscapi.Signer">
<Description>
Функции для работы с крипто-провайдерами через MS CAPI</Description>
<Super>%RegisteredObject</Super>
<TimeChanged>63095,54910.929709</TimeChanged>
<TimeCreated>62647,62739.879273</TimeCreated>
<Method name="LoadDLL">
<Description>
Загрузка DLL
dllPath - полный путь к библиотеке</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>dllPath:%String</FormalSpec>
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
s result = $$$OK
if (dllPath = "") {
w "Please set dllPath equal to path to the ISCAPI.dll"
q $$$ERROR($$$GeneralError, "No path to iscapi.dll is provided")
}
try {
d $zf(-3, dllPath)
}
catch (ex) {
s result = ex.AsStatus()
}
if (result=1)
{w "DLL from "_dllPath_" was loaded"}
else
{w "Cannot load DLL from "_dllPath}
q result
]]></Implementation>
</Method>
<Method name="UnloadDLL">
<Description>
Выгрузка DLL</Description>
<ClassMethod>1</ClassMethod>
<Implementation><![CDATA[ d $zf(-3, "")
]]></Implementation>
</Method>
<Method name="Init">
<Description>
Инициализация крипто-провайдера.
provType - тип провайдера (VipNet=2, CryptoPro=75)
algId - используемый алгоритм (32798)
containerName - полное имя контейнера с ключами
pin - пароль к контейнеру (если не указан, CSP будет запршивать его в интерактивном режиме, что не всегда возможно)
providerName - имя крипто-провайдера</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>provType=75,algId=32798,containerName:%String,pin:%String="111111",providerName:%String=""</FormalSpec>
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
s result = $$$OK
try {
d $zf(-3, "", "Init", provType, algId, containerName, pin, providerName)
}
catch (ex) {
s result = ex.AsStatus()
}
if (result=1)
{w "CSP was successfully initialized"}
else
{w "Error during CSP initialization"}
q result
]]></Implementation>
</Method>
<Method name="InitLogger">
<Description>
Инициализация протоколирования.
logFileName - имя файла протокола. Должно быть право на запись.
logLevel - уровень протоколирования
0 - ничего
1 - только ошибки
2 - все сообщения
logTargets - устройства, в которые нужно писать протокол
0 - не писать никуда
1 - писать в файл
2 - выводить на консоль
3 - файл и консоль</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>logFileName:%String="c:\iscapi.log",logLevel:%Integer=2,logTargets:%Integer=3</FormalSpec>
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
s result = $$$OK
try {
d $zf(-3, "", "InitLogger", logFileName, logLevel, logTargets)
}
catch ex {
s result = ex.AsStatus()
}
if (result=1)
{w "Logger was successfully initialized"}
else
{w "Error during Logger initialization"}
q result
]]></Implementation>
</Method>
<Method name="HashData">
<Description>
Хеширование порции данных.
Можно вызывать в цикле для хеширования потока по чанкам, каждая порция данных будет прибавляться к хешу.</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>dataPortion:%String</FormalSpec>
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
s result = $$$OK
try {
d $zf(-3, "", "HashData", dataPortion)
}
catch ex {
s result = ex.AsStatus()
}
q result
]]></Implementation>
</Method>
<Method name="HashFile">
<Description>
Хеширование файла.</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>fileName:%String</FormalSpec>
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
s result = $$$OK
try {
d $zf(-3, "", "HashFile", fileName)
}
catch ex {
s result = ex.AsStatus()
}
q result
]]></Implementation>
</Method>
<Method name="GetHashValue">
<Description>
Возвращает значение хеша.
После вызова хеш сохраняется</Description>
<ClassMethod>1</ClassMethod>
<ReturnType>%String</ReturnType>
<Implementation><![CDATA[
s result = ""
//s temp = ""
try {
s result = $zf(-3, "", "GetHashValue", "")
}
catch ex {
w "GHV exception", !
zw ex
s result = ""
}
w "GHV result is:", result, !
q result
]]></Implementation>
</Method>
<Method name="ExportUserKey">
<ClassMethod>1</ClassMethod>
<ReturnType>%String</ReturnType>
<Implementation><![CDATA[
s result = ""
try {
s result = $zf(-3, "", "ExportUserKey", "")
}
catch ex {
s result = ""
}
q result
]]></Implementation>
</Method>
<Method name="SignNewHash">
<Description>
Экспорт открытого ключа.
Подпись хеша.</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>dataPortion:%String</FormalSpec>
<ReturnType>%String</ReturnType>
<Implementation><![CDATA[
s result = ""
try {
s result = $zf(-3, "", "SignNewHash", dataPortion, "")
}
catch ex {
s result = ""
}
q result
]]></Implementation>
</Method>
<Method name="SignCurrentHash">
<Description>
Подпись текущего объекта хеша.</Description>
<ClassMethod>1</ClassMethod>
<ReturnType>%String</ReturnType>
<Implementation><![CDATA[
s result = ""
try {
s result = $zf(-3, "", "SignCurrentHash", "")
}
catch ex {
s result = ""
}
w "Signature recieved: ",result,!
q result
]]></Implementation>
</Method>
<Method name="VerifyHash">
<Description>
Проверка подписи хэша.</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>hash:%String,sign:%String</FormalSpec>
<ReturnType>%Boolean</ReturnType>
<Implementation><![CDATA[
s result = 0
try {
s result = $zf(-3, "", "VerifyHash", hash, sign, 0)
}
catch ex {
s result = 0
}
q result
]]></Implementation>
</Method>
<Method name="VerifyHashByKey">
<ClassMethod>1</ClassMethod>
<FormalSpec>hash:%String,sign:%String,pubKey:%String</FormalSpec>
<ReturnType>%Boolean</ReturnType>
<Implementation><![CDATA[
s result = 0
try {
s result = $zf(-3, "", "VerifyHashByKey", hash, sign, pubKey, 0)
}
catch ex {
s result = 0
}
q result
]]></Implementation>
</Method>
<Method name="VerifySignature">
<Description>
Проверка подписи хэша по открытому ключу.
Проверка подписи данных</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>dataPortion:%String,sign:%String</FormalSpec>
<ReturnType>%Boolean</ReturnType>
<Implementation><![CDATA[
s result = 0
try {
s result = $zf(-3, "", "VerifySignature", dataPortion, sign, 0)
}
catch ex {
s result = 0
}
q result
]]></Implementation>
</Method>
<Method name="ReleaseAll">
<Description>
Освобождение ресурсов и выгрузка DLL</Description>
<ClassMethod>1</ClassMethod>
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
s result = $$$OK
try {
d $zf(-3, "", "ReleaseAll")
d ..UnloadDLL()
}
catch ex {
s result = ex.AsStatus()
}
q result
]]></Implementation>
</Method>
<Method name="ByteToHex">
<Description>
Преобразование бинарной строки в HEX
TODO: rewrite</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>bString:%String</FormalSpec>
<ReturnType>%String</ReturnType>
<Implementation><![CDATA[
s str = ""
for i=1:1:$l(bString) {
s hex = $zhex($ascii($e(bString, i)))
if ($l(hex) = 1) s hex = "0" _ hex
s str = str _ hex
}
q str
]]></Implementation>
</Method>
<Method name="HexToString">
<ClassMethod>1</ClassMethod>
<FormalSpec>value:%String</FormalSpec>
<ReturnType>%String</ReturnType>
<Implementation><![CDATA[
s str = ""
for i=1:2:$l(value) {
s hex = $e(value, i, i + 1)
s str = str _ $c($zhex(hex))
}
q str
]]></Implementation>
</Method>
<Method name="PrintProviders">
<Description>
Выгрузка DLL</Description>
<ClassMethod>1</ClassMethod>
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
s result = $$$OK
try {
d $zf(-3, "", "PrintProviders")
//d ..UnloadDLL()
}
catch ex {
s result = ex.AsStatus()
}
q result
]]></Implementation>
</Method>
<Method name="Test">
<Description>
Тестовый прогон КриптоПро</Description>
<ClassMethod>1</ClassMethod>
<Implementation><![CDATA[
s data = "123!"
d ..LoadDLL("C:\ARTEM\ISCAPI.dll")
w "DLL loaded", !
d ..InitLogger("c:\ARTEM\iscapiL.txt", 2, 1)
w "Logger initialized", !
d ..PrintProviders()
d ..Init(75, 32798, "CacheCrypt", "", "Crypto-Pro GOST R 34.10-2001 Cryptographic Service Provider")
w "CSP initialized", !
d ..HashData(data)
w "Hash created on: ", data, !
s hash = ..GetHashValue()
w "Hash received, hash length=", $l(hash), !
w "Hash to base64:", !, $system.Encryption.Base64Encode(hash), !
w "Hash to HEX:", !, ..ByteToHex(hash), !
w "Hash value:", hash, !
s sign = ..SignCurrentHash()
w "Hash signed, sign length=", $l(sign), !
w "Sign to base64:", !, $system.Encryption.Base64Encode(sign), !
w "Sign to HEX:", !, ..ByteToHex(sign), !
s vfy = ..VerifyHash(hash, sign)
w "Verifying Hash signature result = ", vfy, !
s vfy = ..VerifySignature(data, sign)
w "Verifying Signature by input text result = ", vfy, !
w "Exporting User Key...",!
s userKey = ..ExportUserKey()
w "Size: ", $l(userKey), !
w "UserKeyBytes: ", ..ByteToHex(userKey), !
s vfy = ..VerifyHashByKey(hash, sign, userKey)
w "Verifying Hash signature ByKey result = ", vfy, !
d ..ReleaseAll()
]]></Implementation>
</Method>
</Class>
</Export>