@toolspack/ttd-common 1.1.4 → 1.1.5

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.
@@ -1,170 +1,170 @@
1
- <!--本插件制作验签用-->
2
- <template>
3
- <div class="CryptoAgent-wrapper">
4
- <template v-if="isIE">
5
- <!-- id="CryptoAgent" -->
6
- <object ref="CryptoAgent" :codebase="publicPath + codebase" :classid="classid"></object>
7
- </template>
8
- <template v-else>
9
- <embed
10
- ref="CryptoAgent"
11
- type="application/npCryptoKit.Ultimate.x86"
12
- style="height: 0px; width: 0px"
13
- />
14
- </template>
15
- </div>
16
- </template>
17
- <script>
18
- /* ukey 签章
19
- * cfca 有2中签章方式: 1 消息验签,2 文件验签, 我们使用的是消息验签的方式
20
- * 下面是 签章 的公用方法,通过mixin 使用
21
- *
22
- * */
23
-
24
- // 消息签名, 生成Base64 编码的 PKCS#7 签名结果
25
- function SignOnClick() {
26
- let errorDesc = ''
27
- this.sourceData = `${new Date().getTime() }`
28
- try {
29
- const source = this.sourceData
30
- let signature = ''
31
- const signType = 'Attach' // 签名类型
32
- const selectedAlg = 'SHA-1' // 哈希算法(仅对RSA算法有效,SM2默认使用SM3哈希算法):
33
-
34
- if (signType === 'Attach') {
35
- // PKCS#7 Attach
36
- signature = this.CryptoAgent.SignMsgPKCS7(source, selectedAlg, true)
37
- } else if (signType === 'Detach') {
38
- // PKCS#7 Detach
39
- signature = this.CryptoAgent.SignMsgPKCS7(source, selectedAlg, false)
40
- } else {
41
- // PKCS#1
42
- signature = this.CryptoAgent.SignMsgPKCS1(source, selectedAlg)
43
- }
44
- if (!signature) {
45
- errorDesc = this.CryptoAgent.GetLastErrorDesc()
46
- alert(errorDesc)
47
- return ''
48
- }
49
- console.log('SignOnClick 签名结果:', signature)
50
- return signature
51
- } catch (e) {
52
- console.log('SignOnClick error=', e)
53
- errorDesc = this.CryptoAgent.GetLastErrorDesc()
54
- alert(errorDesc)
55
- }
56
- return ''
57
- }
58
-
59
- export default {
60
- name: 'ukey',
61
- data() {
62
- let codebase = ''
63
- let classid = ''
64
- if (window.navigator.cpuClass === 'x86') {
65
- codebase = 'ukey/Cryptokit/x86/CryptoKit.ToToDi.x86.cab'
66
- classid = 'clsid:5635B01D-C661-4ACE-B997-EECFA63BD388'
67
- } else {
68
- codebase = 'ukey/Cryptokit/x64/CryptoKit.ToToDi.x64.cab'
69
- classid = 'clsid:63F9892E-D854-476E-A839-C8BA79254EC1'
70
- }
71
- return {
72
- isIE: navigator.appName.indexOf('Internet') >= 0 || navigator.appVersion.indexOf('Trident') >= 0,
73
- publicPath: 'https://wsp.totodi.com/jz/', // 为了获取public下的静态文件
74
- codebase,
75
- classid,
76
- sourceData: '', // 签名原文, 动态随机字符串
77
- certType: 'RSA', // 签名算法
78
- hashAlg: 'SHA-1',
79
- singType: 'Detach',
80
- CryptoAgent: '',
81
- random: 'ttd',
82
- }
83
- },
84
- mounted() {
85
- this.onLoad()
86
- },
87
- methods: {
88
- /**
89
- * 初始化验签工具包,加载 验签空间(object)
90
- */
91
- onLoad() {
92
- if (this.CryptoAgent) {
93
- return false
94
- }
95
- if (this.isIE) {
96
- // 使用refs 拿到的元素 不能ukey签章
97
- // this.CryptoAgent = document.getElementById('CryptoAgent')
98
- this.CryptoAgent = this.$refs.CryptoAgent
99
- if (!this.CryptoAgent) {
100
- alert('验签插件加载失败!')
101
- }
102
- console.log('加载this.CryptoAgent ', this.CryptoAgent)
103
- } else {
104
- // alert('请使用IE浏览器验签!')
105
- return false
106
- }
107
- },
108
- SignOnClick,
109
- // 筛选证书
110
- SelectCertificateOnClick(serialNo) {
111
- if (!this.isIE) {
112
- alert('请使用IE浏览器!')
113
- }
114
- try {
115
- const subjectDNFilter = ''
116
- const issuerDNFilter = 'CFCA ACS '
117
- // 此处获取SerialNumber 会报错
118
- const serialNumFilter = serialNo;// this.GetSignCertInfoUkey('SerialNumber');
119
-
120
- if (!serialNumFilter) {
121
- console.log(' Ukye, 无序列号筛选证书, serialNo 非必传 ')
122
- }
123
- let bSelectCertResult = ''
124
- let errorDesc = ''
125
- const csp = 'Uyee CSP v6.0 (Enterprise)||CFCA FOR UKEY CSP v1.1.0'
126
- // SelectCertificate 通过传入的字符串作为 DN 的筛选条件,选择出符合 DN 条件的带私钥的SM2/RSA 签名证书。如果筛选字符串为空,则对相应条件不进行筛选
127
- bSelectCertResult = this.CryptoAgent.SelectCertificate(subjectDNFilter, issuerDNFilter, serialNumFilter, csp)
128
- if (!bSelectCertResult) {
129
- errorDesc = this.CryptoAgent.GetLastErrorDesc()
130
- alert(errorDesc)
131
- }
132
- return bSelectCertResult
133
- } catch (e) {
134
- console.log('SelectCertificateOnClick catch', e)
135
- const errorDescE = this.CryptoAgent.GetLastErrorDesc();
136
- alert(`${errorDescE }/error`);
137
- return false
138
- }
139
- },
140
- GetSignCertInfoUkey(InfoTypeID) {
141
- // 有时候获取不到数据
142
- InfoTypeID = InfoTypeID || 'SubjectDN'
143
- console.log('-Ukey-GetSignCertInfoUkey:InfoTypeID ', InfoTypeID)
144
- try {
145
- const InfoContent = this.CryptoAgent.GetSignCertInfo(InfoTypeID)
146
- // Opera浏览器,NPAPI函数执行结果为false时,不能触发异常,需要自己判断返回值。
147
- if (!InfoContent) {
148
- const errorDesc = this.CryptoAgent.GetLastErrorDesc()
149
- alert(errorDesc)
150
- return
151
- }
152
- return InfoContent
153
- } catch (e) {
154
- console.log('GetSignCertInfoUkey-Ukey: ', e)
155
- const errorDesc = this.CryptoAgent.GetLastErrorDesc()
156
- alert(errorDesc)
157
- }
158
- },
159
- },
160
- }
161
-
162
- </script>
163
- <style lang="less" scoped>
164
- .CryptoAgent-wrapper {
165
- height: 0;
166
- width: 0;
167
- position: absoute;
168
- left: -5000px;
169
- }
170
- </style>
1
+ <!--本插件制作验签用-->
2
+ <template>
3
+ <div class="CryptoAgent-wrapper">
4
+ <template v-if="isIE">
5
+ <!-- id="CryptoAgent" -->
6
+ <object ref="CryptoAgent" :codebase="publicPath + codebase" :classid="classid"></object>
7
+ </template>
8
+ <template v-else>
9
+ <embed
10
+ ref="CryptoAgent"
11
+ type="application/npCryptoKit.Ultimate.x86"
12
+ style="height: 0px; width: 0px"
13
+ />
14
+ </template>
15
+ </div>
16
+ </template>
17
+ <script>
18
+ /* ukey 签章
19
+ * cfca 有2中签章方式: 1 消息验签,2 文件验签, 我们使用的是消息验签的方式
20
+ * 下面是 签章 的公用方法,通过mixin 使用
21
+ *
22
+ * */
23
+
24
+ // 消息签名, 生成Base64 编码的 PKCS#7 签名结果
25
+ function SignOnClick() {
26
+ let errorDesc = ''
27
+ this.sourceData = `${new Date().getTime() }`
28
+ try {
29
+ const source = this.sourceData
30
+ let signature = ''
31
+ const signType = 'Attach' // 签名类型
32
+ const selectedAlg = 'SHA-1' // 哈希算法(仅对RSA算法有效,SM2默认使用SM3哈希算法):
33
+
34
+ if (signType === 'Attach') {
35
+ // PKCS#7 Attach
36
+ signature = this.CryptoAgent.SignMsgPKCS7(source, selectedAlg, true)
37
+ } else if (signType === 'Detach') {
38
+ // PKCS#7 Detach
39
+ signature = this.CryptoAgent.SignMsgPKCS7(source, selectedAlg, false)
40
+ } else {
41
+ // PKCS#1
42
+ signature = this.CryptoAgent.SignMsgPKCS1(source, selectedAlg)
43
+ }
44
+ if (!signature) {
45
+ errorDesc = this.CryptoAgent.GetLastErrorDesc()
46
+ alert(errorDesc)
47
+ return ''
48
+ }
49
+ console.log('SignOnClick 签名结果:', signature)
50
+ return signature
51
+ } catch (e) {
52
+ console.log('SignOnClick error=', e)
53
+ errorDesc = this.CryptoAgent.GetLastErrorDesc()
54
+ alert(errorDesc)
55
+ }
56
+ return ''
57
+ }
58
+
59
+ export default {
60
+ name: 'ukey',
61
+ data() {
62
+ let codebase = ''
63
+ let classid = ''
64
+ if (window.navigator.cpuClass === 'x86') {
65
+ codebase = 'ukey/Cryptokit/x86/CryptoKit.ToToDi.x86.cab'
66
+ classid = 'clsid:5635B01D-C661-4ACE-B997-EECFA63BD388'
67
+ } else {
68
+ codebase = 'ukey/Cryptokit/x64/CryptoKit.ToToDi.x64.cab'
69
+ classid = 'clsid:63F9892E-D854-476E-A839-C8BA79254EC1'
70
+ }
71
+ return {
72
+ isIE: navigator.appName.indexOf('Internet') >= 0 || navigator.appVersion.indexOf('Trident') >= 0,
73
+ publicPath: 'https://wsp.totodi.com/jz/', // 为了获取public下的静态文件
74
+ codebase,
75
+ classid,
76
+ sourceData: '', // 签名原文, 动态随机字符串
77
+ certType: 'RSA', // 签名算法
78
+ hashAlg: 'SHA-1',
79
+ singType: 'Detach',
80
+ CryptoAgent: '',
81
+ random: 'ttd',
82
+ }
83
+ },
84
+ mounted() {
85
+ this.onLoad()
86
+ },
87
+ methods: {
88
+ /**
89
+ * 初始化验签工具包,加载 验签空间(object)
90
+ */
91
+ onLoad() {
92
+ if (this.CryptoAgent) {
93
+ return false
94
+ }
95
+ if (this.isIE) {
96
+ // 使用refs 拿到的元素 不能ukey签章
97
+ // this.CryptoAgent = document.getElementById('CryptoAgent')
98
+ this.CryptoAgent = this.$refs.CryptoAgent
99
+ if (!this.CryptoAgent) {
100
+ alert('验签插件加载失败!')
101
+ }
102
+ console.log('加载this.CryptoAgent ', this.CryptoAgent)
103
+ } else {
104
+ // alert('请使用IE浏览器验签!')
105
+ return false
106
+ }
107
+ },
108
+ SignOnClick,
109
+ // 筛选证书
110
+ SelectCertificateOnClick(serialNo) {
111
+ if (!this.isIE) {
112
+ alert('请使用IE浏览器!')
113
+ }
114
+ try {
115
+ const subjectDNFilter = ''
116
+ const issuerDNFilter = 'CFCA ACS '
117
+ // 此处获取SerialNumber 会报错
118
+ const serialNumFilter = serialNo;// this.GetSignCertInfoUkey('SerialNumber');
119
+
120
+ if (!serialNumFilter) {
121
+ console.log(' Ukye, 无序列号筛选证书, serialNo 非必传 ')
122
+ }
123
+ let bSelectCertResult = ''
124
+ let errorDesc = ''
125
+ const csp = 'Uyee CSP v6.0 (Enterprise)||CFCA FOR UKEY CSP v1.1.0'
126
+ // SelectCertificate 通过传入的字符串作为 DN 的筛选条件,选择出符合 DN 条件的带私钥的SM2/RSA 签名证书。如果筛选字符串为空,则对相应条件不进行筛选
127
+ bSelectCertResult = this.CryptoAgent.SelectCertificate(subjectDNFilter, issuerDNFilter, serialNumFilter, csp)
128
+ if (!bSelectCertResult) {
129
+ errorDesc = this.CryptoAgent.GetLastErrorDesc()
130
+ alert(errorDesc)
131
+ }
132
+ return bSelectCertResult
133
+ } catch (e) {
134
+ console.log('SelectCertificateOnClick catch', e)
135
+ const errorDescE = this.CryptoAgent.GetLastErrorDesc();
136
+ alert(`${errorDescE }/error`);
137
+ return false
138
+ }
139
+ },
140
+ GetSignCertInfoUkey(InfoTypeID) {
141
+ // 有时候获取不到数据
142
+ InfoTypeID = InfoTypeID || 'SubjectDN'
143
+ console.log('-Ukey-GetSignCertInfoUkey:InfoTypeID ', InfoTypeID)
144
+ try {
145
+ const InfoContent = this.CryptoAgent.GetSignCertInfo(InfoTypeID)
146
+ // Opera浏览器,NPAPI函数执行结果为false时,不能触发异常,需要自己判断返回值。
147
+ if (!InfoContent) {
148
+ const errorDesc = this.CryptoAgent.GetLastErrorDesc()
149
+ alert(errorDesc)
150
+ return
151
+ }
152
+ return InfoContent
153
+ } catch (e) {
154
+ console.log('GetSignCertInfoUkey-Ukey: ', e)
155
+ const errorDesc = this.CryptoAgent.GetLastErrorDesc()
156
+ alert(errorDesc)
157
+ }
158
+ },
159
+ },
160
+ }
161
+
162
+ </script>
163
+ <style lang="less" scoped>
164
+ .CryptoAgent-wrapper {
165
+ height: 0;
166
+ width: 0;
167
+ position: absoute;
168
+ left: -5000px;
169
+ }
170
+ </style>