appPackage.js 91 KB

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