appPackage.js 91 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971
  1. function utf8_to_b64(str) {
  2. return window.btoa(unescape(encodeURIComponent(str)));
  3. }
  4. function b64_to_utf8(str) {
  5. return decodeURIComponent(escape(window.atob(str)));
  6. }
  7. //////////////工具函数///////////////////
  8. function JsonToTable(json) {
  9. for (var key in json) {
  10. }
  11. }
  12. function toggleVisible(dom) {
  13. toggleClassName(dom.parentElement.getElementsByTagName('table')[0], 'hide');
  14. }
  15. //移除类名
  16. function removeClass(dom, className) {
  17. var temp = dom.className.split(' ');
  18. dom.className = ""
  19. for (var index in temp) {
  20. if (temp[index] != className) {
  21. dom.className += (temp[index] + ' ');
  22. }
  23. }
  24. }
  25. //添加类名
  26. function addClass(dom, className) {
  27. if (dom.className != "") {
  28. if (!hasClass(dom, className)) {
  29. dom.className += (' ' + className);
  30. }
  31. } else {
  32. dom.className = className;
  33. }
  34. }
  35. //是否含有此类名
  36. function hasClass(dom, className) {
  37. var classNames = dom.className.split(' ');
  38. for (var index in classNames) {
  39. if (classNames[index] == className) {
  40. return true;
  41. }
  42. }
  43. return false;
  44. }
  45. function toggleClassName(dom, className) {
  46. if (hasClass(dom, className)) {
  47. removeClass(dom, className);
  48. } else {
  49. addClass(dom, className);
  50. }
  51. }
  52. function toggleBlock(className, showElementId) {
  53. var collection = document.getElementsByTagName('*');
  54. for (var index = 0; index < collection.length; index++) {
  55. if (hasClass(collection[index], className)) {
  56. addClass(collection[index], 'hide');
  57. }
  58. }
  59. var showElement = document.getElementById(showElementId);
  60. removeClass(showElement, 'hide');
  61. }
  62. function formatPrint(outValue){
  63. if(outValue == null || outValue == undefined || outValue.length == 0)
  64. return "null";
  65. else
  66. return outValue;
  67. }
  68. function checkServiceOK()
  69. {
  70. var NETCA_ERROR_WEBSOCKETCONNECTFAIL=-11000;
  71. var params ={};
  72. NetcaPKI.checkPKIInstall(params)
  73. .Then(function(res)
  74. {
  75. SuccessService(res);
  76. })
  77. .Catch(function (res)
  78. {
  79. //连接失败 返回错误
  80. FailedService(res);
  81. });
  82. }
  83. function SuccessService(res)
  84. {
  85. checkVersion();
  86. }
  87. function FailedService(res)
  88. {
  89. alert(res.msg);
  90. }
  91. function getNetcaKeyId(certObj) {
  92. //绑定值顺序 2019-8-1
  93. //证书客户服务号(23)->证书实体唯一标识(36)->绑定姆印(1);*/
  94. if (certObj.userCertServiceId != null && certObj.userCertServiceId.length != 0) {
  95. return certObj.userCertServiceId;
  96. }
  97. else if (certObj.netcaSubjectUniqueId != null && certObj.netcaSubjectUniqueId.length != 0) {
  98. return certObj.netcaSubjectUniqueId;
  99. }
  100. else {
  101. return certObj.Thumbprint;
  102. }
  103. }
  104. function getCertListSuccess(res)
  105. {
  106. if (res && res.deviceCount === 0) {
  107. toastr.error('请插入UKey获取证书');
  108. return;
  109. } else if (res.deviceCount === 1) {
  110. toastr.success('获取证书信息成功');
  111. const cert = res.certInfo[0];
  112. const tip = "证书主题:"+cert.subjectCN+",keyId:"+getNetcaKeyId(cert)+"\n";
  113. // for( s = 0; s < res.certCount; ++s)
  114. // {
  115. // const cert = res.certInfo[s];
  116. // tip += "证书主题:"+cert.subjectCN+",keyId:"+getNetcaKeyId(cert)+"\n";
  117. // }
  118. DeviceOutputId.value = tip;
  119. $('#name').val(cert.subjectCN);
  120. $('#keyId').val(getNetcaKeyId(cert));
  121. } else if (res.deviceCount === 2) {
  122. toastr.error('请拔出多个UKey,保留一个并设置绑定');
  123. return;
  124. } else {
  125. toastr.error('获取证书失败');
  126. }
  127. }
  128. function getCertListFail(res)
  129. {
  130. // alert("获取证书列表成功\n" + res.msg);
  131. $('#netcasign-drive').modal('show');
  132. }
  133. function getCertList()
  134. {
  135. var params={};
  136. NetcaPKI.GetCertList(params)
  137. .Then(function(res){
  138. getCertListSuccess(res);
  139. })
  140. .Catch(function (res) {
  141. getCertListFail(res);
  142. });
  143. }
  144. function DoClearPwdCache() {
  145. var params = {};
  146. NetcaPKI.clearPwdCache(params)
  147. .Then(function (res) {
  148. alert("清除密码缓存成功");
  149. })
  150. .Catch(function (res) {
  151. alert(res.msg);
  152. });
  153. }
  154. function publicKeyEncrypt()
  155. {
  156. var selectType = "Device";
  157. var selectCondition = "CertType='Encrypt'";
  158. switch (publicKeyEncSelectOp.value)
  159. {
  160. case 'pubkeyEnc_op1':
  161. var params = {
  162. cert: { //证书(CertificateParams)
  163. type: selectType,
  164. condition: selectCondition
  165. },
  166. data: { //数据(DataParams)
  167. fileName: publicKeyEncFile.value
  168. }
  169. }
  170. NetcaPKI.publicKeyEncrypt(params)
  171. .Then(function (res) {
  172. SuccessPublicKeyEncryptFileCallBack(res);
  173. })
  174. .Catch(function (res) {
  175. FailedPublicKeyEncryptFileCallBack(res);
  176. })
  177. break;
  178. case 'pubkeyEnc_op2':
  179. var params = {
  180. cert: { //证书(CertificateParams)
  181. type: selectType,
  182. condition: selectCondition
  183. },
  184. data: { //数据(DataParams)
  185. text: utf8_to_b64(publicKeyEncClearText.value)
  186. }};
  187. NetcaPKI.publicKeyEncrypt(params)
  188. .Then(function (res) {
  189. SuccessPublicKeyEncryptFileCallBack(res);
  190. })
  191. .Catch(function (res) {
  192. FailedPublicKeyEncryptFileCallBack(res);
  193. })
  194. break;
  195. }
  196. }
  197. function SuccessPublicKeyEncryptFileCallBack(res)
  198. {
  199. publicKeyEncResult.value =res.encryptValue;
  200. lastPublicKeyEncResult.value = res.encryptValue;
  201. }
  202. function FailedPublicKeyEncryptFileCallBack(res)
  203. {
  204. alert("公钥加密失败\n" + res.msg);
  205. }
  206. function privateKeyDecrypt()
  207. {
  208. var selectType = "Device";
  209. var selectCondition = "CertType='Encrypt'";
  210. var cipherData=lastPublicKeyEncResult.value;
  211. savefile=null;
  212. if(publicKeyDecryptFile.value.length > 0)
  213. {
  214. savefile=publicKeyDecryptFile.value;
  215. }
  216. var params = {
  217. cert: {
  218. type: selectType,
  219. condition: selectCondition
  220. },
  221. // algo: 0, //非对称加密算法
  222. encData: cipherData,
  223. savefileName:savefile
  224. };
  225. NetcaPKI.privateKeyDecrypt(params)
  226. .Then(function (res) {
  227. SuccessPrivateKeyDecryptCallBack(res);
  228. })
  229. .Catch(function (res) {
  230. FailedPrivateKeyDecryptCallBack(res);
  231. })
  232. }
  233. function SuccessPrivateKeyDecryptCallBack(res)
  234. {
  235. if( res.clearEncodeType == "base64" )
  236. {
  237. privateKeyDecResult.value = b64_to_utf8(res.clearValue);
  238. }
  239. else if( res.clearEncodeType == "file" )
  240. {
  241. privateKeyDecResult.value = "文件解密成功,明文文件路径:\n " + savefile;
  242. }
  243. }
  244. function FailedPrivateKeyDecryptCallBack(res)
  245. {
  246. alert("解密失败\n" + res.msg);
  247. }
  248. //PKCS#1 签名
  249. function SuccessSignCallBack(res)
  250. {
  251. p1SignResult.value = "P1签名成功,签名值:\n" + res.signValue;
  252. lastP1SignResult.value = res.signValue;
  253. }
  254. function FailedSignCallBack(res)
  255. {
  256. if (res.netcaCryptoCode != null && res.netcaCryptoCode == -54)
  257. {
  258. alert("P1签名失败\n" + res.msg + ":请确认签名算法和密钥是否匹配!");
  259. return;
  260. }
  261. alert("P1签名失败\n" + res.msg);
  262. }
  263. function signSample()
  264. {
  265. var certEncode = "";
  266. var selectType = "Device";
  267. var selectCondition = "InValidity='True' && CertType='Signature'";
  268. var origindata= utf8_to_b64(p1SignClearText.value);
  269. var signAlgo = parseInt(P1SignAlgo.value);
  270. var params = {
  271. cert: {
  272. "encode": certEncode,
  273. "type": selectType,
  274. "condition": selectCondition
  275. },
  276. data: {
  277. text: origindata
  278. },
  279. algo: signAlgo
  280. };
  281. NetcaPKI.sign(params)
  282. .Then(function (res) {
  283. SuccessSignCallBack(res);
  284. })
  285. .Catch(function (res) {
  286. FailedSignCallBack(res);
  287. });
  288. }
  289. function SuccessSignVerifyCallBack(res) {
  290. alert("p1验证签名成功\n" + res.certObject.certCode);
  291. }
  292. function FailedSignVerifyCallBack(res) {
  293. if (res.netcaCryptoCode != null && res.netcaCryptoCode == -54) {
  294. alert("P1验证签名失败\n" + res.msg + ":请确认签名算法和密钥是否匹配!");
  295. return;
  296. }
  297. alert("P1验证签名失败\n" + res.msg);
  298. }
  299. function signVerifyTest()
  300. {
  301. var certEncode = "";
  302. var selectType = "Device";
  303. var selectCondition = "InValidity='True' && CertType='Signature'";
  304. var origindata = utf8_to_b64(lastP1SignClearText.value);
  305. var signAlgo = parseInt(P1VerifySignAlgo.value);
  306. var signValue = lastP1SignResult.value;
  307. var params = {
  308. cert: {
  309. "encode": certEncode,
  310. "type": selectType,
  311. "condition": selectCondition
  312. },
  313. data: {
  314. text: origindata
  315. },
  316. signature:signValue,
  317. algo: signAlgo
  318. };
  319. NetcaPKI.verifySignature(params)
  320. .Then(function (res) {
  321. SuccessSignVerifyCallBack(res);
  322. })
  323. .Catch(function (res) {
  324. FailedSignVerifyCallBack(res);
  325. });
  326. }
  327. function signedDataSign() {
  328. var certEncode = "";
  329. var selectType = "Device";
  330. var selectCondition = "InValidity='True' && CertType='Signature'";
  331. var _certPwd = CertPwd.value;
  332. var tbs = utf8_to_b64(SignedDataTBS.value);
  333. var _useSubjectKeyId = signedDataUseSubjectKeyId.value;
  334. var _useQ7 = false;
  335. var _detached = signedDataDetach.value;
  336. var _tsaURL = "http://tsa.cnca.net/NETCATimeStampServer/TSAServer.jsp";
  337. var _includeCertOption = 2;
  338. var params={};
  339. if(_certPwd=="")
  340. {
  341. params = {
  342. cert: { //证书(CertificateParams)
  343. encode: certEncode, //可选字段但不能为空
  344. type: selectType,
  345. condition: selectCondition
  346. },
  347. data: { //数据(DataParams)
  348. text: tbs
  349. },
  350. useSubjectKeyId: _useSubjectKeyId, //是否使用主体密钥标识符来标识证书,默认为true
  351. useQ7:_useQ7, //布尔值 是否使用国密Q7的方式,默认为false
  352. detached: parseInt(_detached),
  353. tsaURL: _tsaURL,
  354. includeCertOption: _includeCertOption//整数 包含证书的标识
  355. };
  356. }else
  357. {
  358. params = {
  359. cert: { //证书(CertificateParams)
  360. encode: certEncode, //可选字段但不能为空
  361. type: selectType,
  362. condition: selectCondition
  363. },
  364. data: { //数据(DataParams)
  365. text: tbs
  366. },
  367. useSubjectKeyId: _useSubjectKeyId, //是否使用主体密钥标识符来标识证书,默认为true
  368. useQ7:_useQ7, //布尔值 是否使用国密Q7的方式,默认为false
  369. detached: parseInt(_detached),
  370. tsaURL: _tsaURL,
  371. includeCertOption: _includeCertOption,//整数 包含证书的标识
  372. certPwd:_certPwd
  373. };
  374. }
  375. NetcaPKI.signedDataSign(params)
  376. .Then(function (res) {
  377. SuccessSignedDataSignCallBack(res);
  378. })
  379. .Catch(function (res) {
  380. FailedSignedDataSignCallBack(res);
  381. })
  382. }
  383. function SuccessSignedDataSignCallBack(res)
  384. {
  385. var retSignValue = res.signValue;
  386. //处理base填充问题,这里去掉Base64的填充内容
  387. if(retSignValue!=null&&retSignValue.length>2)
  388. {
  389. var paddingCount=0;
  390. if(retSignValue[retSignValue.length-1]=="=")
  391. {
  392. paddingCount++;
  393. }
  394. if(retSignValue[retSignValue.length-2]=="=")
  395. {
  396. paddingCount++;
  397. }
  398. if(paddingCount>0)
  399. {
  400. //裁剪后面的=号
  401. retSignValue=retSignValue.substring(0,retSignValue.length-paddingCount);
  402. }
  403. }
  404. if(res.result==-5||res.result==-81)
  405. {
  406. retSignValue = "失败\n密码错误,密码重试次数为:"+res.retrynum;
  407. }
  408. SignedDataPVAL.value = "SignedData签名成功,签名值为:\n"+retSignValue;
  409. SignedDataSignature.value = retSignValue;
  410. SignedDataGetInfoSignature.value = retSignValue;
  411. }
  412. function FailedSignedDataSignCallBack(res)
  413. {
  414. alert("SignedData签名失败\n" + res.msg);
  415. }
  416. function signedDataVerify()
  417. {
  418. var _verifyLevel=1;//默认为1
  419. var _signedData = SignedDataSignature.value;
  420. var tbs=null;
  421. if (SignedDataVerifyTBS.value.length > 0 && signedDataDetach.value == "1")
  422. {
  423. tbs=utf8_to_b64(SignedDataVerifyTBS.value);
  424. }
  425. var params = {
  426. verifyLevel: _verifyLevel, //验证级别,默认为验证签名本身,不验证证书,默认为1
  427. signedData: _signedData //signedData的编码值
  428. };
  429. if (tbs != null) {
  430. params.originData = {
  431. text: tbs
  432. };
  433. }
  434. NetcaPKI.signedDataVerify(params)
  435. .Then(function (res) {
  436. SuccessSignedDataVerifyCallBack(res);
  437. })
  438. .Catch(function (res) {
  439. FailedSignedDataVerifyCallBack(res);
  440. })
  441. }
  442. function SuccessSignedDataVerifyCallBack(res)
  443. {
  444. alert("验证签名成功" + JSON.stringify(res));
  445. }
  446. function FailedSignedDataVerifyCallBack(res)
  447. {
  448. alert("验证签名失败"+res.msg);
  449. }
  450. function envelopedDataEncrypt() {
  451. var certCode = "";
  452. var selectType = "Device";
  453. var selectCondition = "CertType='Encrypt'";
  454. var _algo = 0;
  455. var _useSubjectKeyId = (envelopedDataUseSubjectKeyId.value == 1) ? true : false;
  456. switch (EnvelopedDataEncryptSelectOp.value) {
  457. case 'EnvelopedDataEncrypt_op1':
  458. var params = {
  459. cert: { //证书(CertificateParams)
  460. encode: certCode,
  461. type: selectType,
  462. condition: selectCondition
  463. },
  464. algo : _algo, //对称加密算法,默认为128位的AES CBC模式
  465. data: {
  466. fileName: EnvelopedDataEncryptFile.value
  467. },
  468. useSubjectKeyId : _useSubjectKeyId
  469. };
  470. NetcaPKI.envelopedDataEncrypt(params)
  471. .Then(function (res) {
  472. SuccessEnvelopedDataEncryptCallBack(res);
  473. })
  474. .Catch(function (res) {
  475. FailedEnvelopedDataEncryptCallBack(res);
  476. })
  477. break;
  478. case 'EnvelopedDataEncrypt_op2':
  479. var params = {
  480. cert: { //证书(CertificateParams)
  481. encode: certCode,
  482. type: selectType,
  483. condition: selectCondition
  484. },
  485. algo : _algo, //对称加密算法,默认为128位的AES CBC模式
  486. data: {
  487. text: utf8_to_b64(EnvelopedDataEncryptClearText.value)
  488. }
  489. };
  490. NetcaPKI.envelopedDataEncrypt(params)
  491. .Then(function (res) {
  492. SuccessEnvelopedDataEncryptCallBack(res);
  493. })
  494. .Catch(function (res) {
  495. FailedEnvelopedDataEncryptCallBack(res);
  496. })
  497. break;
  498. }
  499. }
  500. function SuccessEnvelopedDataEncryptCallBack(res){
  501. EnvelopedDataEncryptPVAL.value = "数字信封加密成功,密文为:\n"+res.encryptValue;
  502. EnvelopedDataDecryptCipher.value = res.encryptValue;
  503. }
  504. function FailedEnvelopedDataEncryptCallBack(res)
  505. {
  506. alert("数字信封加密失败\n" + res.msg);
  507. }
  508. function envelopedDataDecrypt() {
  509. var _encData = EnvelopedDataDecryptCipher.value;
  510. var _saveFile=null;//解密后如果需要使用文件保存,传入的文件路径
  511. if(EnvelopedDataDecryptFile.value.length > 0)
  512. {
  513. _saveFile=EnvelopedDataDecryptFile.value;
  514. }
  515. var params = {
  516. encData: _encData, //要解密的数据
  517. savefileName:_saveFile
  518. };
  519. NetcaPKI.envelopedDataDecrypt(params)
  520. .Then(function (res) {
  521. SuccessEnvDecryptCallBack(res);
  522. })
  523. .Catch(function (res) {
  524. FailedEnvDecryptCallBack(res);
  525. })
  526. }
  527. function SuccessEnvDecryptCallBack(res)
  528. {
  529. if( res.clearEncodeType == "base64" )
  530. {
  531. EnvelopedDataDecryptClearText.value = b64_to_utf8(res.clearValue);
  532. }
  533. else if( res.clearEncodeType == "file" )
  534. {
  535. EnvelopedDataDecryptClearText.value = "文件解密成功,明文文件路径为 " + EnvelopedDataDecryptFile.value;
  536. }
  537. }
  538. function FailedEnvDecryptCallBack(res)
  539. {
  540. alert("解密失败 " + res.msg);
  541. }
  542. function AutoSignField() {
  543. var _hashAlgo = "SHA-256";//例如:“sha-1”,“sha-256”
  544. var _srcFile = src_path_for_field.value; //源pdf文件
  545. var _destFile = des_path_for_field.value;
  546. var _revInfoIncludeFlag=false; //签名时是否包含签名证书状态信息,true包含
  547. var _tsaURL= "";//时间戳地址
  548. var _tsaUsr= ""; //时间戳服务对应用户名
  549. var _tsaPwd= ""; //时间戳服务对应用户的密码
  550. var _tsaHashAlgo= ""; //时间戳使用的hash算法,例如”sha-1”,”sha-256”等
  551. var _allowCertType="";
  552. /**
  553. * allowCertType为NULL或者ANY表示不进行限制。
  554. * RSA为RSA类型,SM2为SM2类型,ECC为ECC类型包括SM2,ECC!SM2为不包括SM2的ECC类型。
  555. * RSA:SM2为既包括RSA也包括SM2。
  556. * 默认支持RSA,SM2类型的证书。
  557. * 中间件 5.2版本新增的
  558. */
  559. var _selMode= select_mode.value == "0" ? 0 : 1; //选择模式,有两种:按证书选择(0)和按印章选择(1)
  560. var _fieldName = pdfsign_field.value;//要进行签名的签名域名称
  561. var params = {
  562. hashAlgo: _hashAlgo, //例如:“sha-1”,“sha-256”
  563. srcFile: _srcFile, //源pdf文件
  564. destFile: _destFile, //源pdf文件
  565. revInfoIncludeFlag: _revInfoIncludeFlag, //签名时是否包含签名证书状态信息,true包含
  566. selMode: _selMode, //选择模式,有两种:按证书选择(0)和按印章选择(1)
  567. tsaURL: _tsaURL, //时间戳地址
  568. tsaUsr: _tsaUsr, //时间戳服务对应用户名
  569. tsaPwd:_tsaPwd, //时间戳服务对应用户的密码
  570. tsaHashAlgo: _tsaHashAlgo, //时间戳使用的hash算法,例如”sha-1”,”sha-256”等
  571. allowCertType: _allowCertType,
  572. /**
  573. * allowCertType为NULL或者ANY表示不进行限制。
  574. * RSA为RSA类型,SM2为SM2类型,ECC为ECC类型包括SM2,ECC!SM2为不包括SM2的ECC类型。
  575. * RSA:SM2为既包括RSA也包括SM2。
  576. * 默认支持RSA,SM2类型的证书。
  577. * 中间件 5.2版本新增的
  578. */
  579. signField: {
  580. fieldName: _fieldName //要进行签名的签名域名称
  581. }
  582. };
  583. NetcaPKI.pdfAutoSign(params)
  584. .Then(function (res) {
  585. SignSuccessCallBack();
  586. })
  587. .Catch(function (res) {
  588. SignFailedCallBack(res);
  589. });
  590. }
  591. function AutoSignPosition() {
  592. var _hashAlgo = "SHA-256";//例如:“sha-1”,“sha-256”
  593. var _srcFile = src_path_for_position.value; //源pdf文件
  594. var _destFile = des_path_for_position.value;
  595. var _revInfoIncludeFlag=false; //签名时是否包含签名证书状态信息,true包含
  596. var _tsaURL= "";//时间戳地址
  597. var _tsaUsr= ""; //时间戳服务对应用户名
  598. var _tsaPwd= ""; //时间戳服务对应用户的密码
  599. var _tsaHashAlgo= ""; //时间戳使用的hash算法,例如”sha-1”,”sha-256”等
  600. var _allowCertType="";
  601. /**
  602. * allowCertType为NULL或者ANY表示不进行限制。
  603. * RSA为RSA类型,SM2为SM2类型,ECC为ECC类型包括SM2,ECC!SM2为不包括SM2的ECC类型。
  604. * RSA:SM2为既包括RSA也包括SM2。
  605. * 默认支持RSA,SM2类型的证书。
  606. * 中间件 5.2版本新增的
  607. */
  608. var _selMode= select_mode.value == "0" ? 0 : 1; //选择模式,有两种:按证书选择(0)和按印章选择(1)
  609. var _pageNum= parseInt(pdfSign_pageNumber.value); //输入参数,整型,PDF文档的页码,页码从1开始计算。
  610. var _xPos= parseInt(pdfSign_xpos.value); //输入参数,整型,签章左下角的水平向右方向坐标。
  611. var _yPos=parseInt(pdfSign_ypos.value); //输入参数,整型,签章左下角的垂直向上方向坐标。
  612. var _width= parseInt(pdfSign_seal_width.value); //输入参数,整型,签章的宽度。
  613. var _height=parseInt(pdfSign_seal_height.value) ;//输入参数,整型,签章的高度。
  614. var params = {
  615. hashAlgo: _hashAlgo, //例如:“sha-1”,“sha-256”
  616. srcFile: _srcFile, //源pdf文件
  617. destFile: _destFile, //源pdf文件
  618. revInfoIncludeFlag: _revInfoIncludeFlag, //签名时是否包含签名证书状态信息,true包含
  619. selMode: _selMode, //选择模式,有两种:按证书选择(0)和按印章选择(1)
  620. tsaURL: _tsaURL, //时间戳地址
  621. tsaUsr: _tsaUsr, //时间戳服务对应用户名
  622. tsaPwd:_tsaPwd, //时间戳服务对应用户的密码
  623. tsaHashAlgo: _tsaHashAlgo, //时间戳使用的hash算法,例如”sha-1”,”sha-256”等
  624. allowCertType: _allowCertType,
  625. /**
  626. * allowCertType为NULL或者ANY表示不进行限制。
  627. * RSA为RSA类型,SM2为SM2类型,ECC为ECC类型包括SM2,ECC!SM2为不包括SM2的ECC类型。
  628. * RSA:SM2为既包括RSA也包括SM2。
  629. * 默认支持RSA,SM2类型的证书。
  630. * 中间件 5.2版本新增的
  631. */
  632. signPosition: {
  633. pageNum: _pageNum, //输入参数,整型,PDF文档的页码,页码从1开始计算。
  634. xPos: _xPos, //输入参数,整型,签章左下角的水平向右方向坐标。
  635. yPos: _yPos, //输入参数,整型,签章左下角的垂直向上方向坐标。
  636. width: _width, //输入参数,整型,签章的宽度。
  637. height: _height //输入参数,整型,签章的高度。
  638. }
  639. };
  640. NetcaPKI.pdfAutoSign(params)
  641. .Then(function (res) {
  642. SignSuccessCallBack();
  643. })
  644. .Catch(function (res) {
  645. SignFailedCallBack(res);
  646. });
  647. }
  648. function SignSuccessCallBack()
  649. {
  650. alert("签章成功");
  651. }
  652. function SignFailedCallBack(res)
  653. {
  654. alert("签章失败 " + res.msg);
  655. }
  656. function getCertStringAttribute()
  657. {
  658. /* 从USBKey中选择NETCA 颁发的签名证书 */
  659. var certEncode = CertCodeText.value;
  660. var selectType = "";
  661. var selectCondition = "";
  662. var attId = parseInt(CertAttributeIdText.value);
  663. if( CertCodeText.value.length == 0 )
  664. {
  665. selectType = "Device";
  666. selectCondition = "IssuerCN~'NETCA' && InValidity='True' && CertType='Signature'";
  667. }
  668. var params = {
  669. cert: {
  670. "encode":certEncode,
  671. "type":selectType,
  672. "condition":selectCondition
  673. },
  674. id:attId
  675. };
  676. NetcaPKI.getCertStringAttribute(params)
  677. .Then(function(res){
  678. successGetCertStringAttributeCallBack(res);
  679. })
  680. .Catch(function (res) {
  681. failedGetCertStringAttributeCallBack(res);
  682. });
  683. }
  684. function successGetCertStringAttributeCallBack(res)
  685. {
  686. var idvalue="";
  687. if(CertAttributeIdText.value > 0 )
  688. idvalue = "id " + CertAttributeIdText.value + "对应的属性值为 " + formatPrint(res.value);
  689. CertCodeText.value = res.certCode;
  690. var tip = "证书解析成功\n" + idvalue +
  691. "\n公钥算法(1-RSA,2-DSA,3-DH,4-ECC)为 " + res.publicKeyAlgorithm +
  692. " 公钥类型(1-RSA,2-SM2,3-ECC)为 " + res.publicKeyType +
  693. " 公钥长度为 " + res.publicKeyBits +
  694. "\n颁发者为 " + formatPrint(res.issuer) +
  695. "\n颁发者C为 " + formatPrint(res.issuerC) +
  696. "\n颁发者ST为 " + formatPrint(res.issuerST) +
  697. "\n颁发者L为 " + formatPrint(res.issuerL) +
  698. "\n颁发者O为 " + formatPrint(res.issuerO) +
  699. "\n颁发者OU为 " + formatPrint(res.issuerOU) +
  700. "\n颁发者CN为 " + formatPrint(res.issuerCN) +
  701. "\n主体者C为 " + formatPrint(res.subjectC) +
  702. "\n主体ST为 " + formatPrint(res.subjectST) +
  703. "\n主体L为 " + formatPrint(res.subjectL) +
  704. "\n主体O为 " + formatPrint(res.subjectO) +
  705. "\n主体OU为 " + formatPrint(res.subjectOU) +
  706. "\n主体EMAIL为 " + formatPrint(res.subjectEmail) +
  707. "\n主体CN为 " + formatPrint(res.subjectCN) +
  708. "\n有效期开始时间为 " + formatPrint(res.validFromDate) +
  709. "\n有效期结束时间为 " + formatPrint(res.validToDate) +
  710. "\nHex编码的证书序列号为 " + formatPrint(res.serialNumber) +
  711. "\n密钥用法为 " + formatPrint(res.keyUsage) +
  712. "\n用户证书服务号为 " + formatPrint(res.userCertServiceId) +
  713. "\n证书类别为 " + formatPrint( res.certClassExtValue) +
  714. "\n深圳地标唯一标识为 " + formatPrint(res.shenzhenSubjectUniqueId) +
  715. "\nNETCA唯一标识为 " + formatPrint(res.netcaSubjectUniqueId)+
  716. "\n实施证书唯一标识 " + formatPrint(res.AppUsrCertNO);
  717. if(res.netcaIdentifyItemsCount==null||res.netcaIdentifyItemsCount==0)
  718. {
  719. tip+="\n个人身份标识扩展不存在";
  720. }
  721. else
  722. {
  723. tip+="\n个人身份标识编码个数: " + res.netcaIdentifyItemsCount;
  724. var i=0;
  725. for(i=0;i<res.netcaIdentifyItemsCount;++i)
  726. {
  727. tip+="\n个人身份标识编码值:"+res.netcaIdentifyItems[i];
  728. }
  729. }
  730. if(res.netcaEnterpriseidItemsCount==null||res.netcaEnterpriseidItemsCount==0)
  731. {
  732. tip+="\n企业机构身份标识扩展不存在";
  733. }
  734. else
  735. {
  736. tip+="\n企业机构身份标识编码个数: " + res.netcaEnterpriseidItemsCount;
  737. var i=0;
  738. for(i=0;i<res.netcaEnterpriseidItemsCount;++i)
  739. {
  740. tip+="\n企业机构身份标识编码值:"+res.netcaEnterpriseidItems[i];
  741. }
  742. }
  743. CertAttributeValue.value = tip;
  744. }
  745. function failedGetCertStringAttributeCallBack(res)
  746. {
  747. alert("失败\n" + res.msg);
  748. }
  749. function isInsertKey()
  750. {
  751. var _cert = CertCodeText.value;
  752. var _sn = keySN.value;
  753. var _type = parseInt(keyType.value);
  754. var params = {
  755. cert: {
  756. "encode":_cert
  757. },//可选,指定证书所在的Key是否插入
  758. sn:_sn, //可选
  759. type:_type //可选
  760. };
  761. NetcaPKI.isInsertKey(params)
  762. .Then(function(res){
  763. if (res.insertCount > 0)
  764. {
  765. InsertCallBack(res);
  766. }
  767. else
  768. {
  769. UnInsertCallBack(res);
  770. }
  771. })
  772. .Catch(function (res) {
  773. UnInsertCallBack(res);
  774. });
  775. }
  776. function InsertCallBack(res)
  777. {
  778. var tip = "检测是否插入key接口调用成功\n设备数量为 " + res.insertCount;
  779. for( s = 1; s <= res.insertCount; ++s)
  780. {
  781. var temp = "type" + s;
  782. tip += "\n设备" + s +"的类型为" + res[temp];
  783. var temp2 = "sn" + s;
  784. tip += " 序列号为 " + res[temp2];
  785. var temp3="retrynum"+s;
  786. tip += "密码重试次数为 " + res[temp3];
  787. if(s == 1 && keySN.value == "" && keyType.value == "")
  788. {
  789. keySN.value = res[temp2];
  790. keyType.value = res[temp];
  791. }
  792. }
  793. DeviceOutputId.value = tip;
  794. }
  795. function UnInsertCallBack(res)
  796. {
  797. if (res.insertCount == 0)
  798. DeviceOutputId.value = "检测是否插入key接口调用成功,没有发现符合条件的Key";
  799. else
  800. DeviceOutputId.value = res.msg;
  801. }
  802. function monitorDevice()
  803. {
  804. var _delayTime=0;//延迟时间,单位是毫秒,默认是0毫秒
  805. var params = {
  806. delayTime: _delayTime //延迟时间,默认为0毫秒
  807. };
  808. NetcaPKI.monitorDevice(params)
  809. .Then(function(res)
  810. {
  811. SuccessMonitorDeviceCallBack(res);
  812. })
  813. .Catch(function (res)
  814. {
  815. FailedMonitorDeviceCallBack(res);
  816. });
  817. }
  818. function SuccessMonitorDeviceCallBack(res)
  819. {
  820. if(res !=null)
  821. {
  822. var deviceType=res.type;
  823. var deviceStatus;
  824. var isPullOut=res.pullOut;
  825. deviceSn=res.sn;
  826. if(isPullOut==1)
  827. {
  828. deviceStatus="拔出";
  829. alert("设备序列号为:"+deviceSn+"\n设备类型为:"+deviceType+"\n设备状态为:"+deviceStatus);
  830. }
  831. else{
  832. deviceStatus="插入";
  833. alert("设备序列号为:"+deviceSn+"\n设备类型为:"+deviceType+"\n设备状态为:"+deviceStatus);
  834. }
  835. }
  836. }
  837. function FailedMonitorDeviceCallBack(res)
  838. {
  839. alert("失败\n"+res.msg);
  840. }
  841. function checkVersion()
  842. {
  843. var params ={};
  844. NetcaPKI.getVersionInfo(params)
  845. .Then(function(res)
  846. {
  847. SuccessGetVersionInfoCallBack(res);
  848. })
  849. .Catch(function (res)
  850. {
  851. FailedGetVersionInfoCallBack(res);
  852. });
  853. }
  854. function SuccessGetVersionInfoCallBack(res)
  855. {
  856. var versionInfo=res.VersionInfo;
  857. var version =res.Version;
  858. alert("网证通相关驱动已经成功安装\n版本号为:"+version+"\n版本号信息为:"+versionInfo+"\n版本UID为:"+res.UID);
  859. }
  860. function FailedGetVersionInfoCallBack(res)
  861. {
  862. alert("多浏览器应用插件相关文件回调失败\n" + res.msg);
  863. }
  864. function FailedGetCertOidCallBack(res) {
  865. alert("获取证书扩展项失败\n" + res.msg);
  866. }
  867. function SuccessGetCertOidCallBack(res) {
  868. if(res.isExist==0)
  869. {
  870. alert("获取证书扩展项成功,但证书没有对应的扩展项");
  871. return;
  872. }
  873. alert("获取证书扩展项成功\n"+ res.extensionValue);
  874. }
  875. function getCertOid() {
  876. var _encode = CertCodeText.value;
  877. var _selectType = "Device";
  878. var _condition = "CertType='Signature'&& InValidity='True'";
  879. var _oidstr = certOid.value;
  880. var _oidType = parseInt(certOidType.value);
  881. var params = {
  882. cert: {
  883. "encode":_encode,
  884. "type":_selectType,
  885. "condition":_condition
  886. },
  887. oidstr:_oidstr,
  888. type: _oidType
  889. };
  890. NetcaPKI.getCertStringExtensionValue(params)
  891. .Then(function (res) {
  892. SuccessGetCertOidCallBack(res);
  893. })
  894. .Catch(function (res) {
  895. FailedGetCertOidCallBack(res);
  896. });
  897. }
  898. function verifyPwd()
  899. {
  900. var _pwd = pwdId.value;
  901. var _encode = CertCodeText.value;
  902. var _sn = keySN.value;
  903. var _type = parseInt(keyType.value);
  904. var params = {
  905. pwd:_pwd,
  906. cert: {
  907. "encode":_encode
  908. },//可选,指定证书所在的Key是否插入
  909. sn:_sn, //可选
  910. type:_type //可选
  911. };
  912. NetcaPKI.verifyKeyPwd(params)
  913. .Then(function(res){
  914. if (res.result == 1)
  915. {
  916. verifySuccess(res);
  917. }
  918. else
  919. {
  920. verifyFailed(res);
  921. }
  922. })
  923. .Catch(function (res) {
  924. alert(res.msg);
  925. });
  926. }
  927. function verifySuccess(res)
  928. {
  929. var tip = "密码验证成功,验证的设备类型为 " + res.type +
  930. "; 验证的设备序列号为 " + res.sn
  931. + "; 密码剩余重试次数为 " + res.retrynum;
  932. DeviceOutputId.value = tip;
  933. }
  934. function verifyFailed(res)
  935. {
  936. var tip = "密码验证失败,错误码为" + res.result +
  937. "; 验证的设备类型为 " + res.type +
  938. "; 验证的设备序列号为 " + res.sn
  939. + "; 密码剩余重试次数为 " + res.retrynum;
  940. DeviceOutputId.value = tip;
  941. }
  942. function formatPrint(outValue){
  943. if(outValue == null || outValue == undefined || outValue.length == 0)
  944. return "null";
  945. else
  946. return outValue;
  947. }
  948. function getHardDeviceInformation()
  949. {
  950. var params ={};
  951. NetcaPKI.getHardDeviceInformation(params)
  952. .Then(function(res)
  953. {
  954. SuccessGetHardDeviceCallBack(res);
  955. })
  956. .Catch(function (res)
  957. {
  958. FailedGetHardDeviceCallBack(res);
  959. });
  960. }
  961. function SuccessGetHardDeviceCallBack(res)
  962. {
  963. var tip = "当前时间为 " + res.time +
  964. ", mac 为 " + res.mac +
  965. ", 硬盘序列号为 " + res.diskSN +
  966. ", CPUID为 " + res.cpuid +
  967. ", 主板序列号为 " + res.boardsn +
  968. ", 主板类型为 " + res.boardtype;
  969. alert(tip);
  970. }
  971. function FailedGetHardDeviceCallBack(res)
  972. {
  973. alert("获取硬件信息失败 " + res.msg);
  974. }
  975. function getNetworkInformation()
  976. {
  977. var params = {};
  978. NetcaPKI.getNetworkInformation(params)
  979. .Then(function(res)
  980. {
  981. SuccessGetNetworkCallBack(res);
  982. })
  983. .Catch(function(res)
  984. {
  985. FailedGetNetworkCallBack(res);
  986. });
  987. }
  988. function SuccessGetNetworkCallBack(res)
  989. {
  990. var Base64={_keyStr:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",encode:function(e){var t="";var n,r,i,s,o,u,a;var f=0;e=Base64._utf8_encode(e);while(f<e.length){n=e.charCodeAt(f++);r=e.charCodeAt(f++);i=e.charCodeAt(f++);s=n>>2;o=(n&3)<<4|r>>4;u=(r&15)<<2|i>>6;a=i&63;if(isNaN(r)){u=a=64}else if(isNaN(i)){a=64}t=t+this._keyStr.charAt(s)+this._keyStr.charAt(o)+this._keyStr.charAt(u)+this._keyStr.charAt(a)}return t},decode:function(e){var t="";var n,r,i;var s,o,u,a;var f=0;e=e.replace(/[^A-Za-z0-9+/=]/g,"");while(f<e.length){s=this._keyStr.indexOf(e.charAt(f++));o=this._keyStr.indexOf(e.charAt(f++));u=this._keyStr.indexOf(e.charAt(f++));a=this._keyStr.indexOf(e.charAt(f++));n=s<<2|o>>4;r=(o&15)<<4|u>>2;i=(u&3)<<6|a;t=t+String.fromCharCode(n);if(u!=64){t=t+String.fromCharCode(r)}if(a!=64){t=t+String.fromCharCode(i)}}t=Base64._utf8_decode(t);return t},_utf8_encode:function(e){e=e.replace(/rn/g,"n");var t="";for(var n=0;n<e.length;n++){var r=e.charCodeAt(n);if(r<128){t+=String.fromCharCode(r)}else if(r>127&&r<2048){t+=String.fromCharCode(r>>6|192);t+=String.fromCharCode(r&63|128)}else{t+=String.fromCharCode(r>>12|224);t+=String.fromCharCode(r>>6&63|128);t+=String.fromCharCode(r&63|128)}}return t},_utf8_decode:function(e){var t="";var n=0;var r=c1=c2=0;while(n<e.length){r=e.charCodeAt(n);if(r<128){t+=String.fromCharCode(r);n++}else if(r>191&&r<224){c2=e.charCodeAt(n+1);t+=String.fromCharCode((r&31)<<6|c2&63);n+=2}else{c2=e.charCodeAt(n+1);c3=e.charCodeAt(n+2);t+=String.fromCharCode((r&15)<<12|(c2&63)<<6|c3&63);n+=3}}return t}};
  991. var tip = "所有网卡信息:\n";
  992. for(i in res.AdaptorInfo)
  993. {
  994. var adapterInfo = "{" +
  995. "\"Name\"=" + Base64.decode(res.AdaptorInfo[i]["Name"]) +
  996. ", \"Mac\"=" + res.AdaptorInfo[i]["Mac"] +
  997. ", \"IPV4\"=" + res.AdaptorInfo[i]["IPV4"] +
  998. ", \"GateWay\"=" + res.AdaptorInfo[i]["GateWay"] +
  999. ", DNS信息= [";
  1000. var dnsInfo = "";
  1001. for(j in res.AdaptorInfo[i]["DNS"])
  1002. {
  1003. dnsInfo += "\"DNS" + j + "\"=" + res.AdaptorInfo[i]["DNS"][j] + " ";
  1004. }
  1005. dnsInfo += "]}\n"
  1006. tip = tip + adapterInfo + dnsInfo;
  1007. }
  1008. // "网络IP地址:" + res.InuseAdaptor.IPV4 +
  1009. // "\n网关地址:" + res.InuseAdaptor.GateWay +
  1010. // "\nDNS地址:" + res.InuseAdaptor.DNS;
  1011. tip += "\n当前用户登录名:" + Base64.decode(res.LoginName) +
  1012. "\n操作系统版本号:" + res.OSVersion;
  1013. tip += "\n已连接wifi:{" +
  1014. "\"Name\"=" + Base64.decode(res.ConnectedWifi["Name"]) +
  1015. ", \"Mac\"=" + res.ConnectedWifi["Mac"] + "}";
  1016. tip += "\n可连接的所有潜在wifi:\n";
  1017. for(i in res.AttachableWifis)
  1018. {
  1019. var wifiStr = "{" +
  1020. "\"Name\"=" + Base64.decode(res.AttachableWifis[i]["Name"]) +
  1021. ", \"Mac\"=" + res.AttachableWifis[i]["Mac"] +
  1022. "}\n";
  1023. tip += wifiStr;
  1024. }
  1025. alert(tip);
  1026. console.log(tip);
  1027. }
  1028. function FailedGetNetworkCallBack(res)
  1029. {
  1030. alert("获取网络信息失败:" + res.msg);
  1031. }
  1032. function seal_SignSealField(_selMode)
  1033. {
  1034. var _srcFile = signatureCreator_src_path.value; //源Pdf文件路径
  1035. var _srcBytes = signatureCreator_srcBytes.value; //源Pdf文件字节流
  1036. var _destFile = signatureCreator_des_path.value; //目标pdf文件
  1037. var _certEncode = signatureCreator_certEncode.value; //签名证书Base64编码
  1038. var _selMode = parseInt(_selMode.name); //操作模式
  1039. var _signFieldText = signatureCreator_signFieldText.value; //签名域显示的文字
  1040. var _sealImageEncode = signatureCreator_sealImageEncode.value;//签章图片Base64编码
  1041. var _fieldName = signatureCreator_field.value; //签名域名称
  1042. var _revInfoIncludeFlag = (signatureCreator_revInfoIncludeFlag.value == 1) ? true : false; //是否包含吊销信息
  1043. var _tsaUrl= ""; //时间戳地址
  1044. var _tsaUsr= ""; //时间戳服务对应用户名
  1045. var _tsaPwd= ""; //时间戳服务对应用户的密码
  1046. var _tsaHashAlgo= ""; //时间戳使用的hash算法,例如”sha-1”,”sha-256”等
  1047. var params = {
  1048. srcFile: _srcFile, //源pdf文件
  1049. srcBytes: _srcBytes, //源Pdf文件的Base64编码
  1050. destFile: _destFile, //目标pdf文件
  1051. certEncode: _certEncode, //签名证书Base64编码
  1052. selMode: _selMode, //操作模式
  1053. signFieldText: _signFieldText, //签名域显示的文字
  1054. sealImageEncode: _sealImageEncode, //签章图片Base64编码
  1055. revInfoIncludeFlag: _revInfoIncludeFlag,//是否包含吊销信息
  1056. SignField: //签名域对象
  1057. {
  1058. fieldName: _fieldName //签名域名称
  1059. },
  1060. Tsa: //时间戳对象
  1061. {
  1062. tsaUrl: _tsaUrl, //时间戳地址
  1063. tsaUsr: _tsaUsr, //时间戳服务对应用户名
  1064. tsaPwd: _tsaPwd, //时间戳服务对应用户的密码
  1065. tsaHashAlgo: _tsaHashAlgo //时间戳使用的hash算法,例如”sha-1”,”sha-256”等
  1066. }
  1067. };
  1068. NetcaPKI.signatureCreatorSignSeal(params)
  1069. .Then(function (res)
  1070. {
  1071. SignatureCreatorSuccessCallBack(res);
  1072. })
  1073. .Catch(function (res)
  1074. {
  1075. SignatureCreatorFailedCallBack(res);
  1076. });
  1077. }
  1078. function seal_SignSealPosition(_selMode)
  1079. {
  1080. var _srcFile = signatureCreator_src_path.value; //源Pdf文件
  1081. var _srcBytes = signatureCreator_srcBytes.value; //源Pdf文件字节流
  1082. var _destFile = signatureCreator_des_path.value; //目标pdf文件
  1083. var _certEncode = signatureCreator_certEncode.value; //签名证书Base64编码
  1084. var _selMode = parseInt(_selMode.name); //操作模式
  1085. var _signFieldText = signatureCreator_signFieldText.value; //签名域显示的文字
  1086. var _sealImageEncode = signatureCreator_sealImageEncode.value;//签章图片Base64编码
  1087. var _revInfoIncludeFlag = (signatureCreator_revInfoIncludeFlag.value == 1) ? true : false; //是否包含吊销信息
  1088. var _pageNum = parseInt(signatureCreator_pageNumber.value); //PDF文档的页码
  1089. var _xPos = parseInt(signatureCreator_xpos.value); //签名域/签章左下角的水平向右方向坐标
  1090. var _yPos = parseInt(signatureCreator_ypos.value); //签名域/签章左下角的垂直向上方向坐标
  1091. var _width = parseInt(signatureCreator_width.value); //签名域/签章的宽度
  1092. var _height = parseInt(signatureCreator_height.value); //签名域/签章的高度
  1093. var _tsaUrl= "http://tsa.cnca.net/NETCATimeStampServer/TSAServer.jsp"; //时间戳地址
  1094. var _tsaUsr= ""; //时间戳服务对应用户名
  1095. var _tsaPwd= ""; //时间戳服务对应用户的密码
  1096. var _tsaHashAlgo= ""; //时间戳使用的hash算法,例如”sha-1”,”sha-256”等
  1097. var params = {
  1098. srcFile: _srcFile, //源pdf文件
  1099. srcBytes: _srcBytes, //源Pdf文件的Base64编码
  1100. destFile: _destFile, //目标pdf文件
  1101. certEncode: _certEncode, //签名证书Base64编码
  1102. selMode: _selMode, //操作模式
  1103. signFieldText: _signFieldText, //签名域显示的文字
  1104. sealImageEncode: _sealImageEncode, //签章图片Base64编码
  1105. revInfoIncludeFlag: _revInfoIncludeFlag,//是否包含吊销信息
  1106. SignPosition: //签名位置对象
  1107. {
  1108. pageNum: _pageNum, //PDF文档的页码
  1109. xPos: _xPos, //签名域/签章左下角的水平向右方向坐标
  1110. yPos: _yPos, //签名域/签章左下角的垂直向上方向坐标
  1111. width: _width, //签名域/签章的宽度
  1112. height: _height //签名域/签章的高度
  1113. },
  1114. Tsa: //时间戳对象
  1115. {
  1116. tsaUrl: _tsaUrl, //时间戳地址
  1117. tsaUsr: _tsaUsr, //时间戳服务对应用户名
  1118. tsaPwd: _tsaPwd, //时间戳服务对应用户的密码
  1119. tsaHashAlgo: _tsaHashAlgo //时间戳使用的hash算法,例如”sha-1”,”sha-256”等
  1120. }
  1121. };
  1122. NetcaPKI.signatureCreatorSignSeal(params)
  1123. .Then(function (res)
  1124. {
  1125. SignatureCreatorSuccessCallBack(res);
  1126. })
  1127. .Catch(function (res)
  1128. {
  1129. SignatureCreatorFailedCallBack(res);
  1130. });
  1131. }
  1132. function SignatureCreatorSuccessCallBack(res)
  1133. {
  1134. var result = "签名/章成功, 目标文件的Base64编码:\n" + res.destFileEncode;
  1135. alert(result);
  1136. console.log(res.destFileEncode);
  1137. if(res.destFileEncode.length >= 20*1024*1024)
  1138. {
  1139. alert("注意:目标文件大于20M,会造成浏览器卡顿");
  1140. }
  1141. NetcaPDFSeal.preViewPDF(1, res.destFileEncode);
  1142. }
  1143. function SignatureCreatorFailedCallBack(res)
  1144. {
  1145. alert("签名/章失败 " + res.msg);
  1146. }
  1147. function seal_SignSealFieldEx(selMode)
  1148. {
  1149. var _srcFile = signatureCreator_src_pathEx.value; //源Pdf文件路径
  1150. var _srcBytes = signatureCreator_srcBytesEx.value; //源Pdf文件字节流
  1151. var _destFile = signatureCreator_des_pathEx.value; //目标pdf文件
  1152. var _certEncode = signatureCreator_certEncodeEx.value; //签名证书Base64编码
  1153. var _selMode = parseInt(selMode.name); //操作模式
  1154. var _signFieldText = signatureCreator_signFieldTextEx.value; //签名域显示的文字
  1155. var _sealImageEncode = signatureCreator_sealImageEncodeEx.value;//签章图片Base64编码
  1156. var _fieldName = signatureCreator_fieldEx.value; //签名域名称
  1157. var _revInfoIncludeFlag = (signatureCreator_revInfoIncludeFlagEx.value == 1) ? true : false; //是否包含吊销信息
  1158. var _tsaUrl= ""; //时间戳地址
  1159. var _tsaUsr= ""; //时间戳服务对应用户名
  1160. var _tsaPwd= ""; //时间戳服务对应用户的密码
  1161. var _tsaHashAlgo= ""; //时间戳使用的hash算法,例如”sha-1”,”sha-256”等
  1162. var _text=signatureCreator_textEx.value; //自定义文本信息
  1163. var _timeFormat=signatureCreator_timeFormatEx.value; //日期格式
  1164. var _widthPercentage=parseFloat(signatureCreator_widthPercentageEx.value); //宽偏移百分比
  1165. var _heightPercentage=parseFloat(signatureCreator_heightPercentageEx.value); //高偏移百分比
  1166. var _fontName=signatureCreator_fontNameEx.value; //字体
  1167. var _fontSize=parseInt(signatureCreator_fontSizeEx.value); //字体大小
  1168. var _A=parseInt(signatureCreator_fontColorAEx.value); //透明度
  1169. var _R=parseInt(signatureCreator_fontColorREx.value); //红色
  1170. var _G=parseInt(signatureCreator_fontColorGEx.value); //绿色
  1171. var _B=parseInt(signatureCreator_fontColorBEx.value); //蓝色
  1172. var params = {
  1173. srcFile: _srcFile, //源pdf文件
  1174. srcBytes: _srcBytes, //源Pdf文件的Base64编码
  1175. destFile: _destFile, //目标pdf文件
  1176. certEncode: _certEncode, //签名证书Base64编码
  1177. selMode: _selMode, //操作模式
  1178. signFieldText: _signFieldText, //签名域显示的文字
  1179. sealImageEncode: _sealImageEncode, //签章图片Base64编码
  1180. revInfoIncludeFlag: _revInfoIncludeFlag,//是否包含吊销信息
  1181. SignField: //签名域对象
  1182. {
  1183. fieldName: _fieldName //签名域名称
  1184. },
  1185. Tsa: //时间戳对象
  1186. {
  1187. tsaUrl: _tsaUrl, //时间戳地址
  1188. tsaUsr: _tsaUsr, //时间戳服务对应用户名
  1189. tsaPwd: _tsaPwd, //时间戳服务对应用户的密码
  1190. tsaHashAlgo: _tsaHashAlgo //时间戳使用的hash算法,例如”sha-1”,”sha-256”等
  1191. },
  1192. TimeObj:
  1193. {
  1194. text: _text, //自定义文本信息
  1195. timeFormat: _timeFormat, //日期格式
  1196. widthPercentage: _widthPercentage, //宽偏移百分比
  1197. heightPercentage: _heightPercentage,//高偏移百分比
  1198. fontName: _fontName, //字体
  1199. fontSize: _fontSize, //字体大小
  1200. FontColor:
  1201. {
  1202. A: _A,
  1203. R: _R,
  1204. G: _G,
  1205. B: _B
  1206. }
  1207. },
  1208. AppearanceObj:
  1209. {
  1210. appearanceType:parseInt(signatureCreator_appearanceType.value), //外观类型
  1211. width:parseInt(signatureCreator_appearanceWidth.value), //外观宽度
  1212. height:parseInt(signatureCreator_appearanceHeight.value), //外观高度
  1213. textSpirits:g_textSpirits //文本信息
  1214. }
  1215. };
  1216. NetcaPKI.SignatureCreatorSignSealEx(params)
  1217. .Then(function (res)
  1218. {
  1219. SignatureCreatorSuccessCallBackEx(res);
  1220. })
  1221. .Catch(function (res)
  1222. {
  1223. SignatureCreatorFailedCallBackEx(res);
  1224. });
  1225. }
  1226. function seal_SignSealPositionEx(selMode)
  1227. {
  1228. var _srcFile = signatureCreator_src_pathEx.value; //源Pdf文件
  1229. var _srcBytes = signatureCreator_srcBytesEx.value; //源Pdf文件字节流
  1230. var _destFile = signatureCreator_des_pathEx.value; //目标pdf文件
  1231. var _certEncode = signatureCreator_certEncodeEx.value; //签名证书Base64编码
  1232. var _selMode = parseInt(selMode.name); //操作模式
  1233. var _signFieldText = signatureCreator_signFieldTextEx.value; //签名域显示的文字
  1234. var _sealImageEncode = signatureCreator_sealImageEncodeEx.value;//签章图片Base64编码
  1235. var _revInfoIncludeFlag = (signatureCreator_revInfoIncludeFlagEx.value == 1) ? true : false; //是否包含吊销信息
  1236. var _positionStartPage = parseInt(signatureCreator_position_startPageEx.value); //PDF文档的开始页码
  1237. var _positionEndPage = parseInt(signatureCreator_position_endPageEx.value); //PDF文档的结束页码
  1238. var _xPos = parseInt(signatureCreator_xposEx.value); //签名域/签章左下角的水平向右方向坐标
  1239. var _yPos = parseInt(signatureCreator_yposEx.value); //签名域/签章左下角的垂直向上方向坐标
  1240. var _positioinWidth = parseInt(signatureCreator_position_widthEx.value); //签名域/签章的宽度
  1241. var _positionHeight = parseInt(signatureCreator_position_heightEx.value); //签名域/签章的高度
  1242. var _tsaUrl= ""; //时间戳地址
  1243. var _tsaUsr= ""; //时间戳服务对应用户名
  1244. var _tsaPwd= ""; //时间戳服务对应用户的密码
  1245. var _tsaHashAlgo= ""; //时间戳使用的hash算法,例如”sha-1”,”sha-256”等
  1246. var _text=signatureCreator_textEx.value; //自定义文本信息
  1247. var _timeFormat=signatureCreator_timeFormatEx.value; //日期格式
  1248. var _widthPercentage=parseFloat(signatureCreator_widthPercentageEx.value); //宽偏移百分比
  1249. var _heightPercentage=parseFloat(signatureCreator_heightPercentageEx.value); //高偏移百分比
  1250. var _fontName=signatureCreator_fontNameEx.value; //字体
  1251. var _fontSize=parseInt(signatureCreator_fontSizeEx.value); //字体大小
  1252. var _A=parseInt(signatureCreator_fontColorAEx.value); //透明度
  1253. var _R=parseInt(signatureCreator_fontColorREx.value); //红色
  1254. var _G=parseInt(signatureCreator_fontColorGEx.value); //绿色
  1255. var _B=parseInt(signatureCreator_fontColorBEx.value); //蓝色
  1256. var params = {
  1257. srcFile: _srcFile, //源pdf文件
  1258. srcBytes: _srcBytes, //源Pdf文件的Base64编码
  1259. destFile: _destFile, //目标pdf文件
  1260. certEncode: _certEncode, //签名证书Base64编码
  1261. selMode: _selMode, //操作模式
  1262. signFieldText: _signFieldText, //签名域显示的文字
  1263. sealImageEncode: _sealImageEncode, //签章图片Base64编码
  1264. revInfoIncludeFlag: _revInfoIncludeFlag,//是否包含吊销信息
  1265. SignPosition: //签名位置对象
  1266. {
  1267. startPage: _positionStartPage, //PDF文档的开始页码
  1268. endPage: _positionEndPage, //PDF文档的结束页码
  1269. xPos: _xPos, //签名域/签章左下角的水平向右方向坐标
  1270. yPos: _yPos, //签名域/签章左下角的垂直向上方向坐标
  1271. width: _positioinWidth, //签名域/签章的宽度
  1272. height: _positionHeight //签名域/签章的高度
  1273. },
  1274. Tsa: //时间戳对象
  1275. {
  1276. tsaUrl: _tsaUrl, //时间戳地址
  1277. tsaUsr: _tsaUsr, //时间戳服务对应用户名
  1278. tsaPwd: _tsaPwd, //时间戳服务对应用户的密码
  1279. tsaHashAlgo: _tsaHashAlgo //时间戳使用的hash算法,例如”sha-1”,”sha-256”等
  1280. },
  1281. TimeObj:
  1282. {
  1283. text: _text, //自定义文本信息
  1284. timeFormat: _timeFormat, //日期格式
  1285. widthPercentage: _widthPercentage, //宽偏移百分比
  1286. heightPercentage: _heightPercentage,//高偏移百分比
  1287. fontName: _fontName, //字体
  1288. fontSize: _fontSize, //字体大小
  1289. FontColor:
  1290. {
  1291. A: _A,
  1292. R: _R,
  1293. G: _G,
  1294. B: _B
  1295. }
  1296. },
  1297. AppearanceObj:
  1298. {
  1299. appearanceType:parseInt(signatureCreator_appearanceType.value), //外观类型
  1300. width:parseInt(signatureCreator_appearanceWidth.value), //外观宽度
  1301. height:parseInt(signatureCreator_appearanceHeight.value), //外观高度
  1302. textSpirits:g_textSpirits //文本信息
  1303. }
  1304. };
  1305. NetcaPKI.SignatureCreatorSignSealEx(params)
  1306. .Then(function (res)
  1307. {
  1308. SignatureCreatorSuccessCallBackEx(res);
  1309. })
  1310. .Catch(function (res)
  1311. {
  1312. SignatureCreatorFailedCallBackEx(res);
  1313. });
  1314. }
  1315. function seal_SealKeyWord(selMode)
  1316. {
  1317. var _srcFile = signatureCreator_src_pathEx.value; //源Pdf文件
  1318. var _srcBytes = signatureCreator_srcBytesEx.value; //源Pdf文件字节流
  1319. var _destFile = signatureCreator_des_pathEx.value; //目标pdf文件
  1320. var _certEncode = signatureCreator_certEncodeEx.value; //签名证书Base64编码
  1321. var _selMode = parseInt(selMode.name); //操作模式
  1322. var _signFieldText = signatureCreator_signFieldTextEx.value; //签名域显示的文字
  1323. var _sealImageEncode = signatureCreator_sealImageEncodeEx.value;//签章图片Base64编码
  1324. var _revInfoIncludeFlag = (signatureCreator_revInfoIncludeFlagEx.value == 1) ? true : false; //是否包含吊销信息
  1325. var _tsaUrl= ""; //时间戳地址
  1326. var _tsaUsr= ""; //时间戳服务对应用户名
  1327. var _tsaPwd= ""; //时间戳服务对应用户的密码
  1328. var _tsaHashAlgo= ""; //时间戳使用的hash算法,例如”sha-1”,”sha-256”等
  1329. var _text=signatureCreator_textEx.value; //自定义文本信息
  1330. var _timeFormat=signatureCreator_timeFormatEx.value; //日期格式
  1331. var _widthPercentage=parseFloat(signatureCreator_widthPercentageEx.value); //宽偏移百分比
  1332. var _heightPercentage=parseFloat(signatureCreator_heightPercentageEx.value); //高偏移百分比
  1333. var _fontName=signatureCreator_fontNameEx.value; //字体
  1334. var _fontSize=parseInt(signatureCreator_fontSizeEx.value); //字体大小
  1335. var _A=parseInt(signatureCreator_fontColorAEx.value); //透明度
  1336. var _R=parseInt(signatureCreator_fontColorREx.value); //红色
  1337. var _G=parseInt(signatureCreator_fontColorGEx.value); //绿色
  1338. var _B=parseInt(signatureCreator_fontColorBEx.value); //蓝色
  1339. var _keyWord = signatureCreator_keyWordEx.value; //关键字
  1340. var _keyWordStartPage = parseInt(signatureCreator_keyword_startPageEx.value); //PDF文档的开始页码
  1341. var _keyWordEndPage = parseInt(signatureCreator_keyword_endPageEx.value); //PDF文档的开始页码
  1342. var _keyWordIndex = parseInt(signatureCreator_keyWordIndexEx.value); //关键字索引
  1343. var _keyWordWidth = parseInt(signatureCreator_keyword_widthEx.value); //签名域矩形的宽度
  1344. var _keyWordHeight = parseInt(signatureCreator_keyword_heightEx.value); //签名域矩形的高度
  1345. var _offsetX = parseInt(signatureCreator_offsetXEx.value); //水平偏移量
  1346. var _offsetY = parseInt(signatureCreator_offsetYEx.value); //垂直偏移量
  1347. var params = {
  1348. srcFile: _srcFile, //源pdf文件
  1349. srcBytes: _srcBytes, //源Pdf文件的Base64编码
  1350. destFile: _destFile, //目标pdf文件
  1351. certEncode: _certEncode, //签名证书Base64编码
  1352. selMode: _selMode, //操作模式
  1353. signFieldText: _signFieldText, //签名域显示的文字
  1354. sealImageEncode: _sealImageEncode, //签章图片Base64编码
  1355. revInfoIncludeFlag: _revInfoIncludeFlag,//是否包含吊销信息
  1356. SealKeyWord: //关键字对象
  1357. {
  1358. keyWord: _keyWord, //关键字
  1359. startPage: _keyWordStartPage, //PDF文档的开始页码
  1360. endPage: _keyWordEndPage, //PDF文档的结束页码
  1361. keyWordIndex: _keyWordIndex, //关键字索引
  1362. width: _keyWordWidth, //签名域矩形的宽度
  1363. height: _keyWordHeight, //签名域矩形的高度
  1364. offsetX: _offsetX, //水平偏移量
  1365. offsetY: _offsetY //垂直偏移量
  1366. },
  1367. Tsa: //时间戳对象
  1368. {
  1369. tsaUrl: _tsaUrl, //时间戳地址
  1370. tsaUsr: _tsaUsr, //时间戳服务对应用户名
  1371. tsaPwd: _tsaPwd, //时间戳服务对应用户的密码
  1372. tsaHashAlgo: _tsaHashAlgo //时间戳使用的hash算法,例如”sha-1”,”sha-256”等
  1373. },
  1374. TimeObj:
  1375. {
  1376. text: _text, //自定义信息
  1377. timeFormat: _timeFormat, //日期格式
  1378. widthPercentage: _widthPercentage, //宽偏移百分比
  1379. heightPercentage: _heightPercentage,//高偏移百分比
  1380. fontName: _fontName, //字体
  1381. fontSize: _fontSize, //字体大小
  1382. FontColor:
  1383. {
  1384. A: _A,
  1385. R: _R,
  1386. G: _G,
  1387. B: _B
  1388. }
  1389. },
  1390. AppearanceObj:
  1391. {
  1392. appearanceType:parseInt(signatureCreator_appearanceType.value), //外观类型
  1393. width:parseInt(signatureCreator_appearanceWidth.value), //外观宽度
  1394. height:parseInt(signatureCreator_appearanceHeight.value), //外观高度
  1395. textSpirits:g_textSpirits //文本信息
  1396. }
  1397. };
  1398. NetcaPKI.SignatureCreatorSignSealEx(params)
  1399. .Then(function (res)
  1400. {
  1401. SignatureCreatorSuccessCallBackEx(res);
  1402. })
  1403. .Catch(function (res)
  1404. {
  1405. SignatureCreatorFailedCallBackEx(res);
  1406. });
  1407. }
  1408. function SignatureCreatorSuccessCallBackEx(res)
  1409. {
  1410. var result = "签名/章成功, 目标文件的Base64编码:\n" + res.destFileEncode;
  1411. alert(result);
  1412. console.log(res.destFileEncode);
  1413. NetcaPDFSeal.preViewPDF(1, res.destFileEncode);
  1414. }
  1415. function SignatureCreatorFailedCallBackEx(res)
  1416. {
  1417. alert("签名/章失败 " + res.msg);
  1418. }
  1419. //获取签章软件版本号
  1420. function seal_getVersion() {
  1421. var params ={};
  1422. NetcaPKI.getSealClientVersion(params)
  1423. .Then(function(res) {
  1424. successGetSealClientVersionCallBack(res);
  1425. })
  1426. .Catch(function(res) {
  1427. failedGetSealClientVersionCallBack(res);
  1428. });
  1429. }
  1430. function successGetSealClientVersionCallBack(res) {
  1431. alert("获取签章软件版本号成功\n版本号为:" + res.version);
  1432. }
  1433. function failedGetSealClientVersionCallBack(res) {
  1434. alert("获取签章软件版本号失败," + res.msg);
  1435. }
  1436. function HashSuccessCallBack(res)
  1437. {
  1438. hashDataResult.value=res.hashValue;
  1439. }
  1440. function HashFailedCallBack(res)
  1441. {
  1442. alert(res.msg);
  1443. }
  1444. function hashSample() {
  1445. var _hashAlgo = parseInt(hashAlgoId.value);
  1446. var _text = utf8_to_b64(hashText.value);
  1447. var _flag = parseInt(hashflagId.value);
  1448. params = {
  1449. hashAlgo:_hashAlgo,
  1450. data: { //数据(DataParams)
  1451. text: _text
  1452. },
  1453. flag:_flag
  1454. };
  1455. NetcaPKI.HashData(params)
  1456. .Then(function(res){
  1457. HashSuccessCallBack(res);
  1458. })
  1459. .Catch(function (res) {
  1460. HashFailedCallBack(res);
  1461. });
  1462. }
  1463. function CipherSuccessCallBack(res)
  1464. {
  1465. var cipherUseEnc = cipherUseEncId.value=="1"?true:false;
  1466. if(cipherUseEnc)
  1467. {
  1468. cipherResult.value=res.cipherValue;
  1469. }
  1470. else
  1471. {
  1472. cipherResult.value=b64_to_utf8(res.clearValue);
  1473. }
  1474. }
  1475. function CipherFailedCallBack(res)
  1476. {
  1477. alert("对称加解密失败\n"+res.msg);
  1478. }
  1479. function cipherSample() {
  1480. var _algo=parseInt(cipherAlgoId.value);
  1481. var _useEnc = cipherUseEncId.value=="1"?true:false;
  1482. var _text ;
  1483. if(_useEnc==1)
  1484. {
  1485. _text=utf8_to_b64(cipherData.value);
  1486. }
  1487. else
  1488. {
  1489. _text=cipherData.value;
  1490. }
  1491. var _hexText = cipherKeyId.value;
  1492. params = {
  1493. algo:_algo,
  1494. data: { //数据(DataParams)
  1495. text: _text
  1496. },
  1497. key: { //数据(DataParams)
  1498. hexText: _hexText
  1499. },
  1500. useEnc:_useEnc
  1501. };
  1502. NetcaPKI.cipher(params)
  1503. .Then(function(res){
  1504. CipherSuccessCallBack(res);
  1505. })
  1506. .Catch(function (res) {
  1507. CipherFailedCallBack(res);
  1508. });
  1509. }
  1510. //验证证书
  1511. function verifyCertificate() {
  1512. var _certEncode = VerifyCertificate_certEncode.value;
  1513. var _bUseCrl = (VerifyCertificateverify_crlFlag.value == 1) ? true : false;
  1514. var _bUseOcsp = (VerifyCertificate_ocspFlag.value == 1) ? true : false;
  1515. var _crlEncode = VerifyCertificate_crlEncode.value;
  1516. var _ocspUrl = VerifyCertificate_ocspUrl.value;
  1517. var _time = VerifyCertificate_time.value;
  1518. var params = {
  1519. cert : {
  1520. "encode" : _certEncode
  1521. },
  1522. bUseCrl: _bUseCrl,
  1523. bUseOcsp: _bUseOcsp,
  1524. crlEncode: _crlEncode,
  1525. ocspUrl: _ocspUrl,
  1526. time: _time
  1527. };
  1528. NetcaPKI.verifyCertificate(params)
  1529. .Then(function(res) {
  1530. successVerifyCertificateCallBack(res);
  1531. })
  1532. .Catch(function(res) {
  1533. failedVerifyCertificateCallBack(res);
  1534. });
  1535. }
  1536. function successVerifyCertificateCallBack(res) {
  1537. alert("验证成功," + res.info);
  1538. }
  1539. function failedVerifyCertificateCallBack(res) {
  1540. alert("验证失败," + res.msg);
  1541. }
  1542. //验证签名PDF
  1543. function seal_verifySignPDF() {
  1544. var _srcFile = signatureVerifierVerify_src_path.value;
  1545. var _srcBytes = signatureVerifierVerify_srcBytes.value;
  1546. var _level = parseInt(signatureVerifier_level.value);
  1547. var params = {
  1548. srcFile : _srcFile,
  1549. srcBytes : _srcBytes,
  1550. level : _level
  1551. };
  1552. NetcaPKI.signatureVerifierVerifyPDF(params)
  1553. .Then(function(res) {
  1554. successSignatureVerifierVerifyPDF(res);
  1555. })
  1556. .Catch(function(res) {
  1557. failedSignatureVerifierVerifyPDF(res);
  1558. });
  1559. }
  1560. function successSignatureVerifierVerifyPDF(res) {
  1561. info = "";
  1562. for(i in res.VerifyInfos)
  1563. {
  1564. index = parseInt(i)+1;
  1565. info += "第"+ index +"个签名信息, " +
  1566. res.VerifyInfos[i].status +
  1567. ", 签名者:" + res.VerifyInfos[i].signerName +
  1568. ", 签名域:" + res.VerifyInfos[i].fieldName +
  1569. ", 签名证书:" + res.VerifyInfos[i].certEncode +
  1570. ", 签名摘要算法:" + res.VerifyInfos[i].hashAlgo +
  1571. ", 签名创建日期:" + res.VerifyInfos[i].signDate;
  1572. if(res.VerifyInfos[i].hasRevoke)
  1573. {
  1574. info += ",存在吊销信息" +
  1575. ", 证书吊销状态:" + res.VerifyInfos[i].revokeStatus;
  1576. }
  1577. else
  1578. {
  1579. info += ",不存在吊销信息";
  1580. }
  1581. if(res.VerifyInfos[i].hasTsa)
  1582. {
  1583. info += ", 存在时间戳信息";
  1584. }
  1585. else
  1586. {
  1587. info += ", 不存在时间戳信息";
  1588. }
  1589. if(res.VerifyInfos[i].isTsaValid)
  1590. {
  1591. info += ", 时间戳有效";
  1592. }
  1593. else
  1594. {
  1595. info += ", 时间戳无效";
  1596. }
  1597. info += ", 时间戳日期:" + res.VerifyInfos[i].tsaDate + "\n";
  1598. }
  1599. alert("验证证书成功:" + info);
  1600. console.log(info);
  1601. }
  1602. function failedSignatureVerifierVerifyPDF(res) {
  1603. alert("验证失败," + res.msg);
  1604. }
  1605. //撤销签名/章
  1606. function seal_undoSignPDF() {
  1607. var _signFile = signatureVerifierUndo_src_path.value;
  1608. var _signBytes = signatureVerifierUndo_srcBytes.value;
  1609. var _index = parseInt(signatureVerifierUndo_index.value);
  1610. var params = {
  1611. signFile : _signFile,
  1612. signBytes : _signBytes,
  1613. index : _index
  1614. };
  1615. NetcaPKI.signatureVerifierUndoPDF(params)
  1616. .Then(function(res) {
  1617. successSignatureVerifierUndoPDF(res);
  1618. })
  1619. .Catch(function(res) {
  1620. failedSignatureVerifierUndoPDF(res);
  1621. });
  1622. }
  1623. function successSignatureVerifierUndoPDF(res) {
  1624. alert("撤销成功,原文base64编码:" + res.srcBytes);
  1625. console.log(res.srcBytes);
  1626. document.getElementById("signatureVerifierUndo_destBytes").value = res.srcBytes;
  1627. }
  1628. function failedSignatureVerifierUndoPDF(res) {
  1629. alert("撤销失败," + res.msg);
  1630. }
  1631. function showNetcaAAVerifyStatusMsg(res)
  1632. {
  1633. if(res.certVerifyStatus=="0")
  1634. {
  1635. alert("验证证书有效");
  1636. }
  1637. else if(res.certVerifyStatus=="1")
  1638. {
  1639. alert("验证处理失败");
  1640. }
  1641. else if(res.certVerifyStatus=="2")
  1642. {
  1643. alert("证书格式有误");
  1644. }
  1645. else if(res.certVerifyStatus=="3")
  1646. {
  1647. alert("证书不在有效期内");
  1648. }
  1649. else if(res.certVerifyStatus=="4")
  1650. {
  1651. alert("密钥用途不合(KU和EKU)");
  1652. }
  1653. else if(res.certVerifyStatus=="5")
  1654. {
  1655. alert("证书名字不合(DN和SAN)");
  1656. }
  1657. else if(res.certVerifyStatus=="6")
  1658. {
  1659. alert("证书策略不合(取决于CVS的配置)");
  1660. }
  1661. else if(res.certVerifyStatus=="7")
  1662. {
  1663. alert("证书扩展不合(取决于CVS的配置)");
  1664. }
  1665. else if(res.certVerifyStatus=="8")
  1666. {
  1667. alert("证书链验证失败(包括了签名检查;基本约束检查;名字约束检查;策略约束检查;ACL检查等)");
  1668. }
  1669. else if(res.certVerifyStatus=="9")
  1670. {
  1671. alert("证书被注销");
  1672. }
  1673. else if(res.certVerifyStatus=="10")
  1674. {
  1675. alert("注销状态不能确定(如果设置了已过期的CRL或OCSP无法连接)");
  1676. }
  1677. else if(res.certVerifyStatus=="11")
  1678. {
  1679. alert("证书不受信任/未被授权");
  1680. }
  1681. else if(res.certVerifyStatus=="12")
  1682. {
  1683. alert("证书被暂时锁定/未激活");
  1684. }
  1685. else
  1686. {
  1687. alert("证书验证失败");
  1688. }
  1689. }
  1690. function netcaaaverifycertsuccess(res)
  1691. {
  1692. netcaaaResult.value=JSON.stringify(res);
  1693. showNetcaAAVerifyStatusMsg(res);
  1694. }
  1695. function netcaaaverifycertfail(res)
  1696. {
  1697. alert("验证证书失败:" + res.msg);
  1698. }
  1699. function netcaaa_verifycert_example()
  1700. {
  1701. /* 从USBKey中选择NETCA 颁发的签名证书 */
  1702. var _url = netcaaaurl.value;
  1703. var _verifytime = "";
  1704. var _encode="";
  1705. var _type = "";
  1706. var _condition = "";
  1707. //如果是输入的证书编码 可以直接射设置certEncode值
  1708. if( netcaaacert.value.length != 0 )
  1709. {
  1710. _encode=netcaaacert.value;
  1711. }
  1712. else
  1713. {
  1714. _type = "{\"UIFlag\":\"default\", \"InValidity\":true,\"Type\":\"signature\", \"Method\":\"device\",\"Value\":\"any\"}";
  1715. _condition = "IssuerCN~'NETCA' && InValidity='True' && CertType='Signature'";
  1716. }
  1717. var params = {
  1718. url:_url,
  1719. verifytime : _verifytime,
  1720. cert: { //证书(CertificateParams)
  1721. encode: _encode,
  1722. type: _type,
  1723. condition: _condition
  1724. }
  1725. };
  1726. NetcaPKI.netcaAA_VerifyUserCert(params)
  1727. .Then(function(res) {
  1728. netcaaaverifycertsuccess(res);
  1729. })
  1730. .Catch(function(res) {
  1731. netcaaaverifycertfail(res);
  1732. });
  1733. }
  1734. function netcaaachkonecertsuccess(res)
  1735. {
  1736. netcaaachkonecertResult.value=JSON.stringify(res);
  1737. showNetcaAAVerifyStatusMsg(res);
  1738. }
  1739. function netcaaachkonecertfail(res)
  1740. {
  1741. alert("验证证书失败:" + res.msg);
  1742. }
  1743. function netcaaachk_chkonecert_example()
  1744. {
  1745. /* 从USBKey中选择NETCA 颁发的签名证书 */
  1746. var _url = netcaaachkonecerturl.value;
  1747. var _encode = "";
  1748. var _type = "";
  1749. var _condition = "";
  1750. //如果是输入的证书编码 可以直接射设置certEncode值
  1751. if( netcaaachkonecert.value.length != 0 )
  1752. {
  1753. _encode=netcaaachkonecert.value;
  1754. }
  1755. else
  1756. {
  1757. _type = "{\"UIFlag\":\"default\", \"InValidity\":true,\"Type\":\"signature\", \"Method\":\"device\",\"Value\":\"any\"}";
  1758. _condition = "IssuerCN~'NETCA' && InValidity='True' && CertType='Signature'";
  1759. }
  1760. var params = {
  1761. url:_url,
  1762. cert: { //证书(CertificateParams)
  1763. encode: _encode,
  1764. type: _type,
  1765. condition: _condition
  1766. }
  1767. };
  1768. NetcaPKI.netcaAA_ChkOneCert(params)
  1769. .Then(function(res) {
  1770. netcaaachkonecertsuccess(res);
  1771. })
  1772. .Catch(function(res) {
  1773. netcaaachkonecertfail(res);
  1774. });
  1775. }
  1776. function modifyPwd()
  1777. {
  1778. var _sn = keySN.value;
  1779. var _type = parseInt(keyType.value);
  1780. var _oldPwd = oldPwd.value;
  1781. var _newPwd = modify_newPwd.value;
  1782. var params = {
  1783. sn: _sn,
  1784. type: _type,
  1785. oldPwd: _oldPwd,
  1786. newPwd: _newPwd
  1787. };
  1788. NetcaPKI.modifyKeyPwd(params)
  1789. .Then(function(res){
  1790. if (res.result == 1)
  1791. {
  1792. modifySuccess(res);
  1793. }
  1794. else
  1795. {
  1796. modifyFailed(res);
  1797. }
  1798. })
  1799. .Catch(function (res) {
  1800. alert(res.msg);
  1801. });
  1802. }
  1803. function modifySuccess(res)
  1804. {
  1805. var tip = "密码修改成功,密码剩余重试次数为" + res.retrynum;
  1806. DeviceOutputId.value = tip;
  1807. }
  1808. function modifyFailed(res)
  1809. {
  1810. var tip = "密码修改失败,密码剩余重试次数为" + res.retrynum + ",错误码=" + res.result;
  1811. DeviceOutputId.value = tip;
  1812. }
  1813. function unlockPwd()
  1814. {
  1815. var _sn = keySN.value;
  1816. var _type = parseInt(keyType.value);
  1817. var _unlockPwd = unlock_unlockPwd.value;
  1818. var _newPwd = unlock_newPwd.value;
  1819. var params = {
  1820. sn: _sn,
  1821. type: parseInt(_type),
  1822. unlockPwd: _unlockPwd,
  1823. newPwd: _newPwd
  1824. };
  1825. NetcaPKI.unlockKeyPwd(params)
  1826. .Then(function(res){
  1827. if (res.result == 1)
  1828. {
  1829. unlockSuccess(res);
  1830. }
  1831. else
  1832. {
  1833. unlockFailed(res);
  1834. }
  1835. })
  1836. .Catch(function (res) {
  1837. alert(res.msg);
  1838. });
  1839. }
  1840. function unlockSuccess(res)
  1841. {
  1842. var tip = "密码解锁成功,密码剩余重试次数为" + res.retrynum;
  1843. DeviceOutputId.value = tip;
  1844. }
  1845. function unlockFailed(res)
  1846. {
  1847. var tip = "密码解锁失败,密码剩余重试次数为" + res.retrynum + ",错误码=" + res.result;
  1848. DeviceOutputId.value = tip;
  1849. }
  1850. function generateP10()
  1851. {
  1852. var _sn = GenerateP10_sn.value;
  1853. var _type = parseInt(GenerateP10_type.value);
  1854. var _useKeypair = (GenerateP10_useKeypairFlag.value == 1)? true : false;
  1855. var _keypairAlgo = parseInt(GenerateP10_keypairAlgo.value);
  1856. var _keypairLabel = GenerateP10_keypairLabel.value;
  1857. var _keypairBits = parseInt(GenerateP10_keypairBits.value);
  1858. var _signAlgo = parseInt(GenerateP10_signAlgo.value);
  1859. var _c = GenerateP10_c.value;
  1860. var _st = GenerateP10_st.value;
  1861. var _l = GenerateP10_l.value;
  1862. var _o = GenerateP10_o.value;
  1863. var _email = GenerateP10_email.value;
  1864. var _ou = GenerateP10_ou.value;
  1865. var _cn = GenerateP10_cn.value;
  1866. var params = {
  1867. sn: _sn,
  1868. type: parseInt(_type),
  1869. useKeypair: _useKeypair,
  1870. keypairAlgo: parseInt(_keypairAlgo),
  1871. keypairLabel: _keypairLabel,
  1872. keypairBits: parseInt(_keypairBits),
  1873. signAlgo: parseInt(_signAlgo),
  1874. SubjectObj : {
  1875. c: _c,
  1876. st: _st,
  1877. l: _l,
  1878. o: _o,
  1879. email: _email,
  1880. ou: _ou,
  1881. cn: _cn
  1882. }
  1883. };
  1884. NetcaPKI.generateP10(params)
  1885. .Then(function(res) {
  1886. generateP10Success(res);
  1887. })
  1888. .Catch(function(res) {
  1889. generateP10Failed(res);
  1890. });
  1891. }
  1892. function generateP10Success(res)
  1893. {
  1894. alert("产生证书请求成功,编码:" + res.certReq);
  1895. console.log(res.certReq);
  1896. }
  1897. function generateP10Failed(res)
  1898. {
  1899. alert("产生证书请求失败," + res.msg);
  1900. }
  1901. function installCertificate()
  1902. {
  1903. var _sn = InstallCertificate_sn.value;
  1904. var _type = InstallCertificate_type.value;
  1905. var _encKeypair = InstallCertificate_encKeypairEncode.value;
  1906. var _encCert = InstallCertificate_encCertEncode.value;
  1907. var _signCert = InstallCertificate_signCertEncode.value;
  1908. var params = {
  1909. sn: _sn,
  1910. type: parseInt(_type),
  1911. encKeypair: _encKeypair,
  1912. encCert: _encCert,
  1913. signCert: _signCert
  1914. };
  1915. NetcaPKI.installCertificate(params)
  1916. .Then(function(res) {
  1917. installCertificateSuccess(res);
  1918. })
  1919. .Catch(function(res) {
  1920. installCertificateFailed(res);
  1921. });
  1922. }
  1923. function installCertificateSuccess(res)
  1924. {
  1925. alert("安装证书成功");
  1926. }
  1927. function installCertificateFailed(res)
  1928. {
  1929. alert("安装证书失败:" + res.msg);
  1930. }
  1931. function getNetcaSealImage(certEncode) {
  1932. var params = {
  1933. "cert":{
  1934. "encode":certEncode
  1935. }
  1936. };
  1937. NetcaPKI.getNetcaSealImage(params)
  1938. .Then(function(res){
  1939. GetNetcaSealImageSuccessCallBack(res);
  1940. })
  1941. .Catch(function (res) {
  1942. GetNetcaSealImageFailCallBack(res);
  1943. });
  1944. }
  1945. function GetNetcaSealImageSuccessCallBack(res)
  1946. {
  1947. alert("获取签章图片成功!");
  1948. alert(res.sealImageBase64);
  1949. console.log(res.sealImageBase64);
  1950. }
  1951. function GetNetcaSealImageFailCallBack(res)
  1952. {
  1953. alert(res.msg);
  1954. }
  1955. function uIDisplayCert()
  1956. {
  1957. var certEncode = DeviceOutputId.value;
  1958. var selectType = "Device";
  1959. var selectCondition = "InValidity='True' && CertType='Signature'";
  1960. var params = {
  1961. cert: {
  1962. "encode": certEncode,
  1963. "type": selectType,
  1964. "condition": selectCondition
  1965. }
  1966. };
  1967. NetcaPKI.displayCert(params)
  1968. .Then(function(res){
  1969. alert("证书显示成功");
  1970. })
  1971. .Catch(function (res) {
  1972. alert(res.msg);
  1973. });
  1974. }
  1975. function createData()
  1976. {
  1977. var certEncode = Data_certEncode.value;
  1978. var selectType = "Device";
  1979. var selectCondition = "InValidty='True' && CertType='Signature'";
  1980. var params = {
  1981. cert: {
  1982. "encode": certEncode,
  1983. "type": selectType,
  1984. "condition": selectCondition
  1985. },
  1986. device: {
  1987. "sn": Data_sn.value,
  1988. "type": parseInt(Data_type.value)
  1989. },
  1990. id: parseInt(CreateData_id.value),
  1991. noVerifyPermission: {
  1992. canRead: ((CreateData_noVerifyPermission_canRead.value == 1) ? true : false),
  1993. canWrite: ((CreateData_noVerifyPermission_canWrite.value == 1) ? true : false),
  1994. canDelete: ((CreateData_noVerifyPermission_canDelete.value == 1) ? true : false)
  1995. },
  1996. verifyUserPermission: {
  1997. canRead: ((CreateData_verifyUserPermission_canRead.value == 1) ? true : false),
  1998. canWrite: ((CreateData_verifyUserPermission_canWrite.value == 1) ? true : false),
  1999. canDelete: ((CreateData_verifyUserPermission_canDelete.value == 1) ? true : false)
  2000. },
  2001. length: parseInt(CreateData_length.value)
  2002. };
  2003. NetcaPKI.createData(params)
  2004. .Then(function(res) {
  2005. alert("创建数据成功");
  2006. })
  2007. .Catch(function(res) {
  2008. alert(res.msg);
  2009. });
  2010. }
  2011. function readData()
  2012. {
  2013. var certEncode = Data_certEncode.value;
  2014. var selectType = "Device";
  2015. var selectCondition = "InValidty='True' && CertType='Signature'";
  2016. var params = {
  2017. cert: {
  2018. "encode": certEncode,
  2019. "type": selectType,
  2020. "condition": selectCondition
  2021. },
  2022. device: {
  2023. "sn": Data_sn.value,
  2024. "type": parseInt(Data_type.value)
  2025. },
  2026. id: parseInt(ReadData_id.value),
  2027. offset: parseInt(ReadData_offset.value),
  2028. length: parseInt(ReadData_length.value)
  2029. };
  2030. NetcaPKI.readData(params)
  2031. .Then(function(res) {
  2032. alert("读取数据成功");
  2033. ReadData_data.value = res.data;
  2034. })
  2035. .Catch(function(res) {
  2036. alert(res.msg);
  2037. });
  2038. }
  2039. function writeData()
  2040. {
  2041. var certEncode = Data_certEncode.value;
  2042. var selectType = "Device";
  2043. var selectCondition = "InValidty='True' && CertType='Signature'";
  2044. var params = {
  2045. cert: {
  2046. "encode": certEncode,
  2047. "type": selectType,
  2048. "condition": selectCondition
  2049. },
  2050. device: {
  2051. "sn": Data_sn.value,
  2052. "type": parseInt(Data_type.value)
  2053. },
  2054. id: parseInt(WriteData_id.value),
  2055. offset: parseInt(WriteData_offset.value),
  2056. data: { //数据(DataParams)
  2057. text: WriteData_data.value
  2058. }
  2059. };
  2060. NetcaPKI.writeData(params)
  2061. .Then(function(res) {
  2062. alert("写入数据成功");
  2063. })
  2064. .Catch(function(res) {
  2065. alert(res.msg);
  2066. });
  2067. }
  2068. function deleteData()
  2069. {
  2070. var certEncode = Data_certEncode.value;
  2071. var selectType = "Device";
  2072. var selectCondition = "InValidty='True' && CertType='Signature'";
  2073. var params = {
  2074. cert: {
  2075. "encode": certEncode,
  2076. "type": selectType,
  2077. "condition": selectCondition
  2078. },
  2079. device: {
  2080. "sn": Data_sn.value,
  2081. "type": parseInt(Data_type.value)
  2082. },
  2083. id: parseInt(DeleteData_id.value)
  2084. };
  2085. NetcaPKI.deleteData(params)
  2086. .Then(function(res) {
  2087. alert("删除数据成功");
  2088. })
  2089. .Catch(function(res) {
  2090. alert(res.msg);
  2091. });
  2092. }
  2093. function MacSuccessCallBack(res)
  2094. {
  2095. macDataResult.value=res.macValue;
  2096. }
  2097. function MacFailedCallBack(res)
  2098. {
  2099. alert(res.msg);
  2100. }
  2101. function macSample() {
  2102. var _macAlgo = parseInt(macAlgoId.value);
  2103. var _key = macKey.value;
  2104. var _text = utf8_to_b64(macText.value);
  2105. var _flag = parseInt(macflagId.value);
  2106. params = {
  2107. macAlgo:_macAlgo,
  2108. key: { //数据(DataParams)
  2109. hexText: _key
  2110. },
  2111. data: { //数据(DataParams)
  2112. text: _text
  2113. },
  2114. flag:_flag
  2115. };
  2116. NetcaPKI.macData(params)
  2117. .Then(function(res){
  2118. MacSuccessCallBack(res);
  2119. })
  2120. .Catch(function (res) {
  2121. MacFailedCallBack(res);
  2122. });
  2123. }
  2124. function GenerateRandom()
  2125. {
  2126. var certEncode = GenerateRandom_certEncode.value;
  2127. var selectType = "Device";
  2128. var selectCondition = "InValidty='True' && CertType='Signature'";
  2129. var params = {
  2130. cert: {
  2131. "encode": certEncode,
  2132. "type": selectType,
  2133. "condition": selectCondition
  2134. },
  2135. device: {
  2136. "sn": GenerateRandom_sn.value,
  2137. "type": parseInt(GenerateRandom_type.value)
  2138. },
  2139. length: parseInt(GenerateRandom_length.value)
  2140. };
  2141. NetcaPKI.generateRandom(params)
  2142. .Then(function(res) {
  2143. GenerateRandom_randomData.value = res.randomData;
  2144. })
  2145. .Catch(function(res) {
  2146. alert(res.msg);
  2147. });
  2148. }
  2149. function signedDataGetInfo()
  2150. {
  2151. var _signedData = SignedDataGetInfoSignature.value;
  2152. var params = {
  2153. signedData: _signedData //signedData的编码值
  2154. };
  2155. NetcaPKI.signedDataGetInfo(params)
  2156. .Then(function (res) {
  2157. SuccessSignedDataGetInfoCallBack(res);
  2158. })
  2159. .Catch(function (res) {
  2160. FailedSignedDataGetInfoCallBack(res);
  2161. })
  2162. }
  2163. function SuccessSignedDataGetInfoCallBack(res)
  2164. {
  2165. SignedDataInfo.value = "signedData解析成功\n"+JSON.stringify(res);
  2166. }
  2167. function FailedSignedDataGetInfoCallBack(res)
  2168. {
  2169. alert("signedData解析失败\n"+res.msg);
  2170. }
  2171. //获取签名域信息
  2172. function getSignatureFieldInfo() {
  2173. var _srcFile = fieldInfo_src_path.value;
  2174. var _srcBytes = fieldInfo_srcBytes.value;
  2175. var params = {
  2176. srcFile : _srcFile,
  2177. srcBytes : _srcBytes
  2178. };
  2179. NetcaPKI.getSignatureFieldInfo(params)
  2180. .Then(function(res) {
  2181. successGetSignatureFieldInfo(res);
  2182. })
  2183. .Catch(function(res) {
  2184. alert("获取签名域信息失败," + res.msg);
  2185. });
  2186. }
  2187. function successGetSignatureFieldInfo(res) {
  2188. info = "";
  2189. for(i in res.signFields)
  2190. {
  2191. index = parseInt(i)+1;
  2192. info += "第"+ index +"个签名域信息, " +
  2193. "名称:" + res.signFields[i].name +
  2194. ", 页码:" + res.signFields[i].pageNum +
  2195. ", xPos:" + res.signFields[i].xPos +
  2196. ", yPos:" + res.signFields[i].yPos +
  2197. ", width:" + res.signFields[i].width +
  2198. ", height:" + res.signFields[i].height +
  2199. "\n";
  2200. }
  2201. alert("获取签名域信息成功:\n" + info);
  2202. console.log(info);
  2203. }
  2204. function getSealConfigInfo() {
  2205. var params = {};
  2206. NetcaPKI.getSealConfigInfo(params)
  2207. .Then(function(res) {
  2208. alert("获取配置信息成功:\n" + JSON.stringify(res));
  2209. console.log(JSON.stringify(res));
  2210. })
  2211. .Catch(function(res) {
  2212. alert("获取配置信息失败," + res.msg);
  2213. });
  2214. }
  2215. function SelectSealSigntureInfoWithDispaly() {
  2216. var params = {};
  2217. NetcaPKI.selectSealSigntureInfoWithDispaly (params)
  2218. .Then(function(res) {
  2219. document.getElementById("signatureCreator_sealImageEncode").value=res.picture;
  2220. document.getElementById("signatureCreator_sealImageEncodeEx").value=res.picture;
  2221. document.getElementById("insertImage_sealImageEncode").value=res.picture;
  2222. })
  2223. .Catch(function(res) {
  2224. alert("获取印章信息失败," + res.msg);
  2225. });
  2226. }
  2227. var g_textSpirits = new Array();
  2228. function addTextSpirit()
  2229. {
  2230. var _A=parseInt(signatureCreator_appearanceFontColorAEx.value); //透明度
  2231. var _R=parseInt(signatureCreator_appearanceFontColorREx.value); //红色
  2232. var _G=parseInt(signatureCreator_appearanceFontColorGEx.value); //绿色
  2233. var _B=parseInt(signatureCreator_appearanceFontColorBEx.value); //蓝色
  2234. var textSpirit = {
  2235. textSymbol : parseInt(signatureCreator_textSymbolEx.value),
  2236. timeFormat : signatureCreator_appearanceTimeFormatEx.value,
  2237. text : signatureCreator_appearanceTextEx.value,
  2238. widthPercentage : parseFloat(signatureCreator_appearanceWidthPercentageEx.value),
  2239. heightPercentage : parseFloat(signatureCreator_appearanceHeightPercentageEx.value),
  2240. fontName : signatureCreator_appearanceFontNameEx.value,
  2241. fontSize : parseInt(signatureCreator_appearanceFontSizeEx.value),
  2242. FontColor:
  2243. {
  2244. A: _A,
  2245. R: _R,
  2246. G: _G,
  2247. B: _B
  2248. },
  2249. }
  2250. g_textSpirits.push(textSpirit);
  2251. alert("增加外观信息成功,现有"+g_textSpirits.length + "个信息");
  2252. }
  2253. function clearTextSpirit()
  2254. {
  2255. g_textSpirits = [];
  2256. alert("清空外观信息成功");
  2257. }
  2258. function kdfSuccessCallBack(res)
  2259. {
  2260. kdfDataResult.value=res.key;
  2261. alert("密钥派生成功");
  2262. }
  2263. function kdfFailedCallBack(res)
  2264. {
  2265. alert(res.msg);
  2266. }
  2267. function kdfSample() {
  2268. var _kdfAlgo = parseInt(kdfAlgoId.value);
  2269. var _keyLen = parseInt(kdfKeyLen.value);
  2270. var _flag = parseInt(kdfflagId.value);
  2271. params = {
  2272. kdfAlgo:_kdfAlgo,
  2273. pwd: { //数据(DataParams)
  2274. hexText: kdfPwd.value
  2275. },
  2276. keyLen: _keyLen,
  2277. pkcs5Params: {
  2278. hashAlgo: parseInt(kdfPkcs5Hashalgo.value),
  2279. salt: { //数据(DataParams)
  2280. hexText: kdfSalt.value
  2281. },
  2282. iterCount: parseInt(kdfPkcs5IterCount.value)
  2283. },
  2284. flag: _flag
  2285. };
  2286. NetcaPKI.kdf(params)
  2287. .Then(function(res){
  2288. kdfSuccessCallBack(res);
  2289. })
  2290. .Catch(function (res) {
  2291. kdfFailedCallBack(res);
  2292. });
  2293. }
  2294. var g_imagePositions = new Array();
  2295. function addImagePosition() {
  2296. var _imageEncode = insertImage_sealImageEncode.value;
  2297. var _pageNum = parseInt(insertImage_pageNum.value);
  2298. var _xPos = parseInt(insertImage_xPos.value);
  2299. var _yPos = parseInt(insertImage_yPos.value);
  2300. var _width = parseInt(insertImage_width.value);
  2301. var _height = parseInt(insertImage_height.value);
  2302. var imagePosition = {
  2303. imageEncode : _imageEncode,
  2304. pageNum : _pageNum,
  2305. xPos : _xPos,
  2306. yPos : _yPos,
  2307. width : _width,
  2308. height : _height
  2309. }
  2310. g_imagePositions.push(imagePosition);
  2311. alert("增加图片位置信息成功,现有"+g_imagePositions.length + "个信息");
  2312. }
  2313. function clearImagePosition() {
  2314. g_imagePositions = [];
  2315. alert("清空图片位置信息成功");
  2316. }
  2317. function insertImageSuccessCallBack(res)
  2318. {
  2319. var result = "插入图片成功, 目标文件的Base64编码:\n" + res.destFileEncode;
  2320. alert(result);
  2321. if(res.destFileEncode.length >= 20*1024*1024)
  2322. {
  2323. alert("注意:目标文件大于20M,会造成浏览器卡顿");
  2324. }
  2325. NetcaPDFSeal.preViewPDF(1, res.destFileEncode);
  2326. }
  2327. function insertImageFailedCallBack(res)
  2328. {
  2329. alert(res.msg);
  2330. }
  2331. function insertImage() {
  2332. var _srcFile = insertImage_src_path.value;
  2333. var _srcBytes = insertImage_srcBytes.value;
  2334. var _destFile = insertImage__des_path.value;
  2335. var _imagePositions = g_imagePositions;
  2336. params = {
  2337. srcFile : _srcFile,
  2338. srcBytes : _srcBytes,
  2339. destFile : _destFile,
  2340. imagePositions : _imagePositions
  2341. };
  2342. NetcaPKI.insertImage(params)
  2343. .Then(function(res){
  2344. insertImageSuccessCallBack(res);
  2345. })
  2346. .Catch(function (res) {
  2347. insertImageFailedCallBack(res);
  2348. });
  2349. }
  2350. function getPdfPageInfoSuccessCallBack(res)
  2351. {
  2352. alert("获取PDF页面信息成功:" + JSON.stringify(res));
  2353. }
  2354. function getPdfPageInfoFailedCallBack(res)
  2355. {
  2356. alert(res.msg);
  2357. }
  2358. function getPdfPageInfo()
  2359. {
  2360. var _srcFile = getPdfPageInfo_src_path.value;
  2361. var _srcBytes = getPdfPageInfo_srcBytes.value;
  2362. params = {
  2363. srcFile : _srcFile,
  2364. srcBytes : _srcBytes
  2365. };
  2366. NetcaPKI.getPdfPageInfo(params)
  2367. .Then(function(res){
  2368. getPdfPageInfoSuccessCallBack(res);
  2369. })
  2370. .Catch(function (res) {
  2371. getPdfPageInfoFailedCallBack(res);
  2372. });
  2373. }
  2374. function printPDFSuccessCallBack(res)
  2375. {
  2376. alert("打印成功");
  2377. }
  2378. function printPDFFailedCallBack(res)
  2379. {
  2380. alert(res.msg);
  2381. }
  2382. function printPDF()
  2383. {
  2384. var _srcFile = printPDF_src_path.value;
  2385. var _srcBytes = printPDF_srcBytes.value;
  2386. params = {
  2387. srcFile : _srcFile,
  2388. srcBytes : _srcBytes
  2389. };
  2390. NetcaPKI.printPDF(params)
  2391. .Then(function(res){
  2392. printPDFSuccessCallBack(res);
  2393. })
  2394. .Catch(function (res) {
  2395. printPDFFailedCallBack(res);
  2396. });
  2397. }
  2398. function batchSeal()
  2399. {
  2400. var _srcFile = signatureCreator_batchseal_src_path.value; //源Pdf文件
  2401. var _srcBytes = signatureCreator_batchseal_srcBytes.value; //源Pdf文件字节流
  2402. var _destFile = signatureCreator_batchseal_des_path.value; //目标pdf文件
  2403. var _certEncode = signatureCreator_batchseal_certEncode.value; //签名证书Base64编码
  2404. var _sealImageEncode = signatureCreator_batchseal_sealImageEncode.value;//签章图片Base64编码
  2405. var _revInfoIncludeFlag = (signatureCreator_batchseal_revInfoIncludeFlag.value == 1) ? true : false; //是否包含吊销信息
  2406. var _signaturePage = parseInt(signatureCreator_batchseal_signaturePage.value); //P电子签章所在页码
  2407. var _startPage = parseInt(signatureCreator_batchseal_startPage.value); //开始页码
  2408. var _endPage = parseInt(signatureCreator_batchseal_endPage.value); //结束页码
  2409. var _xPos = parseInt(signatureCreator_batchseal_xpos.value); //签名域/签章左下角的水平向右方向坐标
  2410. var _yPos = parseInt(signatureCreator_batchseal_ypos.value); //签名域/签章左下角的垂直向上方向坐标
  2411. var _width = parseInt(signatureCreator_batchseal_width.value); //签名域/签章的宽度
  2412. var _height = parseInt(signatureCreator_batchseal_height.value); //签名域/签章的高度
  2413. var _tsaUrl= "http://tsa.cnca.net/NETCATimeStampServer/TSAServer.jsp"; //时间戳地址
  2414. var _tsaUsr= ""; //时间戳服务对应用户名
  2415. var _tsaPwd= ""; //时间戳服务对应用户的密码
  2416. var _tsaHashAlgo= ""; //时间戳使用的hash算法,例如”sha-1”,”sha-256”等
  2417. var params = {
  2418. srcFile: _srcFile, //源pdf文件
  2419. srcBytes: _srcBytes, //源Pdf文件的Base64编码
  2420. destFile: _destFile, //目标pdf文件
  2421. certEncode: _certEncode, //签名证书Base64编码
  2422. sealImageEncode: _sealImageEncode, //签章图片Base64编码
  2423. revInfoIncludeFlag: _revInfoIncludeFlag,//是否包含吊销信息
  2424. batchSeal: //签名位置对象
  2425. {
  2426. signaturePage: _signaturePage, //电子签章所在页码
  2427. startPage: _startPage, //开始页码
  2428. endPage: _endPage, //结束页码
  2429. xPos: _xPos, //签名域/签章左下角的水平向右方向坐标
  2430. yPos: _yPos, //签名域/签章左下角的垂直向上方向坐标
  2431. width: _width, //签名域/签章的宽度
  2432. height: _height //签名域/签章的高度
  2433. },
  2434. Tsa: //时间戳对象
  2435. {
  2436. tsaUrl: _tsaUrl, //时间戳地址
  2437. tsaUsr: _tsaUsr, //时间戳服务对应用户名
  2438. tsaPwd: _tsaPwd, //时间戳服务对应用户的密码
  2439. tsaHashAlgo: _tsaHashAlgo //时间戳使用的hash算法,例如”sha-1”,”sha-256”等
  2440. }
  2441. };
  2442. NetcaPKI.batchSeal(params)
  2443. .Then(function (res)
  2444. {
  2445. SignatureCreatorBatchSealSuccessCallBack(res);
  2446. })
  2447. .Catch(function (res)
  2448. {
  2449. SignatureCreatorBatchSealFailedCallBack(res);
  2450. });
  2451. }
  2452. function SignatureCreatorBatchSealSuccessCallBack(res)
  2453. {
  2454. var result = "签名/章成功, 目标文件的Base64编码:\n" + res.destFileEncode;
  2455. alert(result);
  2456. console.log(res.destFileEncode);
  2457. if(res.destFileEncode.length >= 20*1024*1024)
  2458. {
  2459. alert("注意:目标文件大于20M,会造成浏览器卡顿");
  2460. }
  2461. NetcaPDFSeal.preViewPDF(1, res.destFileEncode);
  2462. }
  2463. function SignatureCreatorBatchSealFailedCallBack(res)
  2464. {
  2465. alert("签名/章失败 " + res.msg);
  2466. }
  2467. function acrosspageSeal()
  2468. {
  2469. var _srcFile = signatureCreator_acrosspageseal_src_path.value; //源Pdf文件
  2470. var _srcBytes = signatureCreator_acrosspageseal_srcBytes.value; //源Pdf文件字节流
  2471. var _destFile = signatureCreator_acrosspageseal_des_path.value; //目标pdf文件
  2472. var _certEncode = signatureCreator_acrosspageseal_certEncode.value; //签名证书Base64编码
  2473. var _sealImageEncode = signatureCreator_acrosspageseal_sealImageEncode.value;//签章图片Base64编码
  2474. var _revInfoIncludeFlag = (signatureCreator_acrosspageseal_revInfoIncludeFlag.value == 1) ? true : false; //是否包含吊销信息
  2475. var _signaturePage = parseInt(signatureCreator_acrosspageseal_signaturePage.value); //P电子签章所在页码
  2476. var _startPage = parseInt(signatureCreator_acrosspageseal_startPage.value); //开始页码
  2477. var _endPage = parseInt(signatureCreator_acrosspageseal_endPage.value); //结束页码
  2478. var _xPos = parseInt(signatureCreator_acrosspageseal_xpos.value); //签名域/签章左下角的水平向右方向坐标
  2479. var _yPos = parseInt(signatureCreator_acrosspageseal_ypos.value); //签名域/签章左下角的垂直向上方向坐标
  2480. var _width = parseInt(signatureCreator_acrosspageseal_width.value); //签名域/签章的宽度
  2481. var _height = parseInt(signatureCreator_acrosspageseal_height.value); //签名域/签章的高度
  2482. var _tsaUrl= "http://tsa.cnca.net/NETCATimeStampServer/TSAServer.jsp"; //时间戳地址
  2483. var _tsaUsr= ""; //时间戳服务对应用户名
  2484. var _tsaPwd= ""; //时间戳服务对应用户的密码
  2485. var _tsaHashAlgo= ""; //时间戳使用的hash算法,例如”sha-1”,”sha-256”等
  2486. var params = {
  2487. srcFile: _srcFile, //源pdf文件
  2488. srcBytes: _srcBytes, //源Pdf文件的Base64编码
  2489. destFile: _destFile, //目标pdf文件
  2490. certEncode: _certEncode, //签名证书Base64编码
  2491. sealImageEncode: _sealImageEncode, //签章图片Base64编码
  2492. revInfoIncludeFlag: _revInfoIncludeFlag,//是否包含吊销信息
  2493. acrossPageSeal: //签名位置对象
  2494. {
  2495. signaturePage: _signaturePage, //电子签章所在页码
  2496. startPage: _startPage, //开始页码
  2497. endPage: _endPage, //结束页码
  2498. xPos: _xPos, //签名域/签章左下角的水平向右方向坐标
  2499. yPos: _yPos, //签名域/签章左下角的垂直向上方向坐标
  2500. width: _width, //签名域/签章的宽度
  2501. height: _height //签名域/签章的高度
  2502. },
  2503. Tsa: //时间戳对象
  2504. {
  2505. tsaUrl: _tsaUrl, //时间戳地址
  2506. tsaUsr: _tsaUsr, //时间戳服务对应用户名
  2507. tsaPwd: _tsaPwd, //时间戳服务对应用户的密码
  2508. tsaHashAlgo: _tsaHashAlgo //时间戳使用的hash算法,例如”sha-1”,”sha-256”等
  2509. }
  2510. };
  2511. NetcaPKI.acrosspageSeal(params)
  2512. .Then(function (res)
  2513. {
  2514. SignatureCreatorAcrosspageSealSuccessCallBack(res);
  2515. })
  2516. .Catch(function (res)
  2517. {
  2518. SignatureCreatorAcrosspageSealFailedCallBack(res);
  2519. });
  2520. }
  2521. function SignatureCreatorAcrosspageSealSuccessCallBack(res)
  2522. {
  2523. var result = "签名/章成功, 目标文件的Base64编码:\n" + res.destFileEncode;
  2524. alert(result);
  2525. console.log(res.destFileEncode);
  2526. if(res.destFileEncode.length >= 20*1024*1024)
  2527. {
  2528. alert("注意:目标文件大于20M,会造成浏览器卡顿");
  2529. }
  2530. NetcaPDFSeal.preViewPDF(1, res.destFileEncode);
  2531. }
  2532. function SignatureCreatorAcrosspageSealFailedCallBack(res)
  2533. {
  2534. alert("签名/章失败 " + res.msg);
  2535. }
  2536. var g_drawtexTtextSpirits = new Array();
  2537. function graphicsProcessDrawtext_addTextSpirit()
  2538. {
  2539. var _A=parseInt(graphicsProcessDrawtext_appearanceFontColorAEx.value); //透明度
  2540. var _R=parseInt(graphicsProcessDrawtext_appearanceFontColorREx.value); //红色
  2541. var _G=parseInt(graphicsProcessDrawtext_appearanceFontColorGEx.value); //绿色
  2542. var _B=parseInt(graphicsProcessDrawtext_appearanceFontColorBEx.value); //蓝色
  2543. var textSpirit = {
  2544. text : graphicsProcessDrawtext_appearanceTextEx.value,
  2545. widthPercentage : parseFloat(graphicsProcessDrawtext_appearanceWidthPercentageEx.value),
  2546. heightPercentage : parseFloat(graphicsProcessDrawtext_appearanceHeightPercentageEx.value),
  2547. fontName : graphicsProcessDrawtext_appearanceFontNameEx.value,
  2548. fontSize : parseInt(graphicsProcessDrawtext_appearanceFontSizeEx.value),
  2549. FontColor:
  2550. {
  2551. A: _A,
  2552. R: _R,
  2553. G: _G,
  2554. B: _B
  2555. },
  2556. }
  2557. g_drawtexTtextSpirits.push(textSpirit);
  2558. alert("增加外观信息成功,现有"+g_drawtexTtextSpirits.length + "个信息");
  2559. }
  2560. function graphicsProcessDrawtext_clearTextSpirit()
  2561. {
  2562. g_drawtexTtextSpirits = [];
  2563. alert("清空外观信息成功");
  2564. }
  2565. function graphicsProcessDrawText()
  2566. {
  2567. var _srcFile = graphicsProcessDrawtext_src_path.value; //源Pdf文件路径
  2568. var _srcBytes = graphicsProcessDrawtext_srcBytes.value; //源Pdf文件字节流
  2569. var _destFile = graphicsProcessDrawtext_des_path.value; //目标pdf文件
  2570. var _autoSize = graphicsProcessDrawtext_autoSize.value=="1"?true:false;
  2571. var params = {
  2572. srcFile: _srcFile, //源pdf文件
  2573. srcBytes: _srcBytes, //源Pdf文件的Base64编码
  2574. destFile: _destFile, //目标pdf文件
  2575. AppearanceObj:
  2576. {
  2577. appearanceType:parseInt(graphicsProcessDrawtext_appearanceType.value), //外观类型
  2578. width:parseInt(graphicsProcessDrawtext_appearanceWidth.value), //外观宽度
  2579. height:parseInt(graphicsProcessDrawtext_appearanceHeight.value), //外观高度
  2580. autoSize:_autoSize, //外观高度
  2581. textSpirits:g_drawtexTtextSpirits //文本信息
  2582. }
  2583. };
  2584. NetcaPKI.graphicsProcessDrawText(params)
  2585. .Then(function (res)
  2586. {
  2587. GraphicsProcessDrawtextSuccessCallBackEx(res);
  2588. })
  2589. .Catch(function (res)
  2590. {
  2591. GraphicsProcessDrawtextFailedCallBackEx(res);
  2592. });
  2593. }
  2594. function GraphicsProcessDrawtextSuccessCallBackEx(res)
  2595. {
  2596. var result = "产生新图片成功, 目标文件的Base64编码:\n" + res.destFileEncode;
  2597. alert(result);
  2598. }
  2599. function GraphicsProcessDrawtextFailedCallBackEx(res)
  2600. {
  2601. alert("产生新图片失败 " + res.msg);
  2602. }
  2603. function writeSeal()
  2604. {
  2605. var certEncode = Seal_certEncode.value;
  2606. var selectType = "Device";
  2607. var selectCondition = "InValidity='True' && CertType='Signature'";
  2608. var params = {
  2609. cert: {
  2610. "encode": certEncode,
  2611. "type": selectType,
  2612. "condition": selectCondition
  2613. },
  2614. device: {
  2615. "sn": Seal_sn.value,
  2616. "type": parseInt(Seal_type.value)
  2617. },
  2618. seSeals: [
  2619. {
  2620. sealData: Seal_write_se_sealData.value
  2621. }
  2622. ]
  2623. };
  2624. NetcaPKI.writeSeal(params)
  2625. .Then(function(res) {
  2626. alert("写入印章成功");
  2627. })
  2628. .Catch(function(res) {
  2629. alert(res.msg);
  2630. });
  2631. }
  2632. function readSeal()
  2633. {
  2634. var certEncode = Seal_certEncode.value;
  2635. var selectType = "Device";
  2636. var selectCondition = "InValidity='True' && CertType='Signature'";
  2637. var params = {
  2638. cert: {
  2639. "encode": certEncode,
  2640. "type": selectType,
  2641. "condition": selectCondition
  2642. },
  2643. device: {
  2644. "sn": Seal_sn.value,
  2645. "type": parseInt(Seal_type.value)
  2646. }
  2647. };
  2648. NetcaPKI.readSeal(params)
  2649. .Then(function(res) {
  2650. alert("读取印章成功:" + JSON.stringify(res));
  2651. })
  2652. .Catch(function(res) {
  2653. alert(res.msg);
  2654. });
  2655. }
  2656. NetcaPKI.writeSeal=function(params){
  2657. var requestQueryParams = {};
  2658. requestQueryParams["function"] ="WriteSeal";
  2659. requestQueryParams["param"] = params;
  2660. return NetcaPKI.SendNetcaCryptoJsonRpcMessage(requestQueryParams);
  2661. }
  2662. NetcaPKI.readSeal=function(params){
  2663. var requestQueryParams = {};
  2664. requestQueryParams["function"] ="ReadSeal";
  2665. requestQueryParams["param"] = params;
  2666. return NetcaPKI.SendNetcaCryptoJsonRpcMessage(requestQueryParams);
  2667. }