n20-common-lib 2.9.13 → 2.9.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (130) hide show
  1. package/nstc-g6/components/NstcCharts/NstcCharts.vue +16 -8
  2. package/package.json +8 -5
  3. package/src/assets/css/approve-card.scss +1 -1
  4. package/src/assets/css/date-quarter.scss +8 -0
  5. package/src/assets/css/expandable-pane.scss +7 -0
  6. package/src/assets/css/file-upload-table.scss +2 -3
  7. package/src/assets/css/font-icon.scss +3 -1
  8. package/src/assets/css/message.scss +6 -6
  9. package/src/assets/css/normalize.scss +4 -1
  10. package/src/assets/css/table.scss +16 -11
  11. package/src/assets/iconFont/SIMSUN.ttf +0 -0
  12. package/src/assets/iconFont/font.css +4 -0
  13. package/src/components/AIButton/index.vue +101 -0
  14. package/src/components/AdvancedFilter/formItemRender.vue +7 -4
  15. package/src/components/AdvancedFilter/index.vue +6 -7
  16. package/src/components/Anchor/index.vue +1 -0
  17. package/src/components/ApprovalButtons/index.vue +404 -82
  18. package/src/components/ApprovalButtons/indexApp.vue +1102 -0
  19. package/src/components/ApprovalButtons/selectSpr.vue +128 -0
  20. package/src/components/ApprovalButtons/setCarboncopyProp.vue +1 -1
  21. package/src/components/ApprovalButtons/setRejectToProp.vue +45 -5
  22. package/src/components/ApprovalButtons/showAppOpi.vue +265 -8
  23. package/src/components/ApprovalButtons/showOtherAttrNew.vue +161 -0
  24. package/src/components/ApprovalCard/index.vue +190 -44
  25. package/src/components/ApprovalCard/indexApp.vue +592 -0
  26. package/src/components/ApprovalRecord/approvalImgPro/child.vue +1 -1
  27. package/src/components/ApprovalRecord/approvalImgPro/index.vue +42 -5
  28. package/src/components/ApprovalRecord/index.vue +23 -6
  29. package/src/components/ApprovalRecord/indexApp.vue +79 -0
  30. package/src/components/AttachmentPass/index.vue +286 -0
  31. package/src/components/Button/button-group.vue +3 -1
  32. package/src/components/CascaderArea/index.vue +5 -6
  33. package/src/components/DatePicker/por.vue +31 -1
  34. package/src/components/DateSelect/quarterDatePicker.vue +23 -1
  35. package/src/components/Descriptions/index.vue +7 -3
  36. package/src/components/Dialog/index.vue +4 -0
  37. package/src/components/Diff/index.vue +4 -2
  38. package/src/components/DynamicField/DynamicField.vue +29 -6
  39. package/src/components/DynamicField/DynamicFieldMixin.js +13 -5
  40. package/src/components/DynamicField/DynamicFieldOptions.vue +135 -62
  41. package/src/components/DynamicField/DynamicTable.vue +11 -1
  42. package/src/components/DynamicField/contentPop.vue +110 -0
  43. package/src/components/DynamicField/tableList.vue +5 -1
  44. package/src/components/DynamicField/tableView.vue +143 -0
  45. package/src/components/ECharts/index.vue +15 -9
  46. package/src/components/Expandable/main.vue +17 -2
  47. package/src/components/FileImport/index.vue +4 -5
  48. package/src/components/FileUploadTable/FileUploadTableV3.vue +937 -0
  49. package/src/components/FileUploadTable/aiCheckDialog.vue +139 -0
  50. package/src/components/FileUploadTable/index.vue +251 -33
  51. package/src/components/FileUploadTable/jytg.svg +6 -0
  52. package/src/components/FileUploadTable/wsc.svg +3 -0
  53. package/src/components/FileUploadTable/ysc.svg +3 -0
  54. package/src/components/HandlingAdvice/index.vue +191 -0
  55. package/src/components/InputAccount/index.vue +105 -0
  56. package/src/components/InputNumber/index.vue +16 -4
  57. package/src/components/InputNumber/numberRange.vue +14 -0
  58. package/src/components/InputSearch/index.vue +8 -0
  59. package/src/components/Layout/HeaderWrap/changePwd.vue +50 -23
  60. package/src/components/Layout/HeaderWrap/index.vue +2 -2
  61. package/src/components/Layout/HeaderWrap/indexN.vue +296 -119
  62. package/src/components/Layout/SubContent/index.vue +45 -14
  63. package/src/components/Layout/indexN.vue +26 -5
  64. package/src/components/LoginTemporary/form.vue +126 -34
  65. package/src/components/LoginTemporary/index.vue +14 -3
  66. package/src/components/LoginTemporary/indexN.vue +35 -13
  67. package/src/components/Preview/index.vue +199 -0
  68. package/src/components/SelectDatePickerPro/customDatePicker.vue +7 -0
  69. package/src/components/SelectDatePickerPro/halfYearPicker.vue +165 -0
  70. package/src/components/SelectDatePickerPro/index.vue +44 -4
  71. package/src/components/SelectDatePickerPro/quarterDatePicker.vue +32 -10
  72. package/src/components/SelectTree/index.vue +10 -4
  73. package/src/components/SelectTree/pro.vue +3 -0
  74. package/src/components/ShowColumn/index copy 2.vue +545 -0
  75. package/src/components/ShowColumn/index copy.vue +566 -0
  76. package/src/components/ShowColumn/index.vue +11 -7
  77. package/src/components/Statis/statisItem.vue +8 -7
  78. package/src/components/Table/filters.js +13 -0
  79. package/src/components/Table/index.vue +4 -4
  80. package/src/components/TablePro/filterContent.vue +18 -8
  81. package/src/components/TablePro/index.js +41 -1
  82. package/src/components/TablePro/index.vue +117 -6
  83. package/src/components/TableProOperateColumn/OperateBtns.vue +11 -53
  84. package/src/components/TableProOperateColumn/OperateBtns_copy.vue +141 -0
  85. package/src/components/TableProOperateColumn/childrenOperateBtn.vue +108 -0
  86. package/src/components/TableProOperateColumn/index.vue +3 -6
  87. package/src/components/TableSetSize/index.vue +1 -1
  88. package/src/components/Tree/index.vue +21 -5
  89. package/src/components/Upload/index.vue +25 -10
  90. package/src/components/Upload/uploadMsg.vue +30 -25
  91. package/src/components/operatingStatus/index.vue +3 -4
  92. package/src/directives/VTitle/index.js +15 -5
  93. package/src/directives/watermark/index.js +140 -56
  94. package/src/i18n.json +146 -18
  95. package/src/index.js +31 -3
  96. package/src/plugins/Sign/CaMap.js +47 -8
  97. package/src/plugins/Sign/Itrus/index.js +1 -1
  98. package/src/plugins/Sign/Itrus/sign_3720.js +2 -1
  99. package/src/plugins/Sign/NetSM3/index.js +20 -11
  100. package/src/plugins/Sign/NetV3/index.js +163 -22
  101. package/src/plugins/Sign/SkfSign/index.js +55 -52
  102. package/src/plugins/Sign/bjca/index.js +229 -9
  103. package/src/plugins/Sign/hnca/index.js +5064 -0
  104. package/src/plugins/Sign/index.js +155 -103
  105. package/src/plugins/Sign/kySign/base64.js +160 -0
  106. package/src/plugins/Sign/kySign/hex.js +92 -0
  107. package/src/plugins/Sign/kySign/index.js +186 -0
  108. package/src/plugins/Sign/kySign/skf.js +937 -0
  109. package/src/plugins/Sign/kySign/test.html +463 -0
  110. package/src/plugins/Sign/sdca/index.js +73 -0
  111. package/src/plugins/Sign/sign.js +72 -52
  112. package/src/plugins/Sign/signV3/InfosecNetSignCNGAgent.min.js +1 -0
  113. package/src/plugins/Sign/signV3/sign.js +187 -0
  114. package/src/plugins/Sign/sign_back.js +172 -0
  115. package/src/utils/accountFormat.js +7 -0
  116. package/src/utils/asyncGetRelaNos.js +79 -46
  117. package/src/utils/axios.js +3 -5
  118. package/src/utils/i18n/index.js +1 -1
  119. package/src/utils/importGlobal.js +23 -12
  120. package/style/fonts/SIMSUN.5e0c362c.ttf +0 -0
  121. package/style/index.css +2 -2
  122. package/theme/blue.css +2 -2
  123. package/theme/cctcRed.css +2 -2
  124. package/theme/fonts/SIMSUN.5e0c362c.ttf +0 -0
  125. package/theme/green.css +2 -2
  126. package/theme/lightBlue.css +2 -2
  127. package/theme/orange.css +2 -2
  128. package/theme/purple.css +2 -2
  129. package/theme/red.css +2 -2
  130. package/theme/yellow.css +2 -2
