yc-ui2 0.2.2-beta2 → 0.2.2-beta4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. package/package.json +1 -1
  2. package/.env +0 -7
  3. package/babel.config.js +0 -5
  4. package/jsconfig.json +0 -19
  5. package/public/favicon.ico +0 -0
  6. package/public/index.html +0 -20
  7. package/src/App.vue +0 -70
  8. package/src/api/customerService.js +0 -56
  9. package/src/assets/ca/ca-bg.png +0 -0
  10. package/src/assets/ca/caBg.png +0 -0
  11. package/src/assets/customerService/admin.jpg +0 -0
  12. package/src/assets/customerService/chatTop.png +0 -0
  13. package/src/assets/customerService/ellipticalWenh.png +0 -0
  14. package/src/assets/customerService/enlarge.png +0 -0
  15. package/src/assets/customerService/personal.jpg +0 -0
  16. package/src/assets/customerService/personal1.jpg +0 -0
  17. package/src/assets/customerService/personal2.jpg +0 -0
  18. package/src/assets/slideVerify/1.jpg +0 -0
  19. package/src/assets/slideVerify/2.jpg +0 -0
  20. package/src/assets/slideVerify/3.jpg +0 -0
  21. package/src/assets/slideVerify/4.jpg +0 -0
  22. package/src/assets/slideVerify/5.jpg +0 -0
  23. package/src/assets/slideVerify/6.jpg +0 -0
  24. package/src/assets/slideVerify/7.jpg +0 -0
  25. package/src/assets/slideVerify/8.jpg +0 -0
  26. package/src/components/YcCA/index.vue +0 -536
  27. package/src/components/YcCustomerService/chat.vue +0 -337
  28. package/src/components/YcCustomerService/chatMixin.js +0 -128
  29. package/src/components/YcCustomerService/index.vue +0 -272
  30. package/src/components/YcQuestion/index.vue +0 -535
  31. package/src/components/YcSlideVerify/index.vue +0 -104
  32. package/src/main.js +0 -19
  33. package/src/packages/index.js +0 -29
  34. package/src/router/index.js +0 -20
  35. package/src/utils/auth.js +0 -6
  36. package/src/utils/mTokenPlugin/base64.js +0 -148
  37. package/src/utils/mTokenPlugin/base64_backups.js +0 -146
  38. package/src/utils/mTokenPlugin/hunca_mToken_core.js +0 -1447
  39. package/src/utils/mTokenPlugin/hunca_mToken_core2.js +0 -1455
  40. package/src/utils/mTokenPlugin/hunca_mToken_core_backups.js +0 -1425
  41. package/src/utils/mTokenPlugin/mToken.js +0 -3211
  42. package/src/utils/mTokenPlugin/mToken_backups.js +0 -3202
  43. package/src/utils/mTokenPluginBeijin/formateTime.js +0 -10
  44. package/src/utils/mTokenPluginBeijin/xtxasyn.js +0 -1156
  45. package/src/utils/request.js +0 -50
  46. package/src/views/question.vue +0 -32
  47. package/vue.config.js +0 -41
