@toolspack/ttd-common 0.4.7 → 0.5.0
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.
- package/README.md +9 -6
- package/lib/ttd-common.common.js +2029 -5264
- package/lib/ttd-common.umd.js +2029 -5264
- package/lib/ttd-common.umd.min.js +1 -1
- package/package.json +2 -2
- package/src/App.vue +0 -2
- package/src/packages/cfca/CfcaPdf.vue +33 -25
- package/src/packages/index.js +4 -0
- package/src/packages/ukey/SignNew.vue +35 -0
- package/src/packages/ukey/WZHforChrome.js +167 -0
- package/src/packages/ukey/WzhSign.vue +72 -40
- package/src/packages/ukey/WzhSignChrome.vue +261 -0
- package/src/packages/ukey/nmCryptokit.ToToDi.js +338 -0
- package/src/views/About.vue +0 -14
- package/src/views/MakeLabel.vue +0 -178
- package/src/views/MakelLabel.less +0 -162
- package/src/views/labels.js +0 -48
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
|
|
3
|
+
import {nmCryptokit} from './nmCryptokit.ToToDi.js'
|
|
4
|
+
export default {
|
|
5
|
+
methods: {
|
|
6
|
+
BrowserInfo() {
|
|
7
|
+
const res = {
|
|
8
|
+
name: '',
|
|
9
|
+
version: '',
|
|
10
|
+
};
|
|
11
|
+
let reg;
|
|
12
|
+
const userAgent = self.navigator.userAgent;
|
|
13
|
+
|
|
14
|
+
if (reg = /edge\/([\d\.]+)/i.exec(userAgent)) {
|
|
15
|
+
res.name = 'Edge';
|
|
16
|
+
res.version = reg[1];
|
|
17
|
+
} else if (reg = /edg\/([\d\.]+)/i.exec(userAgent)) {
|
|
18
|
+
res.name = 'Edge(Chromium)';
|
|
19
|
+
res.version = reg[1];
|
|
20
|
+
} else if (/msie/i.test(userAgent)) {
|
|
21
|
+
res.name = 'Internet Explorer';
|
|
22
|
+
res.version = /msie ([\d\.]+)/i.exec(userAgent)[1];
|
|
23
|
+
} else if (/Trident/i.test(userAgent)) {
|
|
24
|
+
res.name = 'Internet Explorer';
|
|
25
|
+
res.version = /rv:([\d\.]+)/i.exec(userAgent)[1];
|
|
26
|
+
} else if (/chrome/i.test(userAgent)) {
|
|
27
|
+
res.name = 'Chrome';
|
|
28
|
+
res.version = /chrome\/([\d\.]+)/i.exec(userAgent)[1];
|
|
29
|
+
} else if (/safari/i.test(userAgent)) {
|
|
30
|
+
res.name = 'Safari';
|
|
31
|
+
res.version = /version\/([\d\.]+)/i.exec(userAgent)[1];
|
|
32
|
+
} else if (/firefox/i.test(userAgent)) {
|
|
33
|
+
res.name = 'Firefox';
|
|
34
|
+
res.version = /firefox\/([\d\.]+)/i.exec(userAgent)[1];
|
|
35
|
+
}
|
|
36
|
+
return res;
|
|
37
|
+
},
|
|
38
|
+
LoadObj() {
|
|
39
|
+
|
|
40
|
+
try {
|
|
41
|
+
let extensionVer;
|
|
42
|
+
let hostVer;
|
|
43
|
+
|
|
44
|
+
const browser = this.BrowserInfo();
|
|
45
|
+
|
|
46
|
+
console.log('browser=' ,browser)
|
|
47
|
+
if ((browser.name == 'Edge')
|
|
48
|
+
|| (browser.name == 'Edge(Chromium)')
|
|
49
|
+
|| (browser.name == 'Chrome' && parseInt(browser.version) > 41)
|
|
50
|
+
|| (browser.name == 'Firefox' && parseInt(browser.version) > 52)) {
|
|
51
|
+
this.CryptoAgent = new nmCryptokit(browser.name);
|
|
52
|
+
|
|
53
|
+
this.CryptoAgent.init()
|
|
54
|
+
.then(() => {
|
|
55
|
+
console.log(6662);
|
|
56
|
+
return this.CryptoAgent.getExtensionVersion()
|
|
57
|
+
}).then((response) => {
|
|
58
|
+
console.log(777);
|
|
59
|
+
extensionVer = response.result;
|
|
60
|
+
return this.CryptoAgent.getHostVersion();
|
|
61
|
+
}).then((response) => {
|
|
62
|
+
console.log(85888);
|
|
63
|
+
hostVer = response.result;
|
|
64
|
+
console.log(`extension version: ${ extensionVer}`);
|
|
65
|
+
console.log(`host version: ${ hostVer}`);
|
|
66
|
+
|
|
67
|
+
const extensionLevel = this.compareExtensionVersion(extensionVer);
|
|
68
|
+
const hostLevel = this.compareVersion(hostVer, '3.4.0.1')
|
|
69
|
+
|
|
70
|
+
console.log(`extensionLevel ${ extensionLevel}`);
|
|
71
|
+
console.log(`hostLevel: ${ hostLevel}`);
|
|
72
|
+
|
|
73
|
+
if (hostLevel < 0 && extensionLevel < 0) {
|
|
74
|
+
alert('Please install host');
|
|
75
|
+
} else if (hostLevel < 0) {
|
|
76
|
+
installHost();
|
|
77
|
+
} else {
|
|
78
|
+
console.log('LoadObj success!')
|
|
79
|
+
}
|
|
80
|
+
}).catch((response) => {
|
|
81
|
+
console.log('response=', response)
|
|
82
|
+
// alert(response.result);
|
|
83
|
+
});
|
|
84
|
+
} else {
|
|
85
|
+
alert('Unsupported browser!');
|
|
86
|
+
}
|
|
87
|
+
} catch (e) {
|
|
88
|
+
alert(e);
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
|
|
92
|
+
// version1 == version2 0
|
|
93
|
+
// version1 < version2 -1
|
|
94
|
+
// version1 > version2 1
|
|
95
|
+
compareVersion(version1, version2) {
|
|
96
|
+
const v1Arr = version1.split('.');
|
|
97
|
+
const v2Arr = version2.split('.');
|
|
98
|
+
const len = Math.min(v1Arr.length, v2Arr.length);
|
|
99
|
+
for (let i = 0; i < len; i++) {
|
|
100
|
+
if (parseInt(v1Arr[i], 10) > parseInt(v2Arr[i], 10)) { return 1; }
|
|
101
|
+
|
|
102
|
+
if (parseInt(v1Arr[i], 10) < parseInt(v2Arr[i], 10)) { return -1; }
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (len < v1Arr.length) {
|
|
106
|
+
for (var j = len; j < v1Arr.length; j++) {
|
|
107
|
+
if (parseInt(v1Arr[j], 10) != 0) { return 1; }
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (len < v2Arr.length) {
|
|
112
|
+
for (var j = len; j < v2Arr.length; j++) {
|
|
113
|
+
if (parseInt(v2Arr[j], 10) != 0) { return -1; }
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return 0;
|
|
118
|
+
},
|
|
119
|
+
|
|
120
|
+
// version1 == version2 0
|
|
121
|
+
// version1 < version2 -1
|
|
122
|
+
// version1 > version2 1
|
|
123
|
+
compareExtensionVersion(version) {
|
|
124
|
+
const browser = this.BrowserInfo();
|
|
125
|
+
|
|
126
|
+
if (browser.name == 'Edge') {
|
|
127
|
+
return this.compareVersion(version, '3.4.0.1');
|
|
128
|
+
}
|
|
129
|
+
if (browser.name == 'Chrome') {
|
|
130
|
+
return this.compareVersion(version, '3.4.0.1');
|
|
131
|
+
}
|
|
132
|
+
if (browser.name == 'Firefox') {
|
|
133
|
+
return this.compareVersion(version, '3.4.0.1');
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
|
|
137
|
+
intallExtensionCallback(url, status) {
|
|
138
|
+
if (status == 0) {
|
|
139
|
+
window.setTimeout('installHost()', 1000);
|
|
140
|
+
} else {
|
|
141
|
+
alert('Install extension failed!');
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
|
|
145
|
+
OnUnLoad() {
|
|
146
|
+
try {
|
|
147
|
+
this.CryptoAgent.uninit().then(() => { });
|
|
148
|
+
} catch (e) {
|
|
149
|
+
alert(e);
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
ShowErrorInfo(response) {
|
|
155
|
+
if (response == null) {
|
|
156
|
+
alert('Extension has been remove!');
|
|
157
|
+
} else if (response.errorcode == 1) { // connection error
|
|
158
|
+
alert(response.result);
|
|
159
|
+
} else { // host error
|
|
160
|
+
this.CryptoAgent.GetLastErrorDesc()
|
|
161
|
+
.then((response) => {
|
|
162
|
+
alert(response.result);
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
},
|
|
166
|
+
},
|
|
167
|
+
}
|
|
@@ -1,28 +1,16 @@
|
|
|
1
1
|
<!--无纸化 签署-->
|
|
2
2
|
<template>
|
|
3
3
|
<div class="CryptoAgent-wrapper">
|
|
4
|
-
<template v-if="isIE">
|
|
5
|
-
<!-- id="CryptoAgent" -->
|
|
6
4
|
<object ref="CryptoAgent" :codebase="publicPath+codebase" :classid="classid"></object>
|
|
7
|
-
</template>
|
|
8
|
-
<template v-else>
|
|
9
|
-
<embed
|
|
10
|
-
ref="CryptoAgent"
|
|
11
|
-
type="application/npCryptoKit.Paperless.x86"
|
|
12
|
-
style="height: 0px; width: 0px"
|
|
13
|
-
/>
|
|
14
|
-
</template>
|
|
15
5
|
</div>
|
|
16
6
|
</template>
|
|
17
7
|
<script>
|
|
18
8
|
// import { getSignHash, mergeHash } from '@/api/ess'
|
|
19
9
|
|
|
20
10
|
import { getUrl } from '../utils'
|
|
21
|
-
import CheckUkeyMethods from './CheckUkeyMethods'
|
|
22
11
|
|
|
23
12
|
export default {
|
|
24
13
|
name: 'wzh-sing',
|
|
25
|
-
mixins: [CheckUkeyMethods],
|
|
26
14
|
data() {
|
|
27
15
|
let codebase = ''
|
|
28
16
|
let classid = ''
|
|
@@ -60,41 +48,37 @@ export default {
|
|
|
60
48
|
if (this.CryptoAgent) {
|
|
61
49
|
return false
|
|
62
50
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
alert('验签插件加载失败!')
|
|
69
|
-
}
|
|
70
|
-
console.log('加载this.CryptoAgent ', this.CryptoAgent)
|
|
71
|
-
} else {
|
|
72
|
-
return false
|
|
51
|
+
// 使用refs 拿到的元素 不能ukey签章
|
|
52
|
+
// this.CryptoAgent = document.getElementById('CryptoAgent')
|
|
53
|
+
this.CryptoAgent = this.$refs.CryptoAgent
|
|
54
|
+
if (!this.CryptoAgent) {
|
|
55
|
+
alert('验签插件加载失败!')
|
|
73
56
|
}
|
|
57
|
+
console.log('加载this.CryptoAgent ', this.CryptoAgent)
|
|
74
58
|
},
|
|
75
59
|
|
|
76
60
|
getUkeyImage() {
|
|
77
61
|
let image = ''
|
|
78
62
|
try {
|
|
79
63
|
image = this.CryptoAgent.GetSealImage('CFCA_UKEY_P11.dll')
|
|
80
|
-
console.log('
|
|
64
|
+
console.log('CFCA_UKEY_P11', image)
|
|
81
65
|
} catch (e) {
|
|
82
|
-
console.log('error', e)
|
|
66
|
+
console.log('CFCA_UKEY_P11 error', e)
|
|
83
67
|
}
|
|
84
68
|
if (!image) {
|
|
85
69
|
try {
|
|
86
70
|
image = this.CryptoAgent.GetSealImage('UyeePKCS11.Enterprise.dll')
|
|
87
|
-
console.log('
|
|
71
|
+
console.log('UyeePKCS11', image)
|
|
88
72
|
} catch (e) {
|
|
89
|
-
console.log('error', e)
|
|
73
|
+
console.log('UyeePKCS11 error', e)
|
|
90
74
|
}
|
|
91
75
|
}
|
|
92
76
|
if (!image) {
|
|
93
77
|
try {
|
|
94
78
|
image = this.CryptoAgent.GetSealImage('UlanPKCS11.Enterprise.dll')
|
|
95
|
-
console.log('UlanPKCS11', image)
|
|
79
|
+
console.log('UlanPKCS11.Enterprise', image)
|
|
96
80
|
} catch (e) {
|
|
97
|
-
console.log('error', e)
|
|
81
|
+
console.log('UlanPKCS11.Enterprise error', e)
|
|
98
82
|
}
|
|
99
83
|
}
|
|
100
84
|
if (!image) {
|
|
@@ -110,6 +94,40 @@ export default {
|
|
|
110
94
|
}
|
|
111
95
|
return image
|
|
112
96
|
},
|
|
97
|
+
// 消息签名, 生成Base64 编码的 PKCS#7 签名结果
|
|
98
|
+
SignOnClick() {
|
|
99
|
+
let errorDesc = ''
|
|
100
|
+
this.sourceData = `${new Date().getTime() }`
|
|
101
|
+
try {
|
|
102
|
+
const source = this.sourceData
|
|
103
|
+
let signature = ''
|
|
104
|
+
const signType = 'Attach' // 签名类型
|
|
105
|
+
const selectedAlg = 'SHA-1' // 哈希算法(仅对RSA算法有效,SM2默认使用SM3哈希算法):
|
|
106
|
+
|
|
107
|
+
if (signType === 'Attach') {
|
|
108
|
+
// PKCS#7 Attach
|
|
109
|
+
signature = this.CryptoAgent.SignMsgPKCS7(source, selectedAlg, true)
|
|
110
|
+
} else if (signType === 'Detach') {
|
|
111
|
+
// PKCS#7 Detach
|
|
112
|
+
signature = this.CryptoAgent.SignMsgPKCS7(source, selectedAlg, false)
|
|
113
|
+
} else {
|
|
114
|
+
// PKCS#1
|
|
115
|
+
signature = this.CryptoAgent.SignMsgPKCS1(source, selectedAlg)
|
|
116
|
+
}
|
|
117
|
+
if (!signature) {
|
|
118
|
+
errorDesc = this.CryptoAgent.GetLastErrorDesc()
|
|
119
|
+
alert(errorDesc)
|
|
120
|
+
return ''
|
|
121
|
+
}
|
|
122
|
+
console.log('SignOnClick 签名结果:', signature)
|
|
123
|
+
return signature
|
|
124
|
+
} catch (e) {
|
|
125
|
+
console.log('SignOnClick error=', e)
|
|
126
|
+
errorDesc = this.CryptoAgent.GetLastErrorDesc()
|
|
127
|
+
alert(errorDesc)
|
|
128
|
+
}
|
|
129
|
+
return ''
|
|
130
|
+
},
|
|
113
131
|
GetCertInfoOnClick(InfoTypeID) {
|
|
114
132
|
InfoTypeID = InfoTypeID || 'SubjectDN'
|
|
115
133
|
console.log('GetCertInfoOnClick:InfoTypeID ', InfoTypeID)
|
|
@@ -119,13 +137,13 @@ export default {
|
|
|
119
137
|
if (!InfoContent) {
|
|
120
138
|
const errorDesc = this.CryptoAgent.GetLastErrorDesc()
|
|
121
139
|
alert(errorDesc)
|
|
122
|
-
return
|
|
140
|
+
return false
|
|
123
141
|
}
|
|
124
142
|
return InfoContent
|
|
125
143
|
} catch (e) {
|
|
126
144
|
console.log('GetCertInfoOnClick-WzhSign: ', e)
|
|
127
145
|
const errorDesc = this.CryptoAgent.GetLastErrorDesc()
|
|
128
|
-
alert(errorDesc)
|
|
146
|
+
alert(errorDesc + e)
|
|
129
147
|
}
|
|
130
148
|
},
|
|
131
149
|
SelectCertificateOnClick(serialNo = '') {
|
|
@@ -134,7 +152,7 @@ export default {
|
|
|
134
152
|
}
|
|
135
153
|
try {
|
|
136
154
|
const subjectDNFilter = '';
|
|
137
|
-
const issuerDNFilter = 'CFCA ACS
|
|
155
|
+
const issuerDNFilter = 'CFCA ACS';// CFCA ACS OCA31 ,CFCA ACS OCA32, CFCA ACS TEST OCA31
|
|
138
156
|
const serialNumFilter = serialNo;
|
|
139
157
|
const bstrSM2CSPNameList = 'Uyee CSP v6.0 (Enterprise)||CFCA FOR UKEY CSP v1.1.0'
|
|
140
158
|
let bSelectCertResult = '';
|
|
@@ -145,20 +163,24 @@ export default {
|
|
|
145
163
|
const errorDesc = this.CryptoAgent.GetLastErrorDesc();
|
|
146
164
|
console.log('wzh SelectCertResult 不存在', errorDesc)
|
|
147
165
|
alert(errorDesc);
|
|
148
|
-
return;
|
|
166
|
+
return false;
|
|
149
167
|
}
|
|
150
168
|
console.log('wzh SelectCertResult', bSelectCertResult)
|
|
151
169
|
return true
|
|
152
170
|
} catch (e) {
|
|
153
171
|
const errorDesc2 = this.CryptoAgent.GetLastErrorDesc();
|
|
154
172
|
console.log('wzh SelectCertResult catch error: ', errorDesc2)
|
|
155
|
-
alert(errorDesc2);
|
|
173
|
+
alert(errorDesc2 + e);
|
|
156
174
|
return false
|
|
157
175
|
}
|
|
158
176
|
},
|
|
159
177
|
getHashValue(label, fileOss, sealImage) {
|
|
160
178
|
const CertContent = this.CryptoAgent.GetSignCertInfo('CertContent');
|
|
161
179
|
this.$emit('getImg', sealImage)
|
|
180
|
+
if (!CertContent) {
|
|
181
|
+
alert('获取证书公钥失败!')
|
|
182
|
+
return Promise.reject()
|
|
183
|
+
}
|
|
162
184
|
if (fileOss.bucketName && fileOss.objectKey) {
|
|
163
185
|
return this.api.getSignHash({
|
|
164
186
|
jsonData: {
|
|
@@ -207,11 +229,12 @@ export default {
|
|
|
207
229
|
} catch (e) {
|
|
208
230
|
const errorDesc2 = this.CryptoAgent.GetLastErrorDesc();
|
|
209
231
|
console.log('getSignHashValue', e)
|
|
210
|
-
alert(errorDesc2);
|
|
232
|
+
alert(errorDesc2 + e);
|
|
211
233
|
}
|
|
212
234
|
},
|
|
213
235
|
async signFileKeyImage(item, fileItem, image) {
|
|
214
236
|
const res = await this.getSignHashValue(item, fileItem, image)
|
|
237
|
+
let errorMsg = '计算Hash 失败!'
|
|
215
238
|
if (res) {
|
|
216
239
|
const { data, code } = await this.api.mergeHash({
|
|
217
240
|
jsonData: {
|
|
@@ -224,25 +247,34 @@ export default {
|
|
|
224
247
|
},
|
|
225
248
|
})
|
|
226
249
|
// 此方法 code 不能完全说明正确,调用失败code 也是0
|
|
227
|
-
if (code === 0
|
|
228
|
-
|
|
250
|
+
if (code === 0) {
|
|
251
|
+
if (data.bean.url) {
|
|
252
|
+
return data.bean
|
|
253
|
+
}
|
|
254
|
+
errorMsg = data.bean.msg
|
|
255
|
+
} else {
|
|
256
|
+
errorMsg = data.msg
|
|
229
257
|
}
|
|
230
258
|
}
|
|
231
|
-
this.$message.error('计算Hash
|
|
259
|
+
this.$message.error(errorMsg || 'error计算Hash失败!')
|
|
232
260
|
return false
|
|
233
261
|
},
|
|
234
262
|
// fileOss: 为文件对象 {obje}
|
|
235
263
|
// isOffset: 修正印章的位置,印章加时间后需要向下修正
|
|
236
|
-
async multipleSign(labels, fileOss, serialNo, image, isOffset =
|
|
264
|
+
async multipleSign(labels, fileOss, serialNo, image, isOffset = 18) {
|
|
237
265
|
const serialNoBegin = this.CryptoAgent.GetSignCertInfo('SerialNumber');
|
|
238
266
|
let result = ''
|
|
267
|
+
if (!image) {
|
|
268
|
+
alert('印章图片缺失!')
|
|
269
|
+
return false
|
|
270
|
+
}
|
|
239
271
|
|
|
240
272
|
for (let index = 0; index < labels.length; index++) {
|
|
241
273
|
const item = getUrl(labels[index])
|
|
242
274
|
// 此处for循环多个文件时候以前签署,所以提示无意义
|
|
243
275
|
// const message = `签署 [${text}] 位于第${label.pageIndex}页的位置,[总共:${index + 1}/${labels.length}个位置]`
|
|
244
276
|
if (typeof isOffset === 'number') {
|
|
245
|
-
//
|
|
277
|
+
// 印章统一向下偏移
|
|
246
278
|
item.Y -= isOffset
|
|
247
279
|
}
|
|
248
280
|
if (index > 0) {
|
|
@@ -275,7 +307,7 @@ export default {
|
|
|
275
307
|
.CryptoAgent-wrapper {
|
|
276
308
|
height: 0;
|
|
277
309
|
width: 0;
|
|
278
|
-
position:
|
|
310
|
+
position: absolute;
|
|
279
311
|
left: -5000px;
|
|
280
312
|
}
|
|
281
313
|
</style>>
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
<!--无纸化 签署-->
|
|
2
|
+
<template>
|
|
3
|
+
<div class="CryptoAgent-wrapper">
|
|
4
|
+
</div>
|
|
5
|
+
</template>
|
|
6
|
+
<script>
|
|
7
|
+
// import { getSignHash, mergeHash } from '@/api/ess'
|
|
8
|
+
|
|
9
|
+
import { getUrl } from '../utils'
|
|
10
|
+
|
|
11
|
+
import WZHforChrome from './WZHforChrome'
|
|
12
|
+
|
|
13
|
+
export default {
|
|
14
|
+
mixins: [WZHforChrome],
|
|
15
|
+
data() {
|
|
16
|
+
return {
|
|
17
|
+
isIE: navigator.appName.indexOf('Internet') >= 0 || navigator.appVersion.indexOf('Trident') >= 0,
|
|
18
|
+
sourceData: '', // 签名原文, 动态随机字符串
|
|
19
|
+
certType: 'RSA', // 签名算法
|
|
20
|
+
CryptoAgent: null,
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
props: {
|
|
24
|
+
api: {
|
|
25
|
+
type: Object,
|
|
26
|
+
required: true,
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
mounted() {
|
|
30
|
+
this.onLoad()
|
|
31
|
+
},
|
|
32
|
+
provide() {
|
|
33
|
+
return {
|
|
34
|
+
GetCertInfoOnClick: this.GetCertInfoOnClick,
|
|
35
|
+
SelectCertificateOnClick: this.SelectCertificateOnClick,
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
methods: {
|
|
39
|
+
/**
|
|
40
|
+
* 初始化验签工具包,加载 验签空间(object)
|
|
41
|
+
*/
|
|
42
|
+
onLoad() {
|
|
43
|
+
if (this.CryptoAgent) {
|
|
44
|
+
console.log(3333, this.CryptoAgent)
|
|
45
|
+
return false
|
|
46
|
+
}
|
|
47
|
+
this.LoadObj()
|
|
48
|
+
},
|
|
49
|
+
|
|
50
|
+
getUkeyImage() {
|
|
51
|
+
let image = ''
|
|
52
|
+
try {
|
|
53
|
+
image = this.CryptoAgent.GetSealImage('CFCA_UKEY_P11.dll')
|
|
54
|
+
console.log('CFCA_UKEY_P11', image)
|
|
55
|
+
} catch (e) {
|
|
56
|
+
console.log('CFCA_UKEY_P11 error', e)
|
|
57
|
+
}
|
|
58
|
+
if (!image) {
|
|
59
|
+
try {
|
|
60
|
+
image = this.CryptoAgent.GetSealImage('UyeePKCS11.Enterprise.dll')
|
|
61
|
+
console.log('UyeePKCS11', image)
|
|
62
|
+
} catch (e) {
|
|
63
|
+
console.log('UyeePKCS11 error', e)
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (!image) {
|
|
67
|
+
try {
|
|
68
|
+
image = this.CryptoAgent.GetSealImage('UlanPKCS11.Enterprise.dll')
|
|
69
|
+
console.log('UlanPKCS11.Enterprise', image)
|
|
70
|
+
} catch (e) {
|
|
71
|
+
console.log('UlanPKCS11.Enterprise error', e)
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (!image) {
|
|
75
|
+
try {
|
|
76
|
+
image = this.CryptoAgent.GetSealImage('UlanPKCS11.dll')
|
|
77
|
+
console.log('UlanPKCS11', image)
|
|
78
|
+
} catch (e) {
|
|
79
|
+
console.log('error', e)
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (!image) {
|
|
83
|
+
alert('读取Ukey印章图片失败!')
|
|
84
|
+
}
|
|
85
|
+
return image
|
|
86
|
+
},
|
|
87
|
+
GetCertInfoOnClick(InfoTypeID) {
|
|
88
|
+
InfoTypeID = InfoTypeID || 'SubjectDN'
|
|
89
|
+
console.log('GetCertInfoOnClick:InfoTypeID ', InfoTypeID)
|
|
90
|
+
return this.CryptoAgent.GetSignCertInfo(InfoTypeID).then((response) => response.result).catch((e) => {
|
|
91
|
+
console.log('GetCertInfoOnClick-WzhSign: ', e)
|
|
92
|
+
alert(e)
|
|
93
|
+
})
|
|
94
|
+
},
|
|
95
|
+
|
|
96
|
+
async SignOnClick() {
|
|
97
|
+
const errorDesc = ''
|
|
98
|
+
this.sourceData = `${new Date().getTime() }`
|
|
99
|
+
const source = this.sourceData
|
|
100
|
+
let signature = ''
|
|
101
|
+
const signType = 'Attach' // 签名类型
|
|
102
|
+
const selectedAlg = 'SHA-1' // 哈希算法(仅对RSA算法有效,SM2默认使用SM3哈希算法):
|
|
103
|
+
|
|
104
|
+
if (signType === 'Attach') {
|
|
105
|
+
// PKCS#7 Attach
|
|
106
|
+
signature = await this.CryptoAgent.SignMsgPKCS7(source, selectedAlg, true)
|
|
107
|
+
} else if (signType === 'Detach') {
|
|
108
|
+
// PKCS#7 Detach
|
|
109
|
+
signature = await this.CryptoAgent.SignMsgPKCS7(source, selectedAlg, false)
|
|
110
|
+
} else {
|
|
111
|
+
// PKCS#1
|
|
112
|
+
signature = await this.CryptoAgent.SignMsgPKCS1(source, selectedAlg)
|
|
113
|
+
}
|
|
114
|
+
console.log('SignOnClick 签名结果:', signature)
|
|
115
|
+
return signature.result
|
|
116
|
+
},
|
|
117
|
+
async SelectCertificateOnClick(serialNo = '') {
|
|
118
|
+
const subjectDNFilter = '';
|
|
119
|
+
const issuerDNFilter = 'CFCA ACS ';// CFCA ACS OCA31 ,CFCA ACS OCA32, CFCA ACS TEST OCA31
|
|
120
|
+
const serialNumFilter = serialNo;
|
|
121
|
+
const bstrSM2CSPNameList = 'Uyee CSP v6.0 (Enterprise)||CFCA FOR UKEY CSP v1.1.0'
|
|
122
|
+
|
|
123
|
+
return this.CryptoAgent.SelectCertificate(subjectDNFilter, issuerDNFilter, serialNumFilter, bstrSM2CSPNameList)
|
|
124
|
+
.then((response) => response.result)
|
|
125
|
+
.catch((response) => {
|
|
126
|
+
console.log('SelectCertificate:', response)
|
|
127
|
+
alert('证书选择失败!');
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
// 返回值resSelect 在chrome下是 对象,在ie下返回是 true/false
|
|
131
|
+
},
|
|
132
|
+
async getHashValue(label, fileOss, sealImage) {
|
|
133
|
+
const CertContent = await this.GetCertInfoOnClick('CertContent');
|
|
134
|
+
this.$emit('getImg', sealImage)
|
|
135
|
+
if (!CertContent) {
|
|
136
|
+
alert('获取证书公钥失败!')
|
|
137
|
+
return Promise.reject()
|
|
138
|
+
}
|
|
139
|
+
if (fileOss.bucketName && fileOss.objectKey) {
|
|
140
|
+
return this.api.getSignHash({
|
|
141
|
+
jsonData: {
|
|
142
|
+
source: 'TTDFUND',
|
|
143
|
+
timestamp: new Date().getTime(),
|
|
144
|
+
msgBody: {
|
|
145
|
+
// 合同地址, 相对路径--合同文件全路径。网络地址:http://xxxxxx.pdf;阿里云地址:oss:bucketxx:key
|
|
146
|
+
attachfile: `oss:${fileOss.bucketName}:${fileOss.objectKey}`,
|
|
147
|
+
reason: '', // 签署原因
|
|
148
|
+
location: '', // 签署地点
|
|
149
|
+
signImgfileName: '', // 图片名称
|
|
150
|
+
signImgfile: sealImage, // 图片路径,格式同文件字段类似
|
|
151
|
+
pageNo: label.pageIndex, // 签章页
|
|
152
|
+
pageX: Number(label.X), // 签章页签章位置X坐标
|
|
153
|
+
pageY: Number(label.Y), // 签章页签章位置Y坐标
|
|
154
|
+
certBase64: CertContent, // 证书公钥
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
})
|
|
158
|
+
}
|
|
159
|
+
alert('文件对象不合规!')
|
|
160
|
+
return Promise.reject()
|
|
161
|
+
},
|
|
162
|
+
async getSignHashValue(item, fileItem, image) {
|
|
163
|
+
let sourceHashData = ''
|
|
164
|
+
const { code, data } = await this.getHashValue(item, fileItem, image);
|
|
165
|
+
if (code === 0) {
|
|
166
|
+
if (`${data.bean.code}` === '200') { sourceHashData = data.bean.pdfHash }
|
|
167
|
+
}
|
|
168
|
+
if (!sourceHashData) {
|
|
169
|
+
alert(`CFCA计算HASH值失败!( ${data.bean.msg || ''})`)
|
|
170
|
+
return false
|
|
171
|
+
}
|
|
172
|
+
// 将原文Hash值的Base64编码解码后,对其进行PKCS#7分离式签名
|
|
173
|
+
return this.CryptoAgent.SignHashMsgPKCS7Detached(sourceHashData, 'SHA-1')
|
|
174
|
+
.then((response) => ({
|
|
175
|
+
signature: response.result,
|
|
176
|
+
id: data.bean.id,
|
|
177
|
+
}))
|
|
178
|
+
.catch((response) => {
|
|
179
|
+
alert(response);
|
|
180
|
+
return false;
|
|
181
|
+
});
|
|
182
|
+
},
|
|
183
|
+
async signFileKeyImage(item, fileItem, image) {
|
|
184
|
+
const res = await this.getSignHashValue(item, fileItem, image)
|
|
185
|
+
let errorMsg = '计算Hash 失败!'
|
|
186
|
+
if (res) {
|
|
187
|
+
const { data, code } = await this.api.mergeHash({
|
|
188
|
+
jsonData: {
|
|
189
|
+
source: 'TTDFUND',
|
|
190
|
+
timestamp: new Date().getTime(),
|
|
191
|
+
msgBody: {
|
|
192
|
+
sigString: res.signature, // 签名后的hash值
|
|
193
|
+
id: res.id, // 计算接口返回的ID
|
|
194
|
+
},
|
|
195
|
+
},
|
|
196
|
+
})
|
|
197
|
+
// 此方法 code 不能完全说明正确,调用失败code 也是0
|
|
198
|
+
if (code === 0) {
|
|
199
|
+
if (data.bean.url) {
|
|
200
|
+
return data.bean
|
|
201
|
+
}
|
|
202
|
+
errorMsg = data.bean.msg
|
|
203
|
+
} else {
|
|
204
|
+
errorMsg = data.msg
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
this.$message.error(errorMsg || 'error计算Hash失败!')
|
|
208
|
+
return false
|
|
209
|
+
},
|
|
210
|
+
// fileOss: 为文件对象 {obje}
|
|
211
|
+
// isOffset: 修正印章的位置,印章加时间后需要向下修正
|
|
212
|
+
async multipleSign(labels, fileOss, serialNo, image, isOffset = 18) {
|
|
213
|
+
const serialNoBegin = await this.GetCertInfoOnClick('SerialNumber');
|
|
214
|
+
let result = ''
|
|
215
|
+
if (!image) {
|
|
216
|
+
alert('印章图片缺失!')
|
|
217
|
+
return false
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
for (let index = 0; index < labels.length; index++) {
|
|
221
|
+
const item = getUrl(labels[index])
|
|
222
|
+
// 此处for循环多个文件时候以前签署,所以提示无意义
|
|
223
|
+
// const message = `签署 [${text}] 位于第${label.pageIndex}页的位置,[总共:${index + 1}/${labels.length}个位置]`
|
|
224
|
+
if (typeof isOffset === 'number') {
|
|
225
|
+
// 印章统一向下偏移
|
|
226
|
+
item.Y -= isOffset
|
|
227
|
+
}
|
|
228
|
+
if (index > 0) {
|
|
229
|
+
const serialNoAgain = await this.GetCertInfoOnClick('SerialNumber');
|
|
230
|
+
if (serialNoBegin !== serialNoAgain) {
|
|
231
|
+
alert('签署过程中,请不要更换ukey!')
|
|
232
|
+
return false
|
|
233
|
+
}
|
|
234
|
+
// 这里签署第二个章,需要在第一个签好的文件上签署 所以用result中是文件
|
|
235
|
+
if (result) {
|
|
236
|
+
// eslint-disable-next-line
|
|
237
|
+
result = await this.signFileKeyImage((item), result, image)
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
console.log(`iterateSign 签章结果${index}---result----`, result)
|
|
241
|
+
} else {
|
|
242
|
+
// eslint-disable-next-line
|
|
243
|
+
result = await this.signFileKeyImage((item), fileOss, image)
|
|
244
|
+
console.log('第一个章 签章结果', result)
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
console.log('multipleSign 签章的结果', result)
|
|
248
|
+
return result
|
|
249
|
+
},
|
|
250
|
+
},
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
</script>
|
|
254
|
+
<style lang="less" scoped>
|
|
255
|
+
.CryptoAgent-wrapper {
|
|
256
|
+
height: 0;
|
|
257
|
+
width: 0;
|
|
258
|
+
position: absolute;
|
|
259
|
+
left: -5000px;
|
|
260
|
+
}
|
|
261
|
+
</style>>
|