@@ -1,137 +1,189 @@
1
1
  import importG from '../../utils/importGlobal.js'
2
2
 
3
3
  import CaMap from './CaMap.js'
4
- import { getCert as itrusGetCert } from './Itrus/index'
5
- import { getCertInfo as NetSM3 } from './NetSM3/index'
6
- import { getCertInfo as SkfSign } from './SkfSign/index'
7
- import { getCertInfo } from './sign'
4
+
5
+ /**
6
+ * 统一处理签名逻辑
7
+ * @param {Object} config - 签名配置
8
+ * @param {string} config.type - 签名类型
9
+ * @param {string|Function} config.path - 签名模块路径
10
+ * @param {boolean} config.needAvailable - 是否需要检查可用性
11
+ * @param {*} p1 - 签名参数1
12
+ * @param {*} p2 - 签名参数2
13
+ * @param {*} p3 - 签名参数3
14
+ * @returns {Promise<*>} 签名结果
15
+ */
16
+ async function disposeSign(config, p1, p2, p3) {
17
+ try {
18
+ // 如果是信安CA且在银河麒麟系统上,则使用国密签名
19
+ // 使用更可靠的系统和环境检测方法
20
+ if (
21
+ config.type === 'inetSign' &&
22
+ // 检查操作系统
23
+ (navigator.platform.toLowerCase().includes('linux') ||
24
+ navigator.userAgent.toLowerCase().includes('linux') ||
25
+ // 检查是否为银河麒麟特有的环境变量或特征
26
+ typeof window.KylinOS !== 'undefined' ||
27
+ document.documentElement.dataset.osType === 'kylin')
28
+ ) {
29
+ // 确保CaMap中存在SkfSign配置
30
+ if (!CaMap['SkfSign']) {
31
+ console.warn('未找到SkfSign配置,将继续使用原始配置')
32
+ return
33
+ }
34
+ config = CaMap['SkfSign']
35
+ }
36
+
37
+ const path = typeof config.path === 'function' ? config.path(p3) : config.path
38
+ const module = await importG(config.type, () => import(`${path}`))
39
+
40
+ if (config.needAvailable) {
41
+ await new Promise((resolve, reject) => {
42
+ module.availableSign((available) => {
43
+ available ? resolve() : reject(new Error('签名不可用'))
44
+ }, systemIdentification())
45
+ })
46
+ }
47
+
48
+ return await module.getSign(p1, p2, p3)
49
+ } catch (error) {
50
+ console.error('签名处理失败:', error)
51
+ throw error
52
+ }
53
+ }
54
+
55
+ function systemIdentification() {
56
+ const userAgent = navigator.userAgent || navigator.vendor || window.opera
57
+ let url = window.NetSignName || '/portal/NetSignCNG-v2.1.152.2.exe'
58
+ if (/windows/i.test(userAgent)) {
59
+ url = window.NetSignName
60
+ } else if (/linux/i.test(userAgent)) {
61
+ url = /Kylin/i.test(userAgent)
62
+ ? window.KylinSignName || '/portal/NetSignCNG-v2.1.152.2.rpm' // 麒麟系统
63
+ : window.linuxSignName || '/portal/NetSignCNG-v2.1.152.2.deb' // 普通Linux
64
+ }
65
+ return url
66
+ }
67
+
68
+ /**
69
+ * 获取签名
70
+ * @param {*} p1 - 签名参数1
71
+ * @param {*} p2 - 签名参数2
72
+ * @param {*} p3 - 签名参数3
73
+ * @returns {Promise<*>} 签名结果
74
+ */
8
75
  export async function getSign(p1, p2, p3) {
9
76
  let signType = window.sessionStorage.getItem('signType')
10
77
  if (!signType || !CaMap[signType]) {
11
- console.error('请设置签名服务公司sessionStorage.signType,公司字段映射:', CaMap)
78
+ console.error('请设置签名服务公司sessionStorage.signType')
12
79
  signType = CaMap['null'] ? CaMap['null'].type : ''
13
80
  }
14
- let url = window.NetSignName
81
+ // 是否使用信安3.0版本sdk (默认使用2.0版本)
82
+ if (window.NetSignVersion === 'signV3') {
83
+ return await disposeSign(CaMap['signV3'], p1, p2, p3)
84
+ } else {
85
+ return await disposeSign(CaMap[signType], p1, p2, p3)
86
+ }
87
+ }
15
88
 