@@ -1,1455 +0,0 @@
1
- /**
2
- * @name mTokenPlugin集成代码
3
- * @author Akay
4
- * @version 0.7.12
5
- * @date 2020.07.21
6
- *
7
- * @description
8
- *ver 0.7.12 2020.12.21
9
- * 1. 新增操作系统判断,根据不同的系统加载不同的配置
10
- *
11
- *ver 0.7.11 2020.07.21
12
- * 1. 解决Https的问题
13
- *
14
- * ver 0.7.10 2020.04.04
15
- * 1. 新增获取设备序号
16
- * 2. 支持多Key
17
- *
18
- * ver 0.7.9 2020.01.08
19
- * 1. 支持SJK1137型号
20
- *
21
- * ver 0.7.8 2019.10.23
22
- * 1. 新增UKey适配
23
- *
24
- * ver 0.7.4 2019.09.18
25
- * 1. 新增证书生效,失效时间
26
- *
27
- * ver 0.7.3 2019.08.19
28
- * 1. 获取证书使用者信息
29
- *
30
- * ver 0.7.2 2019.08.08
31
- * 1. 新增远程解锁接口
32
- *
33
- * ver 0.7.1 2019.07.17
34
- * TODO: 未安装组件时,判断组件是否安装(暂定,未解决)
35
- *
36
- * ver 0.7.0 2019.07.04
37
- * 1. 更新核心文件,解决多Key插入问题
38
- * 2. Ukey目前仅支持国密证书
39
- *
40
- * ver 0.6.3 2019.06.24
41
- * 1. 修复部分Bug
42
- *
43
- * ver 0.6.1 2019.06.24
44
- * 1. 支持数字信封数据解密接口
45
- * 2. 修复加密接口错误部分。
46
- *
47
- * ver 0.6.0 2019.06.20
48
- * 1. 支持数字信封数据加密接口
49
- * 2. 暂不支持多Ukey
50
- *
51
- * ver 0.5.1 2019.06.19
52
- * 1. 修正新Ukey引入导致的Bug
53
- *
54
- * ver 0.5 2019.06.18
55
- * 1. 适配SJK1137型号Ukey
56
- *
57
- * ver 0.4 2019.03.16
58
- * 1. 新增方法 枚举Ukey获取证书“G项信息”列表
59
- * 2. 新增方法 将“证书G项信息”转化为“证书名称”方法
60
- *
61
- * ver 0.3 2018.12.10
62
- * 1. 新增修改Ukey密码的方法
63
- *
64
- * ver 0.2 2018.09.26
65
- * 1. 新增获取签名证书SN号的方法
66
- * 2. 修正部分Bug
67
- *
68
- * ver 0.1 2018.09.21
69
- * 1. 搭建初步框架
70
- * 2. 完成签名功能
71
- *
72
- */
73
- import { mToken } from "utils/mTokenPlugin/mToken";
74
- import { _Base64encode } from "utils/mTokenPlugin/base64";
75
- export function hunca_mToken_core () {
76
-
77
- var token = new mToken("mTokenPlugin");
78
- // eslint-disable-next-line no-unused-vars
79
- var certInfoList = null;
80
- // eslint-disable-next-line no-unused-vars
81
- var singleKey = 0;
82
- var libraryNameList = null;
83
-
84
- if ((navigator.platform == "Win32") || (navigator.platform == "Windows")) {
85
- libraryNameList = Array("GM3000", "HT", "SJK1137");
86
- } else {
87
- //libraryNameList = Array("GM3000"); //国产操作系统支持GM3000型号
88
- libraryNameList = Array("HT"); //国产操作系统支持海泰型号
89
- }
90
- /**
91
- * 错误信息
92
- */
93
- var LAST_ERRORSTRING = "";
94
-
95
- /**
96
- * 证书用途
97
- */
98
- var KEY_SPEC_TYPE_ENCRYPT = 0;
99
- var KEY_SPEC_TYPE_SIGN = 1;
100
-
101
- /**
102
- * 摘要算法
103
- */
104
- var SGD_SM3 = 1;
105
- // eslint-disable-next-line no-unused-vars
106
- var SGD_SHA1 = 2;
107
-
108
- /**
109
- * 加密算法
110
- */
111
- //分组加密算法标识
112
- // eslint-disable-next-line no-unused-vars
113
- let SGD_SM1_ECB = 0x00000101;
114
- // eslint-disable-next-line no-unused-vars
115
- let SGD_SM1_CBC = 0x00000102;
116
- // eslint-disable-next-line no-unused-vars
117
- let SGD_SM1_CFB = 0x00000104;
118
- // eslint-disable-next-line no-unused-vars
119
- let SGD_SM1_OFB = 0x00000108;
120
- // eslint-disable-next-line no-unused-vars
121
- let SGD_SM1_MAC = 0x00000110;
122
- let SGD_SM4_ECB = 0x00000401;
123
- // eslint-disable-next-line no-unused-vars
124
- let SGD_SM4_CBC = 0x00000402;
125
- // eslint-disable-next-line no-unused-vars
126
- let SGD_SM4_CFB = 0x00000404;
127
- // eslint-disable-next-line no-unused-vars
128
- let SGD_SM4_OFB = 0x00000408;
129
- // eslint-disable-next-line no-unused-vars
130
- let SGD_SM4_MAC = 0x00000410;
131
-
132
-
133
- /**
134
- * 用户ID(固定)
135
- */
136
- var USER_ID = "1234567812345678";
137
-
138
-
139
- /**
140
- * 错误信息提示列表
141
- */
142
- var ERROR_MESSAGE_NOT_LOADLIBRARY = "控件加载失败,错误码:";
143
- var ERROR_MESSAGE_NOT_FIND_UKEY = "未找到UKey!\n1.请确认是否安装最新驱动!\n2.计算机是否插入湖南CA UKey!";
144
- // eslint-disable-next-line no-unused-vars
145
- var ERROR_MSSSAGE_FIND_MORE_UKEY = "计算机插入多个UKey,请拔除多余“湖南CA UKey”!";
146
- var ERROR_MESSAGE_NOT_INSTANCE_DEVICE = "USBKey实例化失败,请确认此UKey是否插入计算机!\n点击‘刷新’按钮,更新设备列表。\n错误码:";
147
- var ERROR_MESSAGE_USERPIN_LENGTH = "Ukey密码必须为4~16位!";
148
- var ERROR_MESSAGE_USERPIN_IS_ERROR = "UKey密码错误";
149
- var ERROR_MESSAGE_USERPIN_CHANGE_ERROR = "UKey密码修改失败";
150
- var ERROR_MESSAGE_KEY_NOT_EXIT = "UKey不存在,请确认此UKey是否插入计算机,并点击'刷新'按钮,更新设备列表!";
151
- var ERROR_MESSAGE_USERNAME_IS_NULL = "请点击‘刷新’按钮,更新设备列表并选择相应设备!";
152
- var ERROR_MESSAGE_KEY_EXPORT_CERT = "证书获取失败,请加检测Key中是否存在证书!";
153
- var ERROR_MESSAGE_SET_DIGEST_METHOD_ERROR = "设置摘要算法失败,请重新刷新浏览器!";
154
- var ERROR_MESSAGE_SET_USERID_ERROR = "设置用户ID失败,请重新刷新浏览器";
155
- var ERROR_MESSAGE_SIGN_ORIGINALDATA_IS_NULL = "签名失败,待签名原文不能为空";
156
- var ERROR_MESSAGE_SIGN_ERROR = "签名失败,返回错误码:";
157
- var ERROR_MESSAGE_USERNAMEGN_IS_NULL = "请点击‘刷新’按钮,更新设备列表并选择相应设备!";
158
- var ERROR_MESSAGE_USERNAMEGN_TO_USERNAME_ERROR = "证书G项信息转化证书名称失败,请点击“刷新”按钮!";
159
- var ERROR_MESSAGE_KEY_LIBRAY = "加载国密库失败!";
160
- var ERROR_MESSAGE_ENCRYPT_DATA_IS_NULL = "加密失败:待加密原文不能为空!";
161
- var ERROR_MESSAGE_DECRYPT_DATA_IS_NULL = "解密失败:待解密密文不能为空!";
162
- var ERROR_MESSAGE_DECRYPT_DATA_IS_ERROR = "解密失败:请确认密文是否完整!\n解密所采用的Ukey是否为加密时的Ukey!";
163
- var ERROR_MESSAGE_GET_REMOTEUNLOCKREQUEST_FAIL = "申请解锁请求失败!";
164
- var ERROR_MESSAGE_GET_REMOTEUNLOCKREQUEST_NOT_SUPPORT = "此型号Ukey不支持解锁!";
165
- var ERROR_MESSAGE_REMOTE_UNLOCK_FAIL = "Ukey解锁失败!";
166
-
167
- /**
168
- * 私有变量
169
- */
170
- var tokenInfoList = null;
171
-
172
- /**
173
- * 私有变量
174
- */
175
- var signResultSignData = null;
176
- var signResultCert = null;
177
-
178
- /**
179
- * 证书信息
180
- */
181
- var certSn = null; //证书Sn
182
- var cert_subject_GN = null; //证书Gn
183
- var cert_subject = null; //证书使用者
184
- var cert_validTime = null; //证书失效时间
185
- var cert_notbeforetime = null; //证书生效时间
186
-
187
- /**
188
- * 返回错误信息
189
- */
190
- this.Hunca_GetLastError = function () {
191
- return LAST_ERRORSTRING;
192
- }
193
-
194
- /**
195
- * 获取证书列表
196
- */
197
- this.Hunca_GetUserList = function () {
198
- var deviceArray = null;
199
- var containerName = null;
200
- var userName = null;
201
- var tmpInfo = null;
202
-
203
- signResultCert = null;
204
- signResultSignData = null;
205
- tokenInfoList = new Array(); //清空信息
206
-
207
- for (var index = 0; index < libraryNameList.length; index++) {
208
- var libraryName = libraryNameList[index];
209
- if (!SOF_LoadLibrary(libraryName)) {
210
- continue;
211
- }
212
-
213
- deviceArray = SOF_EnumDevice();
214
- if (null == deviceArray) {
215
- continue;
216
- }
217
-
218
- for (var i = 0; i < deviceArray.length; i++) {
219
- var tokenInfo = new Object();
220
- //实例化设备失败
221
- if (!SOF_GetDeviceInstance(deviceArray[i])) {
222
- break;
223
- }
224
-
225
- //获取设备信息
226
- tmpInfo = SOF_GetUserList();
227
- if (null != tmpInfo || tmpInfo.length != 0) {
228
- containerName = tmpInfo[0][1];
229
- userName = tmpInfo[0][0];
230
-
231
- tokenInfo.libraryName = libraryName; //Ukey型号
232
- tokenInfo.serial = deviceArray[i]; //设备序列号
233
- tokenInfo.userName = userName; //证书名称
234
- tokenInfo.containerName = containerName; //应用名称
235
-
236
- tokenInfoList.push(tokenInfo);
237
- } else {
238
- continue;
239
- }
240
- SOF_LogOut();
241
- }
242
- }
243
-
244
- //返回证书信息
245
- var userNameList = new Array();
246
- for (let i = 0; i < tokenInfoList.length; i++) {
247
- userNameList[i] = tokenInfoList[i].userName;
248
- }
249
-
250
- if (userNameList.length == 0) {
251
- LAST_ERRORSTRING = ERROR_MESSAGE_NOT_FIND_UKEY;
252
- return "";
253
- }
254
-
255
- return userNameList;
256
- }
257
-
258
- /**
259
- * 获取证书G项信息列表
260
- */
261
- this.Hunca_GetUserListGN = function Hunca_GetUserListGN () {
262
- var deviceArray = null;
263
- var containerName = null;
264
- var userName = null;
265
- var tmpInfo = null;
266
- var certB64 = null;
267
- var deviceSerial = "";
268
-
269
- // eslint-disable-next-line no-unused-vars
270
- var signResultCert = null;
271
- // eslint-disable-next-line no-unused-vars
272
- var signResultSignData = null;
273
- tokenInfoList = new Array(); //清空信息
274
- var LAST_ERRORSTRING = "";
275
-
276
- for (var index = 0; index < libraryNameList.length; index++) {
277
- var libraryName = libraryNameList[index];
278
- //加载控件
279
- if (!SOF_LoadLibrary(libraryName)) {
280
- continue;
281
- }
282
-
283
- deviceArray = SOF_EnumDevice();
284
- if (null == deviceArray) {
285
- continue;
286
- }
287
-
288
- for (var i = 0; i < deviceArray.length; i++) {
289
- cert_subject_GN = null;
290
- certSn = null;
291
- deviceSerial = deviceArray[i];
292
-
293
- var tokenInfo = new Object();
294
-
295
- //实例化设备失败
296
- if (!SOF_GetDeviceInstance(deviceSerial)) {
297
- break;
298
- }
299
-
300
- //获取设备信息
301
- tmpInfo = SOF_GetUserList();
302
- if (null != tmpInfo || tmpInfo.length != 0) {
303
- containerName = tmpInfo[0][1];
304
- userName = tmpInfo[0][0];
305
-
306
- tokenInfo.libraryName = libraryName;
307
- tokenInfo.serial = deviceArray[i]; //设备序列号
308
- tokenInfo.userName = userName; //证书名称
309
- tokenInfo.containerName = containerName;
310
- } else {
311
- continue;
312
- }
313
-
314
- //获取证书G项信息
315
- certB64 = SOF_ExportUserCert(tokenInfo.containerName, KEY_SPEC_TYPE_SIGN);
316
- if (SOF_GetCertInfo(certB64)) {
317
- tokenInfo.subjectGN = cert_subject_GN; //设备证书G项目;
318
- } else {
319
- continue;
320
- }
321
-
322
- tokenInfoList.push(tokenInfo);
323
- SOF_LogOut();
324
- }
325
- }
326
-
327
- //返回证书G项信息
328
- var userNameGNList = new Array();
329
- for (let i = 0; i < tokenInfoList.length; i++) {
330
- userNameGNList[i] = tokenInfoList[i].subjectGN;
331
- }
332
-
333
- if (userNameGNList.length == 0) {
334
- // eslint-disable-next-line no-unused-vars
335
- LAST_ERRORSTRING = ERROR_MESSAGE_NOT_FIND_UKEY;
336
- return "";
337
- }
338
-
339
- /*****
340
- if (userNameGNList.length > 1){
341
- LAST_ERRORSTRING = ERROR_MSSSAGE_FIND_MORE_UKEY;
342
- return "";
343
- }
344
- ****/
345
- return userNameGNList;
346
- }
347
-
348
- /**
349
- * 将证书G项信息转化为证书名称
350
- */
351
- this.Hunca_userNameGNToUserName = function (userNameGN) {
352
- var userName = null;
353
- LAST_ERRORSTRING = "";
354
- if (null == userNameGN || userNameGN.length == 0) {
355
- LAST_ERRORSTRING = ERROR_MESSAGE_USERNAMEGN_IS_NULL;
356
- }
357
-
358
- for (var i = 0; i < tokenInfoList.length; i++) {
359
- if (userNameGN == tokenInfoList[i].subjectGN) {
360
- userName = tokenInfoList[i].userName;
361
- break;
362
- }
363
- }
364
-
365
- if (null == userName || userName.length == 0) {
366
- LAST_ERRORSTRING = ERROR_MESSAGE_USERNAMEGN_TO_USERNAME_ERROR;
367
- return null;
368
- }
369
- return userName;
370
- }
371
-
372
- this.Hunca_GenRemoteUnblockRequest = function (userName) {
373
- var tokenInfo = null; //Ukey设备信息
374
- var tempTokenInfo = null; //临时设备信息,循环遍历用
375
- var request = "";
376
-
377
- LAST_ERRORSTRING = "";
378
-
379
- //设备名称为空
380
- if (null == userName || userName.length == null) {
381
- LAST_ERRORSTRING = ERROR_MESSAGE_USERNAME_IS_NULL;
382
- return false;
383
- }
384
-
385
- //查找匹配的设备序列号
386
- if (null == tokenInfoList || tokenInfoList.length == 0) {
387
- LAST_ERRORSTRING = ERROR_MESSAGE_NOT_FIND_UKEY;
388
- return false;
389
- }
390
-
391
- //索引设备编号
392
- for (var i = 0; i < tokenInfoList.length; i++) {
393
- tempTokenInfo = tokenInfoList[i];
394
- if (tempTokenInfo.userName == userName) {
395
- tokenInfo = tempTokenInfo;
396
- break;
397
- }
398
- }
399
-
400
- //如果所选择的设备不存在
401
- if (null == tokenInfo) {
402
- LAST_ERRORSTRING = ERROR_MESSAGE_KEY_NOT_EXIT;
403
- return false;
404
- }
405
-
406
- //判断设备是否支持远程解锁
407
- if (tokenInfo.libraryName != "GM3000") {
408
- LAST_ERRORSTRING = ERROR_MESSAGE_GET_REMOTEUNLOCKREQUEST_NOT_SUPPORT;
409
- return false;
410
- }
411
-
412
- //加载库文件
413
- if (!SOF_LoadLibrary(tokenInfo.libraryName)) {
414
- LAST_ERRORSTRING = ERROR_MESSAGE_KEY_LIBRAY;
415
- return false;
416
- }
417
-
418
- //实例化设备
419
- if (!SOF_GetDeviceInstance(tokenInfo.serial)) {
420
- return false;
421
- }
422
-
423
- //枚举容器,并选择第一个容器
424
- if (SOF_GetUserList() == null) {
425
- return false;
426
- }
427
-
428
- //远程解锁
429
- request = SOF_GenRemoteUnblockRequest()
430
-
431
- return request;
432
- }
433
-
434
- this.HUnca_GetDeviceNumber = function (userName) {
435
- var m_devNumber = null;
436
-
437
- //设备名称为空
438
- if (null == userName || userName.length == null) {
439
- LAST_ERRORSTRING = ERROR_MESSAGE_USERNAME_IS_NULL;
440
- return false;
441
- }
442
-
443
- //查找匹配的设备序列号
444
- if (null == tokenInfoList || tokenInfoList.length == 0) {
445
- LAST_ERRORSTRING = ERROR_MESSAGE_NOT_FIND_UKEY;
446
- return false;
447
- }
448
-
449
- //索引设备编号
450
- for (var i = 0; i < tokenInfoList.length; i++) {
451
- let tempTokenInfo = tokenInfoList[i];
452
- if (tempTokenInfo.userName == userName) {
453
- // eslint-disable-next-line no-undef
454
- tokenInfo = tempTokenInfo;
455
- break;
456
- }
457
- }
458
-
459
- //如果所选择的设备不存在
460
- // eslint-disable-next-line no-undef
461
- if (null == tokenInfo) {
462
- LAST_ERRORSTRING = ERROR_MESSAGE_KEY_NOT_EXIT;
463
- return false;
464
- }
465
-
466
- //加载库文件
467
- // eslint-disable-next-line no-undef
468
- if (!SOF_LoadLibrary(tokenInfo.libraryName)) {
469
- LAST_ERRORSTRING = ERROR_MESSAGE_KEY_LIBRAY;
470
- return false;
471
- }
472
-
473
- //实例化设备
474
- // eslint-disable-next-line no-undef
475
- if (!SOF_GetDeviceInstance(tokenInfo.serial)) {
476
- return false;
477
- }
478
- m_devNumber = SOF_GetDeviceNumber();
479
-
480
- return m_devNumber + "";
481
- }
482
-
483
- this.Hunca_RemoteUnlockPIN = function (userName, response) {
484
- var tokenInfo = null; //Ukey设备信息
485
- var tempTokenInfo = null; //临时设备信息,循环遍历用
486
- var result = false;
487
-
488
- LAST_ERRORSTRING = "";
489
-
490
- //设备名称为空
491
- if (null == userName || userName.length == null) {
492
- LAST_ERRORSTRING = ERROR_MESSAGE_USERNAME_IS_NULL;
493
- return false;
494
- }
495
-
496
- //查找匹配的设备序列号
497
- if (null == tokenInfoList || tokenInfoList.length == 0) {
498
- LAST_ERRORSTRING = ERROR_MESSAGE_NOT_FIND_UKEY;
499
- return false;
500
- }
501
-
502
- //索引设备编号
503
- for (var i = 0; i < tokenInfoList.length; i++) {
504
- tempTokenInfo = tokenInfoList[i];
505
- if (tempTokenInfo.userName == userName) {
506
- tokenInfo = tempTokenInfo;
507
- break;
508
- }
509
- }
510
-
511
- //如果所选择的设备不存在
512
- if (null == tokenInfo) {
513
- LAST_ERRORSTRING = ERROR_MESSAGE_KEY_NOT_EXIT;
514
- return false;
515
- }
516
-
517
- //判断设备是否支持远程解锁
518
- if (tokenInfo.libraryName != "GM3000") {
519
- LAST_ERRORSTRING = ERROR_MESSAGE_GET_REMOTEUNLOCKREQUEST_NOT_SUPPORT;
520
- return false;
521
- }
522
-
523
- //加载库文件
524
- if (!SOF_LoadLibrary(tokenInfo.libraryName)) {
525
- LAST_ERRORSTRING = ERROR_MESSAGE_KEY_LIBRAY;
526
- return false;
527
- }
528
-
529
- //实例化设备
530
- if (!SOF_GetDeviceInstance(tokenInfo.serial)) {
531
- return false;
532
- }
533
-
534
- //枚举容器,并选择第一个容器
535
- if (SOF_GetUserList() == null) {
536
- return false;
537
- }
538
-
539
- //远程解锁
540
- result = SOF_RemoteUnlockPIN(response)
541
- return result;
542
- }
543
-
544
- /**
545
- * 修改Ukey密码
546
- */
547
- this.Hunca_ChangeUserPin = function (userName, oldUserPin, newUserPin) {
548
- var tokenInfo = null; //Ukey设备信息
549
- var tempTokenInfo = null; //临时设备信息,循环遍历用
550
- LAST_ERRORSTRING = "";
551
-
552
- //设备名称为空
553
- if (null == userName || userName.length == null) {
554
- LAST_ERRORSTRING = ERROR_MESSAGE_USERNAME_IS_NULL;
555
- return false;
556
- }
557
-
558
- //查找匹配的设备序列号
559
- if (null == tokenInfoList || tokenInfoList.length == 0) {
560
- LAST_ERRORSTRING = ERROR_MESSAGE_NOT_FIND_UKEY;
561
- return false;
562
- }
563
-
564
- //索引设备编号
565
- for (var i = 0; i < tokenInfoList.length; i++) {
566
- tempTokenInfo = tokenInfoList[i];
567
- if (tempTokenInfo.userName == userName) {
568
- tokenInfo = tempTokenInfo;
569
- break;
570
- }
571
- }
572
-
573
- //如果所选择的设备不存在
574
- if (null == tokenInfo) {
575
- LAST_ERRORSTRING = ERROR_MESSAGE_KEY_NOT_EXIT;
576
- return false;
577
- }
578
-
579
- //加载库文件
580
- if (!SOF_LoadLibrary(tokenInfo.libraryName)) {
581
- LAST_ERRORSTRING = ERROR_MESSAGE_KEY_LIBRAY;
582
- }
583
-
584
- //实例化设备
585
- if (!SOF_GetDeviceInstance(tokenInfo.serial)) {
586
- return false;
587
- }
588
-
589
- //修改密码
590
- if (!SOF_ChangeUserPin(oldUserPin, newUserPin)) {
591
- return false;
592
- }
593
-
594
- SOF_LogOut();
595
- return true;
596
- }
597
-
598
- /**
599
- * 对数据进行签名,并返回签名是否成功
600
- * @param {string} originalData 待签名原文
601
- * @param {string} userName Ukey用户名称
602
- * @param {string} userPin Ukey密码
603
- */
604
- this.Hunca_PKCS1 = function (originalData, userName, userPin) {
605
- // eslint-disable-next-line no-unused-vars
606
- var libraryName = null;
607
- var tokenInfo = null; //Ukey设备信息
608
- var tempTokenInfo = null; //临时设备信息,循环遍历用
609
- var certBase64 = null; //签名证书值
610
-
611
- var LAST_ERRORSTRING = "";
612
- // eslint-disable-next-line no-unused-vars
613
- var signResultInfo = null;
614
- // eslint-disable-next-line no-unused-vars
615
- var certInfo = new Object();
616
- //设备名称为空
617
- if (null == userName || userName.length == null) {
618
- LAST_ERRORSTRING = ERROR_MESSAGE_USERNAME_IS_NULL;
619
- return false;
620
- }
621
-
622
- //查找匹配的设备序列号
623
- if (null == tokenInfoList || tokenInfoList.length == 0) {
624
- LAST_ERRORSTRING = ERROR_MESSAGE_NOT_FIND_UKEY;
625
- return false;
626
- }
627
-
628
- //索引设备编号
629
- for (var i = 0; i < tokenInfoList.length; i++) {
630
- tempTokenInfo = tokenInfoList[i];
631
- if (tempTokenInfo.userName == userName) {
632
- tokenInfo = tempTokenInfo;
633
- break;
634
- }
635
- }
636
-
637
- //如果所选择的设备不存在
638
- if (null == tokenInfo) {
639
- LAST_ERRORSTRING = ERROR_MESSAGE_KEY_NOT_EXIT;
640
- return false;
641
- }
642
-
643
- //加载库文件
644
- if (!SOF_LoadLibrary(tokenInfo.libraryName)) {
645
- // eslint-disable-next-line no-unused-vars
646
- LAST_ERRORSTRING = ERROR_MESSAGE_KEY_LIBRAY;
647
- }
648
-
649
- //实例化设备
650
- if (!SOF_GetDeviceInstance(tokenInfo.serial)) {
651
- return false;
652
- }
653
-
654
- //登陆应用
655
- if (!SOF_Login(userPin)) {
656
- return false;
657
- }
658
-
659
- //获取签名证书Base64
660
- certBase64 = SOF_ExportUserCert(tokenInfo.containerName, KEY_SPEC_TYPE_SIGN);
661
- if (null == certBase64) {
662
- return false;
663
- }
664
-
665
- //设置摘要算法
666
- if (!SOF_SetDigestMethod(SGD_SM3)) {
667
- return false;
668
- }
669
-
670
- if (!SOF_SetUserID()) {
671
- return false;
672
- }
673
-
674
- //进行签名
675
- if (!SOF_SignData(tokenInfo.containerName, SGD_SM3, originalData, certBase64)) {
676
- return false;
677
- }
678
-
679
- //获取证书信息
680
- if (!SOF_GetCertInfo(certBase64)) {
681
- return false;
682
- }
683
-
684
- SOF_LogOut();
685
- return true;
686
- }
687
-
688
- /**
689
- * 获取签名结果
690
- */
691
- this.Hunca_GetSignData = function () {
692
- return signResultSignData;
693
- }
694
-
695
- /**
696
- * 获取签名证书
697
- */
698
- this.Hunca_GetSignCert = function () {
699
- return signResultCert;
700
- }
701
-
702
- this.Hunca_GetSignCertSn = function () {
703
- return certSn
704
- }
705
-
706
- this.Hunca_GetSignCertSubject = function () {
707
- return cert_subject;
708
- }
709
-
710
- this.Hunca_GetValidTime = function () {
711
- return cert_validTime;
712
- }
713
-
714
- this.HUnca_GetNotBeforeTime = function () {
715
- return cert_notbeforetime;
716
- }
717
- /**
718
- * 处理设备中签名证书信息
719
- * @param {*} userName
720
- */
721
- this.Hunca_DealCertInfo = function (userName) {
722
- var tokenInfo = null; //Ukey设备信息
723
- var tempTokenInfo = null; //临时设备信息,循环遍历用
724
- var certBase64 = null; //签名证书值
725
-
726
- LAST_ERRORSTRING = "";
727
- // eslint-disable-next-line no-undef
728
- signResultInfo = null;
729
- // eslint-disable-next-line no-undef
730
- certInfo = new Object();
731
- //设备名称为空
732
- if (null == userName || userName.length == null) {
733
- LAST_ERRORSTRING = ERROR_MESSAGE_USERNAME_IS_NULL;
734
- return false;
735
- }
736
-
737
- //查找匹配的设备序列号
738
- if (null == tokenInfoList || tokenInfoList.length == 0) {
739
- LAST_ERRORSTRING = ERROR_MESSAGE_NOT_FIND_UKEY;
740
- return false;
741
- }
742
-
743
- //索引设备编号
744
- for (var i = 0; i < tokenInfoList.length; i++) {
745
- tempTokenInfo = tokenInfoList[i];
746
- if (tempTokenInfo.userName == userName) {
747
- tokenInfo = tempTokenInfo;
748
- break;
749
- }
750
- }
751
-
752
- //如果所选择的设备不存在
753
- if (null == tokenInfo) {
754
- LAST_ERRORSTRING = ERROR_MESSAGE_KEY_NOT_EXIT;
755
- return false;
756
- }
757
-
758
- if (!SOF_LoadLibrary(tokenInfo.libraryName)) {
759
- LAST_ERRORSTRING = ERROR_MESSAGE_KEY_LIBRAY;
760
- return false;
761
- }
762
-
763
- //实例化设备
764
- if (!SOF_GetDeviceInstance(tokenInfo.serial)) {
765
- return false;
766
- }
767
-
768
- //导出证书
769
- certBase64 = SOF_ExportUserCert(tokenInfo.containerName, KEY_SPEC_TYPE_SIGN);
770
- if (null == certBase64 || certBase64.length == 0) {
771
- return false;
772
- }
773
-
774
- SOF_GetCertInfo(certBase64);
775
- SOF_LogOut();
776
- return true;
777
- }
778
-
779
- /**
780
- * 对数据进行数字信封加密
781
- * @param {string} inData 待加密原文
782
- * @param {string} userName Ukey用户名称
783
- * @param {string} EncryptMethod 对称加密方式
784
- * @param {string} EncryptIV 加密IV值
785
- * @returns {string} "",加密失败;非空,加密成功
786
- */
787
- this.Hunca_EncryptDataPKCS7 = function (inData, userName, EncryptMethod, EncryptIV) {
788
- var tokenInfo = null; //Ukey设备信息
789
- var tempTokenInfo = null; //临时设备信息,循环遍历用
790
- var certBase64 = null; //签名证书值
791
- var m_EncryptMethod = "",
792
- m_EncryptIV = "";
793
-
794
- var LAST_ERRORSTRING = "";
795
- // eslint-disable-next-line no-unused-vars
796
- var signResultInfo = null;
797
- // eslint-disable-next-line no-unused-vars
798
- var certInfo = new Object();
799
-
800
-
801
- //设备名称为空
802
- if (null == userName || userName.length == null) {
803
- LAST_ERRORSTRING = ERROR_MESSAGE_USERNAME_IS_NULL;
804
- return "";
805
- }
806
-
807
- //查找匹配的设备序列号
808
- if (null == tokenInfoList || tokenInfoList.length == 0) {
809
- LAST_ERRORSTRING = ERROR_MESSAGE_NOT_FIND_UKEY;
810
- return "";
811
- }
812
-
813
- //索引设备编号
814
- for (var i = 0; i < tokenInfoList.length; i++) {
815
- tempTokenInfo = tokenInfoList[i];
816
- if (tempTokenInfo.userName == userName) {
817
- tokenInfo = tempTokenInfo;
818
- break;
819
- }
820
- }
821
-
822
- //如果所选择的设备不存在
823
- if (null == tokenInfo) {
824
- LAST_ERRORSTRING = ERROR_MESSAGE_KEY_NOT_EXIT;
825
- return "";
826
- }
827
-
828
- //加载链接库
829
- if (!SOF_LoadLibrary(tokenInfo.libraryName)) {
830
- // eslint-disable-next-line no-unused-vars
831
- LAST_ERRORSTRING = ERROR_MESSAGE_KEY_LIBRAY;
832
- return "";
833
- }
834
-
835
- //实例化设备
836
- if (!SOF_GetDeviceInstance(tokenInfo.serial)) {
837
- return "";
838
- }
839
-
840
- //导出加密证书
841
- certBase64 = SOF_ExportUserCert(tokenInfo.containerName, KEY_SPEC_TYPE_ENCRYPT);
842
- if (null == certBase64 || certBase64.length == 0) {
843
- return "";
844
- }
845
-
846
- //设置加密方式
847
-
848
- m_EncryptMethod = EncryptMethod + "";
849
- m_EncryptIV = EncryptIV + "";
850
-
851
- if (m_EncryptMethod == null || m_EncryptMethod.length == 0) {
852
- m_EncryptMethod = SGD_SM4_ECB;
853
- m_EncryptIV = "";
854
- }
855
-
856
- if (!SOF_SetEncryptMethodAndIV(m_EncryptMethod, m_EncryptIV)) {
857
- return "";
858
- }
859
-
860
- //对数据进行加密
861
- // eslint-disable-next-line no-undef
862
- encryptData = SOF_EncryptDataPKCS7(certBase64, inData);
863
-
864
- SOF_LogOut();
865
-
866
- // eslint-disable-next-line no-undef
867
- return encryptData;
868
- }
869
-
870
- /**
871
- * 对密文进行数字信封解密操作
872
- * @param {string} encryptData 待解密密文
873
- * @param {string} userName Ukey用户名称
874
- * @param {string} userPin Ukey用户PIN码
875
- * @param {string} EncryptMethod 对称加密方式
876
- * @param {string} EncryptIV 加密IV值
877
- * @returns {string} "",加密失败;非空,加密成功
878
- */
879
- this.Hunca_DecryptDataPKCS7 = function (encryptData, userName, userPin, EncryptMethod, EncryptIV) {
880
- var tokenInfo = null; //Ukey设备信息
881
- var tempTokenInfo = null; //临时设备信息,循环遍历用
882
- var m_EncryptMethod = "",
883
- m_EncryptIV = "";
884
- var m_EncryptData = "";
885
- var m_DecryptData = "";
886
- var resData = "";
887
-
888
- var LAST_ERRORSTRING = "";
889
- // eslint-disable-next-line no-unused-vars
890
- var signResultInfo = null;
891
- // eslint-disable-next-line no-unused-vars
892
- var certInfo = new Object();
893
-
894
-
895
- m_EncryptData = "" + encryptData;
896
- //设备名称为空
897
- if (null == userName || userName.length == null) {
898
- LAST_ERRORSTRING = ERROR_MESSAGE_USERNAME_IS_NULL;
899
- return "";
900
- }
901
-
902
- //查找匹配的设备序列号
903
- if (null == tokenInfoList || tokenInfoList.length == 0) {
904
- LAST_ERRORSTRING = ERROR_MESSAGE_NOT_FIND_UKEY;
905
- return "";
906
- }
907
-
908
- //索引设备编号
909
- for (var i = 0; i < tokenInfoList.length; i++) {
910
- tempTokenInfo = tokenInfoList[i];
911
- if (tempTokenInfo.userName == userName) {
912
- tokenInfo = tempTokenInfo;
913
- break;
914
- }
915
- }
916
-
917
- //如果所选择的设备不存在
918
- if (null == tokenInfo) {
919
- LAST_ERRORSTRING = ERROR_MESSAGE_KEY_NOT_EXIT;
920
- return "";
921
- }
922
-
923
- //加载链接库
924
- if (!SOF_LoadLibrary(tokenInfo.libraryName)) {
925
- LAST_ERRORSTRING = ERROR_MESSAGE_KEY_LIBRAY;
926
- return "";
927
- }
928
-
929
- //实例化设备
930
- if (!SOF_GetDeviceInstance(tokenInfo.serial)) {
931
- return "";
932
- }
933
-
934
- //登陆应用
935
- if (!SOF_Login(userPin)) {
936
- return "";
937
- }
938
-
939
- //设置加密方式
940
- m_EncryptMethod = EncryptMethod + "";
941
- m_EncryptIV = EncryptIV + "";
942
- if (m_EncryptMethod == null || m_EncryptMethod.length == 0) {
943
- m_EncryptMethod = SGD_SM4_ECB;
944
- m_EncryptIV = "";
945
- }
946
-
947
- if (!SOF_SetEncryptMethodAndIV(m_EncryptMethod, m_EncryptIV)) {
948
- return "";
949
- }
950
-
951
- m_DecryptData = SOF_DecryptDataPKCS7(tokenInfo.containerName, KEY_SPEC_TYPE_ENCRYPT, m_EncryptData);
952
- if (m_DecryptData.length == 0) {
953
- return "";
954
- }
955
-
956
- try {
957
- // eslint-disable-next-line no-undef
958
- resData = _Base64decode(m_DecryptData);
959
- } catch (e) {
960
- resData = m_DecryptData;
961
- // eslint-disable-next-line no-unused-vars
962
- LAST_ERRORSTRING = "解密失败:Base64解码失败";
963
- }
964
-
965
- return resData;
966
- }
967
-
968
- /**
969
- * 加载底层文件
970
- * @returns {boolean} true,加载成功;false加载失败;
971
- */
972
- function SOF_LoadLibrary (libraryName) {
973
- var resultCode = 0;
974
- if (libraryName == "GM3000") {
975
- resultCode = token.SOF_LoadLibrary(token.GM3000);
976
- }
977
- else if (libraryName == "HT") {
978
- resultCode = token.SOF_LoadLibrary(token.HT);
979
- }
980
- else if (libraryName == "SJK1137") {
981
- resultCode = token.SOF_LoadLibrary(token.SJK1137);
982
- }
983
-
984
- if (resultCode != 0) {
985
- LAST_ERRORSTRING = ERROR_MESSAGE_NOT_LOADLIBRARY + token.SOF_GetLastError();
986
- return false;
987
- }
988
- return true;
989
- }
990
-
991
- /**
992
- * 枚举设备
993
- */
994
- function SOF_EnumDevice () {
995
- var deviceNameList = "";
996
-
997
- deviceNameList = token.SOF_EnumDevice();
998
-
999
- //检测是否插入USBKey
1000
- if (null == deviceNameList || deviceNameList.length == 0) {
1001
- LAST_ERRORSTRING = ERROR_MESSAGE_NOT_FIND_UKEY;
1002
- return null;
1003
- }
1004
-
1005
- return deviceNameList;
1006
- }
1007
-
1008
- /**
1009
- * 实例化设备,为后续一系列操作准备
1010
- * @param {string} deviceName 设备名称
1011
- */
1012
- function SOF_GetDeviceInstance (deviceName) {
1013
- var resultCode = 0;
1014
-
1015
- resultCode = token.SOF_GetDeviceInstance(deviceName, "");
1016
- //设备未正常实例化
1017
- if (resultCode != 0) {
1018
- LAST_ERRORSTRING = ERROR_MESSAGE_NOT_INSTANCE_DEVICE + token.SOF_GetLastError();
1019
- return false;
1020
- }
1021
- return true;
1022
- }
1023
-
1024
- /**
1025
- * 枚举应用中的容器
1026
- */
1027
- function SOF_GetUserList () {
1028
- var userList = "";
1029
-
1030
- userList = token.SOF_GetUserList();
1031
- if (null == userList || userList.length == 0) {
1032
- LAST_ERRORSTRING = "USBkey中未找到证书!";
1033
- return null;
1034
- }
1035
-
1036
- return userList;
1037
- }
1038
-
1039
- /**
1040
- * 登陆应用,验证密码是否正确
1041
- * @param {string} userPin
1042
- */
1043
- function SOF_Login (userPin) {
1044
- var resultCode = 0;
1045
- var m_userPin = "" + userPin;
1046
- var RetryCount = 0;
1047
-
1048
- if (null == m_userPin || m_userPin.length == 0) {
1049
- LAST_ERRORSTRING = ERROR_MESSAGE_USERPIN_LENGTH;
1050
- return false;
1051
- }
1052
-
1053
- if (m_userPin.length < 4 || m_userPin.length > 16) {
1054
- LAST_ERRORSTRING = ERROR_MESSAGE_USERPIN_LENGTH;
1055
- return false;
1056
- }
1057
-
1058
- resultCode = token.SOF_Login(m_userPin);
1059
- if (resultCode != 0) {
1060
- RetryCount = SOF_GetPinRetryCount();
1061
- if (RetryCount > 0) {
1062
- LAST_ERRORSTRING = ERROR_MESSAGE_USERPIN_IS_ERROR + ",还剩 " + RetryCount + " 次重试机会!";
1063
- } else {
1064
- LAST_ERRORSTRING = "UKey已经锁死,请联系管理员进行解锁!"
1065
- }
1066
- return false;
1067
- }
1068
- return true
1069
- }
1070
-
1071
- /**
1072
- * 修改UKey密码
1073
- * @param {*} oldUserPin
1074
- * @param {*} newUserPin
1075
- */
1076
- function SOF_ChangeUserPin (oldUserPin, newUserPin) {
1077
- var resultCode = 0;
1078
- var m_oldUserPin = "" + oldUserPin;
1079
- var m_newUserPin = "" + newUserPin;
1080
- var RetryCount = 0;
1081
-
1082
- if (null == m_oldUserPin || m_oldUserPin.length == 0) {
1083
- LAST_ERRORSTRING = ERROR_MESSAGE_USERPIN_LENGTH;
1084
- return false;
1085
- }
1086
-
1087
- if (null == m_newUserPin || m_newUserPin.length == 0) {
1088
- LAST_ERRORSTRING = ERROR_MESSAGE_USERPIN_LENGTH;
1089
- return false;
1090
- }
1091
-
1092
- if (m_oldUserPin.length < 4 || m_oldUserPin.length > 16) {
1093
- LAST_ERRORSTRING = ERROR_MESSAGE_USERPIN_LENGTH;
1094
- return false;
1095
- }
1096
-
1097
- if (m_newUserPin.length < 4 || m_newUserPin.length > 16) {
1098
- LAST_ERRORSTRING = ERROR_MESSAGE_USERPIN_LENGTH;
1099
- return false;
1100
- }
1101
-
1102
- resultCode = token.SOF_ChangePassWd(m_oldUserPin, m_newUserPin);
1103
- if (resultCode != 0) {
1104
- RetryCount = SOF_GetPinRetryCount();
1105
- if (RetryCount > 0) {
1106
- LAST_ERRORSTRING = ERROR_MESSAGE_USERPIN_CHANGE_ERROR + ",还剩 " + RetryCount + " 次重试机会!";
1107
- } else {
1108
- LAST_ERRORSTRING = "UKey已经锁死,请联系管理员进行解锁!"
1109
- }
1110
- return false;
1111
- }
1112
- return true;
1113
- }
1114
-
1115
- /**
1116
- * 返回重试次数
1117
- */
1118
- function SOF_GetPinRetryCount () {
1119
- var retryCount = 0;
1120
- retryCount = token.SOF_GetPinRetryCount();
1121
- return retryCount;
1122
- }
1123
-
1124
- function SOF_GetDeviceNumber () {
1125
- var deviceNumber = null;
1126
- deviceNumber = token.SOF_GetDeviceInfo(token.SGD_DEVICE_SERIAL_NUMBER);
1127
- return deviceNumber;
1128
- }
1129
-
1130
- /**
1131
- * 导出证书值
1132
- * @param {string} containerName 容器名称
1133
- * @param {int} keySec 证书用途
1134
- */
1135
- function SOF_ExportUserCert (containerName, keySec) {
1136
- var certBase64;
1137
- certBase64 = token.SOF_ExportUserCert(containerName, keySec);
1138
- if (null == certBase64 || certBase64.length == 0) {
1139
- LAST_ERRORSTRING = ERROR_MESSAGE_KEY_EXPORT_CERT;
1140
- return null;
1141
- }
1142
- return certBase64;
1143
- }
1144
-
1145
- /**
1146
- * 设置加密算法
1147
- * @param {*} EncryptMethod 设置加密算法
1148
- * @param {*} EncryptIV 设置IV值
1149
- */
1150
- function SOF_SetEncryptMethodAndIV (EncryptMethod, EncryptIV) {
1151
- var resCode = 1;
1152
-
1153
- if (EncryptMethod == undefined || EncryptMethod == null) {
1154
- LAST_ERRORSTRING = "请设置加密方式!";
1155
- return false;
1156
- }
1157
-
1158
- resCode = token.SOF_SetEncryptMethodAndIV(EncryptMethod, _Base64encode(EncryptIV));
1159
- if (resCode != 0) {
1160
- LAST_ERRORSTRING = token.SOF_GetLastError();
1161
- return false;
1162
- }
1163
- return true;
1164
- }
1165
-
1166
- /**
1167
- * 设置签名算法
1168
- * @param {}} digestMethod
1169
- */
1170
- function SOF_SetDigestMethod (digestMethod) {
1171
- var resultCode = 0;
1172
- resultCode = token.SOF_SetDigestMethod(digestMethod);
1173
- if (resultCode != 0) {
1174
- LAST_ERRORSTRING = ERROR_MESSAGE_SET_DIGEST_METHOD_ERROR;
1175
- return false;
1176
- }
1177
-
1178
- return true;
1179
- }
1180
-
1181
- /**
1182
- * 设置默认USERID
1183
- */
1184
- function SOF_SetUserID () {
1185
- var resultCode = 0;
1186
- resultCode = token.SOF_SetUserID(USER_ID);
1187
- if (resultCode != 0) {
1188
- LAST_ERRORSTRING = ERROR_MESSAGE_SET_USERID_ERROR;
1189
- return false;
1190
- }
1191
- return true;
1192
- }
1193
-
1194
- /**
1195
- * 数字信封加密
1196
- * @param {String} Base64EncodeCert 加密证书值
1197
- * @param {String} inData 待加密原文
1198
- * @returns {*} "",表示加密失败;非空,加密成功
1199
- */
1200
- function SOF_EncryptDataPKCS7 (Base64EncodeCert, inData) {
1201
- var encryptData = "";
1202
- var inDataBase64 = "";
1203
- var m_inData = "";
1204
-
1205
- m_inData = "" + inData;
1206
- if (m_inData.length == 0) {
1207
- LAST_ERRORSTRING = ERROR_MESSAGE_ENCRYPT_DATA_IS_NULL;
1208
- return "";
1209
- }
1210
-
1211
- inDataBase64 = _Base64encode(m_inData)
1212
- encryptData = token.SOF_EncryptDataPKCS7(Base64EncodeCert, inDataBase64, inData.length);
1213
-
1214
- if (encryptData == null || encryptData.length == 0) {
1215
- LAST_ERRORSTRING = "加密失败," + token.SOF_GetLastError();
1216
- return "";
1217
- }
1218
- return encryptData;
1219
- }
1220
-
1221
- /**
1222
- * 数字信封解密
1223
- * @param {*} containerName 应用名称
1224
- * @param {int} cerType
1225
- * @param {*} encrypedData
1226
- */
1227
- function SOF_DecryptDataPKCS7 (containerName, cerType, encrypedData) {
1228
- var m_EncrypedData = "",
1229
- m_DecryptData = "";
1230
-
1231
- m_EncrypedData = "" + encrypedData;
1232
- if (containerName == null || containerName.length == 0) {
1233
- LAST_ERRORSTRING = "应用名称不能为空!";
1234
- return "";
1235
- }
1236
-
1237
- if (m_EncrypedData.length == 0) {
1238
- LAST_ERRORSTRING = ERROR_MESSAGE_DECRYPT_DATA_IS_NULL;
1239
- return "";
1240
- }
1241
-
1242
- try {
1243
- m_DecryptData = token.SOF_DecryptDataPKCS7(containerName, cerType, m_EncrypedData);
1244
- } catch (e) {
1245
- m_DecryptData = "";
1246
- }
1247
- if (undefined == m_DecryptData || m_DecryptData == null || m_DecryptData == "") {
1248
- LAST_ERRORSTRING = ERROR_MESSAGE_DECRYPT_DATA_IS_ERROR;
1249
- return "";
1250
- }
1251
-
1252
- return m_DecryptData;
1253
- }
1254
-
1255
- /**
1256
- * 数据签名
1257
- * @param {*} containerName
1258
- * @param {*} ulKeySpec
1259
- * @param {*} data
1260
- * @param {*} certBase64
1261
- */
1262
- function SOF_SignData (containerName, ulKeySpec, data, certBase64) {
1263
- var signData = null;
1264
- var b64Data = null;
1265
- var m_data = "" + data;
1266
-
1267
-
1268
- if (null == m_data || m_data.length == 0) {
1269
- LAST_ERRORSTRING = ERROR_MESSAGE_SIGN_ORIGINALDATA_IS_NULL;
1270
- return false;
1271
- }
1272
-
1273
- b64Data = _Base64encode(m_data);
1274
- signData = token.SOF_SignData(containerName, ulKeySpec, _Base64encode(b64Data), b64Data.length)
1275
- if (null == signData || signData.length == 0) {
1276
- // eslint-disable-next-line no-undef
1277
- LAST_ERRORSTRING = ERROR_MESSAGE_SIGN_ERROR + SOF_GetLastError();
1278
- return false;
1279
- }
1280
-
1281
- signResultCert = certBase64;
1282
- signResultSignData = signData;
1283
-
1284
- return true;
1285
- }
1286
-
1287
- /**
1288
- * 导出证书
1289
- * @param {*} certBase64
1290
- */
1291
- function SOF_GetCertInfo (certBase64) {
1292
- var str = null;
1293
- var subject = null;
1294
- var tmpList = null;
1295
- var validTime = null;
1296
- var notBeforetime = null;
1297
- var key, value;
1298
-
1299
- if (null == certBase64 || certBase64.length == 0) {
1300
- return false;
1301
- }
1302
-
1303
- cert_subject_GN = "";
1304
- certSn = "";
1305
- cert_subject = "";
1306
-
1307
- str = token.SOF_GetCertInfo(certBase64, token.SGD_CERT_SERIAL);
1308
- certSn = hexToDec(str);
1309
-
1310
- subject = token.SOF_GetCertInfo(certBase64, token.SGD_CERT_SUBJECT);
1311
- cert_subject = subject;
1312
-
1313
- validTime = token.SOF_GetCertInfo(certBase64, token.SGD_CERT_VALID_TIME);
1314
- cert_validTime = validTime;
1315
-
1316
- notBeforetime = token.SOF_GetCertInfo(certBase64, token.SGD_CERT_NOT_BEFORE);
1317
- cert_notbeforetime = notBeforetime;
1318
-
1319
- tmpList = subject.split(',');
1320
- for (var i = 0; i < tmpList.length; i++) {
1321
- if (tmpList[i].indexOf("=") == -1) {
1322
- continue;
1323
- }
1324
-
1325
- key = tmpList[i].split('=')[0];
1326
- value = tmpList[i].split('=')[1];
1327
-
1328
- if (key == 'GN') {
1329
- cert_subject_GN = value;
1330
- break;
1331
- }
1332
- }
1333
- return true;
1334
- }
1335
-
1336
-
1337
-
1338
- /**
1339
- * 登出UKey
1340
- */
1341
- function SOF_LogOut () {
1342
- token.SOF_LogOut();
1343
- }
1344
-
1345
- /**
1346
- * 生成解锁请求
1347
- */
1348
- function SOF_GenRemoteUnblockRequest () {
1349
- var request = token.SOF_GenRemoteUnblockRequest();
1350
- if (request == null || request == "") {
1351
- LAST_ERRORSTRING = ERROR_MESSAGE_GET_REMOTEUNLOCKREQUEST_FAIL;
1352
- return "";
1353
- }
1354
-
1355
- return request;
1356
- }
1357
-
1358
- function SOF_RemoteUnlockPIN (response) {
1359
- var result = false;
1360
-
1361
- if (null == response || response.length == 0) {
1362
- LAST_ERRORSTRING = "解锁失败解:响应不能为空!";
1363
- return false;
1364
- }
1365
-
1366
- result = token.SOF_RemoteUnblockPIN(response);
1367
- if (result != 0) {
1368
- LAST_ERRORSTRING = ERROR_MESSAGE_REMOTE_UNLOCK_FAIL;
1369
- return false;
1370
- } else {
1371
- return true;
1372
- }
1373
- }
1374
-
1375
- function add (x, y, base) {
1376
- var z = [];
1377
- var n = Math.max(x.length, y.length);
1378
- var carry = 0;
1379
- var i = 0;
1380
- while (i < n || carry) {
1381
- var xi = i < x.length ? x[i] : 0;
1382
- var yi = i < y.length ? y[i] : 0;
1383
- var zi = carry + xi + yi;
1384
- z.push(zi % base);
1385
- carry = Math.floor(zi / base);
1386
- i++;
1387
- }
1388
- return z;
1389
- }
1390
-
1391
- function multiplyByNumber (num, x, base) {
1392
- if (num < 0) return null;
1393
- if (num == 0) return [];
1394
-
1395
- var result = [];
1396
- var power = x;
1397
- // eslint-disable-next-line no-constant-condition
1398
- while (true) {
1399
- if (num & 1) {
1400
- result = add(result, power, base);
1401
- }
1402
- num = num >> 1;
1403
- if (num === 0) break;
1404
- power = add(power, power, base);
1405
- }
1406
-
1407
- return result;
1408
- }
1409
-
1410
- function parseToDigitsArray (str, base) {
1411
- var digits = str.split('');
1412
- var ary = [];
1413
- for (var i = digits.length - 1; i >= 0; i--) {
1414
- var n = parseInt(digits[i], base);
1415
- if (isNaN(n)) return null;
1416
- ary.push(n);
1417
- }
1418
- return ary;
1419
- }
1420
-
1421
-
1422
- function convertBase (str, fromBase, toBase) {
1423
- var digits = parseToDigitsArray(str, fromBase);
1424
- if (digits === null) return null;
1425
-
1426
- var outArray = [];
1427
- var power = [1];
1428
- for (var i = 0; i < digits.length; i++) {
1429
- // invariant: at this point, fromBase^i = power
1430
- if (digits[i]) {
1431
- outArray = add(outArray, multiplyByNumber(digits[i], power, toBase), toBase);
1432
- }
1433
- power = multiplyByNumber(fromBase, power, toBase);
1434
- }
1435
-
1436
- var out = '';
1437
- for (let i = outArray.length - 1; i >= 0; i--) {
1438
- out += outArray[i].toString(toBase);
1439
- }
1440
- return out;
1441
- }
1442
-
1443
- // eslint-disable-next-line no-unused-vars
1444
- function decToHex (decStr) {
1445
- var hex = convertBase(decStr, 10, 16);
1446
- return hex ? '0x' + hex : null;
1447
- }
1448
-
1449
-
1450
- function hexToDec (hexStr) {
1451
- if (hexStr.substring(0, 2) === '0x') hexStr = hexStr.substring(2);
1452
- hexStr = hexStr.toLowerCase();
1453
- return convertBase(hexStr, 16, 10);
1454
- }
1455
- }