16
- const por = new Promise((resolve, reject) => {
89
+ /**
90
+ * 获取证书信息
91
+ * @param {string} dn - 证书DN
92
+ * @returns {Promise<*>} 证书信息
93
+ */
94
+ export function getCert(dn) {
95
+ let signType = window.sessionStorage.getItem('signType')
96
+ console.log('signType', signType)
97
+ return new Promise((resolve, reject) => {
17
98
  if (signType === 'inetSign' /* 信安CA */) {
18
- importG('inetSign', () => import(/*webpackChunkName: "inetSign"*/ './sign.js')).then(
19
- ({ availableSign, getSign }) => {
20
- availableSign((available) => {
21
- if (available) {
22
- const sign = getSign(p1, p2, p3)
23
- resolve(sign)
24
- } else {
25
- reject()
26
- }
27
- }, url)
28
- }
29
- )
30
- } else if (signType === 'bjcaSign' /* 北京CA */) {
31
- importG('bjcaSign', () => import(/*webpackChunkName: "bjcaSign"*/ './bjca/index.js')).then(({ getSign }) => {
32
- getSign(p1, p2, p3)
33
- .then((sign) => {
34
- resolve(sign)
35
- })
36
- .catch(() => {
37
- reject()
38
- })
39
- })
40
- } else if (signType === 'ItrusSign' /* 天威CA */) {
41
- if (p3 && p3 === '3720') {
42
- importG('ItrusSign', () => import(/*webpackChunkName: "ItrusSign"*/ './Itrus/sign_3720.js')).then(
43
- ({ getSign }) => {
99
+ // 是否使用信安3.0版本sdk (默认使用2.0版本)
100
+ if (window.NetSignVersion === 'signV3') {
101
+ importG('inetSign', () => import(/*webpackChunkName: "inetSign"*/ './signV3/sign.js')).then(
102
+ ({ getCertInfo }) => {
44
103
  try {
45
- const ItrusSign = getSign(p1, p2, p3)
46
- resolve(ItrusSign)
104
+ const itrusGetCert = getCertInfo(dn)
105
+ resolve(itrusGetCert)
47
106
  } catch (error) {
48
107
  reject()
49
108
  }
50
109
  }
51
110
  )
52
111
  } else {
53
- importG('ItrusSign', () => import(/*webpackChunkName: "ItrusSign"*/ './Itrus/index.js')).then(({ getSign }) => {
112
+ importG('inetSign', () => import(/*webpackChunkName: "inetSign"*/ './sign.js')).then(({ getCertInfo }) => {
54
113
  try {
55
- const ItrusSign = getSign(p1, p2, p3)
56
- resolve(ItrusSign)
114
+ const itrusGetCert = getCertInfo(dn)
115
+ resolve(itrusGetCert)
57
116
  } catch (error) {
58
117
  reject()
59
118
  }
60
119
  })
61
120
  }
62
- } else if (signType === 'SkfSign' /* 信安国密CA */) {
63
- importG('SkfSign', () => import(/*webpackChunkName: "SkfSign"*/ './SkfSign/index.js')).then(
64
- ({ availableSign, getSign }) => {
65
- availableSign((available) => {
66
- if (available) {
67
- const SkfSign = getSign(p1, p2, p3)
68
- resolve(SkfSign)
69
- } else {
70
- reject()
71
- }
72
- }, url)
121
+ } else if (signType === 'SkfSign') {
122
+ importG('SkfSign', () => import(/*webpackChunkName: "SkfSign"*/ './SkfSign/index.js')).then(({ getCertInfo }) => {
123
+ try {
124
+ const itrusGetCert = getCertInfo(dn)
125
+ resolve(itrusGetCert)
126
+ } catch (error) {
127
+ reject()
73
128
  }
74
- )
75
- } else if (signType === 'netcaSign' /* 网证通 */) {
76
- importG('netcaSign', () => import(/*webpackChunkName: "netcaSign"*/ './netca/index.js')).then(({ getSign }) => {
77
- getSign(p1, p2, p3)
78
- .then((sign) => {
79
- resolve(sign)
80
- })
81
- .catch(() => {
82
- reject()
83
- })
84
129
  })
85
- } else if (signType === 'NetSM3' /* 信安国密CA软签 */) {
86
- importG('NetSM3', () => import(/*webpackChunkName: "NetSM3"*/ './NetSM3/index.js')).then(
87
- ({ availableSign, getSign }) => {
88
- availableSign((available) => {
89
- if (available) {
90
- const SkfSign = getSign(p1, p2, p3)
91
- resolve(SkfSign)
92
- } else {
93
- reject()
94
- }
95
- }, url)
130
+ } else if (signType === 'NetSM3') {
131
+ importG('NetSM3', () => import(/*webpackChunkName: "NetSM3"*/ './NetSM3/index.js')).then(({ getCertInfo }) => {
132
+ try {
133
+ const itrusGetCert = getCertInfo(dn)
134
+ resolve(itrusGetCert)
135
+ } catch (error) {
136
+ reject()
137
+ }
138
+ })
139
+ } else if (signType === 'ItrusSign') {
140
+ importG('ItrusSign', () => import(/*webpackChunkName: "ItrusSign"*/ './Itrus/index.js')).then(({ getCert }) => {
141
+ try {
142
+ const itrusGetCert = getCert(dn)
143
+ resolve(itrusGetCert)
144
+ } catch (error) {
145
+ reject()
146
+ }
147
+ })
148
+ } else if (signType === 'bjcaSign') {
149
+ importG('bjcaSign', () => import(/*webpackChunkName: "ItrusSign"*/ './bjca/index.js')).then(({ getCert }) => {
150
+ try {
151
+ const itrusGetCert = getCert(dn)
152
+ console.log('itrusGetCert', itrusGetCert)
153
+ resolve(itrusGetCert)
154
+ } catch (error) {
155
+ reject()
156
+ }
157
+ })
158
+ } else if (signType === 'hncaSign') {
159
+ importG('hncaSign', () => import(/*webpackChunkName: "ItrusSign"*/ './hnca/index.js')).then(({ getCert }) => {
160
+ try {
161
+ const hncaGetCert = getCert(dn)
162
+ resolve(hncaGetCert)
163
+ } catch (error) {
164
+ reject()
96
165
  }
97
- )
98
- } else if (signType === 'cfcaSign' /* CFCA */) {
99
- importG('CFCA', () => import(/*webpackChunkName: "CFCA"*/ './cfca/index.js')).then(({ getSign }) => {
100
- getSign(p1, p2, p3)
101
- .then((sign) => {
102
- resolve(sign)
103
- })
104
- .catch(() => {
105
- reject()
106
- })
107
166
  })
108
167
  }
109
168
  })
110
-
111
- return por
112
- }
113
-
114
- export function getCert(dn) {
115
- let signType = window.sessionStorage.getItem('signType')
116
- if (signType === 'inetSign' /* 信安CA */) {
117
- return getCertInfo(dn)
118
- } else if (signType === 'SkfSign') {
119
- return SkfSign(dn)
120
- } else if (signType === 'NetSM3') {
121
- return NetSM3(dn)
122
- } else if (signType === 'ItrusSign') {
123
- return itrusGetCert(dn)
124
- }
125
169
  }
126
170
 
127
- export function updateCert(cspName) {
128
- return importG('NetV3', () => import(/*webpackChunkName: "NetV3"*/ './NetV3/index.js')).then(({ updateCert }) => {
129
- updateCert(cspName)
130
- })
171
+ /**
172
+ * 更新证书
173
+ * @param {string} cspName - CSP名称
174
+ * @returns {Promise<void>}
175
+ */
176
+ export async function updateCert(cspName, onSuccess, dnInfo) {
177
+ const { updateCert } = await importG('NetV3', () => import(/*webpackChunkName: "NetV3"*/ './NetV3/index.js'))
178
+ await updateCert(cspName, onSuccess, dnInfo)
131
179
  }
132
180
 
133
- export function updateCertHG(uno) {
134
- return importG('NetV3', () => import(/*webpackChunkName: "NetV3"*/ './NetV3/index.js')).then(({ updateCertHG }) => {
135
- updateCertHG(uno)
136
- })
181
+ /**
182
+ * 更新证书(海港)
183
+ * @param {string} uno - 用户编号
184
+ * @returns {Promise<void>}
185
+ */
186
+ export async function updateCertHG(uno) {
187
+ const { updateCertHG } = await importG('NetV3', () => import(/*webpackChunkName: "NetV3"*/ './NetV3/index.js'))
188
+ await updateCertHG(uno)
137
189
  }
@@ -0,0 +1,160 @@
1
+ /*******************************************************
2
+ *
3
+ * 函数名称:Base64encode()
4
+ * 功 能:对数据进行Base64加密
5
+ * 说 明:函数中将数据使用_utf8_encode()进行编码转换后再加密,保证数据完整
6
+ *
7
+ **********************************************************/
8
+
9
+ var _keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='
10
+
11
+ function _Base64encode(input) {
12
+ var output = ''
13
+ var chr1, chr2, chr3, enc1, enc2, enc3, enc4
14
+ var i = 0
15
+
16
+ input = _utf8_encode(input)
17
+
18
+ while (i < input.length) {
19
+ chr1 = input.charCodeAt(i++)
20
+ chr2 = input.charCodeAt(i++)
21
+ chr3 = input.charCodeAt(i++)
22
+
23
+ enc1 = chr1 >> 2
24
+ enc2 = ((chr1 & 3) << 4) | (chr2 >> 4)
25
+ enc3 = ((chr2 & 15) << 2) | (chr3 >> 6)
26
+ enc4 = chr3 & 63
27
+
28
+ if (isNaN(chr2)) {
29
+ enc3 = enc4 = 64
30
+ } else if (isNaN(chr3)) {
31
+ enc4 = 64
32
+ }
33
+
34
+ output = output + _keyStr.charAt(enc1) + _keyStr.charAt(enc2) + _keyStr.charAt(enc3) + _keyStr.charAt(enc4)
35
+ }
36
+ return output
37
+ }
38
+
39
+ /*******************************************************
40
+ *
41
+ * 函数名称:Base64decode()
42
+ * 功 能:对数据进行Base64解密
43
+ * 说 明:函数中将数据使用_utf8_decode()将解密后的数据编码,保证数据完整
44
+ *
45
+ **********************************************************/
46
+ function _Base64decode(input) {
47
+ var output = ''
48
+ var chr1, chr2, chr3
49
+ var enc1, enc2, enc3, enc4
50
+ var i = 0
51
+
52
+ input = input.replace(/[^A-Za-z0-9\+\/\=]/g, '')
53
+
54
+ while (i < input.length) {
55
+ enc1 = _keyStr.indexOf(input.charAt(i++))
56
+ enc2 = _keyStr.indexOf(input.charAt(i++))
57
+ enc3 = _keyStr.indexOf(input.charAt(i++))
58
+ enc4 = _keyStr.indexOf(input.charAt(i++))
59
+
60
+ chr1 = (enc1 << 2) | (enc2 >> 4)
61
+ chr2 = ((enc2 & 15) << 4) | (enc3 >> 2)
62
+ chr3 = ((enc3 & 3) << 6) | enc4
63
+
64
+ output = output + String.fromCharCode(chr1)
65
+
66
+ if (enc3 != 64) {
67
+ output = output + String.fromCharCode(chr2)
68
+ }
69
+ if (enc4 != 64) {
70
+ output = output + String.fromCharCode(chr3)
71
+ }
72
+ }
73
+
74
+ output = _utf8_decode(output)
75
+
76
+ return output
77
+ }
78
+
79
+ /*******************************************************
80
+ *
81
+ * 函数名称:_utf8_encode()
82
+ * 功 能:将数据进行utf8编码
83
+ * 说 明:
84
+ *
85
+ **********************************************************/
86
+ function _utf8_encode(string) {
87
+ string = string.replace(/\r\n/g, '\n')
88
+ var utftext = ''
89
+
90
+ for (var n = 0; n < string.length; n++) {
91
+ var c = string.charCodeAt(n)
92
+
93
+ if (c < 128) {
94
+ utftext += String.fromCharCode(c)
95
+ } else if (c > 127 && c < 2048) {
96
+ utftext += String.fromCharCode((c >> 6) | 192)
97
+ utftext += String.fromCharCode((c & 63) | 128)
98
+ } else {
99
+ utftext += String.fromCharCode((c >> 12) | 224)
100
+ utftext += String.fromCharCode(((c >> 6) & 63) | 128)
101
+ utftext += String.fromCharCode((c & 63) | 128)
102
+ }
103
+ }
104
+ return utftext
105
+ }
106
+
107
+ /*******************************************************
108
+ *
109
+ * 函数名称:_utf8_decode()
110
+ * 功 能:将数据进行utf8解码
111
+ * 说 明:
112
+ *
113
+ **********************************************************/
114
+ function _utf8_decode(utftext) {
115
+ var string = ''
116
+ var i = 0
117
+ var c = (c1 = c2 = 0)
118
+
119
+ while (i < utftext.length) {
120
+ c = utftext.charCodeAt(i)
121
+
122
+ if (c < 128) {
123
+ string += String.fromCharCode(c)
124
+ i++
125
+ } else if (c > 191 && c < 224) {
126
+ c2 = utftext.charCodeAt(i + 1)
127
+ string += String.fromCharCode(((c & 31) << 6) | (c2 & 63))
128
+ i += 2
129
+ } else {
130
+ c2 = utftext.charCodeAt(i + 1)
131
+ c3 = utftext.charCodeAt(i + 2)
132
+ string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63))
133
+ i += 3
134
+ }
135
+ }
136
+ return string
137
+ }
138
+
139
+ function base64ToHex(base64String) {
140
+ const binaryString = atob(base64String)
141
+ let hexString = ''
142
+
143
+ for (let i = 0; i < binaryString.length; i++) {
144
+ const hex = binaryString.charCodeAt(i).toString(16)
145
+ hexString += hex.length === 1 ? '0' + hex : hex
146
+ }
147
+
148
+ return hexString
149
+ }
150
+
151
+ function hexToBase64(hexString) {
152
+ const binaryString = hexString
153
+ .match(/.{1,2}/g)
154
+ .map((hex) => String.fromCharCode(parseInt(hex, 16)))
155
+ .join('')
156
+ const base64String = btoa(binaryString)
157
+ return base64String
158
+ }
159
+
160
+ export { _Base64encode, hexToBase64, base64ToHex, _Base64decode }
@@ -0,0 +1,92 @@
1
+ /**
2
+ * Hex 16 进制转换
3
+ */
4
+
5
+ /**
6
+ * 将字节数组转换为 16 进制字符串
7
+ *
8
+ * @param {Uint8Array} bytes 8bits 大小的字节数组
9
+ *
10
+ * @return {String} 16 进制的字符串
11
+ *
12
+ * @static
13
+ *
14
+ * @example
15
+ *
16
+ * let bytes = [1, 2, 3, 4, 5, 6];
17
+ * let hexstr = KeyouCryptography.util.Hex.stringify(bytes);
18
+ * assert(hexstr === "010203040506");
19
+ */
20
+ function stringify(bytes) {
21
+ if (bytes?.length) {
22
+ let hexstr = []
23
+ const length = bytes.length
24
+ for (let i = 0; i < length; i++) {
25
+ let byte = bytes[i]
26
+ hexstr.push((byte >>> 4).toString(16))
27
+ hexstr.push((byte & 0x0f).toString(16))
28
+ alert(hexstr)
29
+ }
30
+ return hexstr.join('').toUpperCase()
31
+ } else {
32
+ return bytes
33
+ }
34
+ }
35
+ function encode(bytes) {
36
+ return stringify(bytes)
37
+ }
38
+
39
+ /**
40
+ * 将 16 进制的字符串转换为字节数组
41
+ *
42
+ * @param {String} hexstr 16 进制的字符串
43
+ *
44
+ * @return {Uint8Array} 字节数组
45
+ *
46
+ * @static
47
+ *
48
+ * @example
49
+ *
50
+ * let hexstr = "313233343536";
51
+ * let bytes = KeyouCryptography.util.Hex.parse(hexstr);
52
+ * assert(bytes === ['1', '2', '3', '4', '5', '6']);
53
+ */
54
+ function parse(hexstr) {
55
+ let bytes = []
56
+ if (!(hexstr != undefined && hexstr.length % 2 == 0)) {
57
+ throw new TypeError('illegal Hex string:' + hexstr)
58
+ }
59
+ let regExp = new RegExp('[A-Fa-f0-9]+$', 'g')
60
+ if (!hexstr.match(regExp)) {
61
+ throw new TypeError('illegal Hex string:' + hexstr)
62
+ }
63
+ const length = hexstr.length / 2
64
+ for (let i = 0; i < length; i++) {
65
+ bytes[i] = parseInt(hexstr.substring(i * 2, i * 2 + 2), 16)
66
+ }
67
+ return bytes
68
+ }
69
+ function decode(hexstr) {
70
+ return parse(hexstr)
71
+ }
72
+ /*
73
+ * 负数的bytes转为正数
74
+ */
75
+ function toUnsignBytes(bytes) {
76
+ let bs = []
77
+ for (let i = 0; i < bytes.length; i++) {
78
+ let b = bytes[i]
79
+ if (b < 0) {
80
+ b += 256
81
+ }
82
+ bs[i] = b
83
+ }
84
+ return bs
85
+ }
86
+ function stringToRawHex(str) {
87
+ return Array.from(str)
88
+ .map((char) => char.charCodeAt(0).toString(16).padStart(2, '0').toUpperCase())
89
+ .join('')
90
+ }
91
+
92
+ export { encode, decode, toUnsignBytes, stringToRawHex }