1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989 |
- function utf8_to_b64(str) {
- return window.btoa(unescape(encodeURIComponent(str)));
- }
- function b64_to_utf8(str) {
- return decodeURIComponent(escape(window.atob(str)));
- }
- //////////////工具函数///////////////////
- function JsonToTable(json) {
- for (var key in json) {
- }
- }
- function toggleVisible(dom) {
- toggleClassName(dom.parentElement.getElementsByTagName('table')[0], 'hide');
- }
- //移除类名
- function removeClass(dom, className) {
- var temp = dom.className.split(' ');
- dom.className = ""
- for (var index in temp) {
- if (temp[index] != className) {
- dom.className += (temp[index] + ' ');
- }
- }
- }
- //添加类名
- function addClass(dom, className) {
- if (dom.className != "") {
- if (!hasClass(dom, className)) {
- dom.className += (' ' + className);
- }
- } else {
- dom.className = className;
- }
- }
- //是否含有此类名
- function hasClass(dom, className) {
- var classNames = dom.className.split(' ');
- for (var index in classNames) {
- if (classNames[index] == className) {
- return true;
- }
- }
- return false;
- }
- function toggleClassName(dom, className) {
- if (hasClass(dom, className)) {
- removeClass(dom, className);
- } else {
- addClass(dom, className);
- }
- }
- function toggleBlock(className, showElementId) {
- var collection = document.getElementsByTagName('*');
- for (var index = 0; index < collection.length; index++) {
- if (hasClass(collection[index], className)) {
- addClass(collection[index], 'hide');
- }
- }
- var showElement = document.getElementById(showElementId);
- removeClass(showElement, 'hide');
- }
- function formatPrint(outValue){
- if(outValue == null || outValue == undefined || outValue.length == 0)
- return "null";
- else
- return outValue;
- }
- function checkServiceOK()
- {
- var NETCA_ERROR_WEBSOCKETCONNECTFAIL=-11000;
- var params ={};
- NetcaPKI.checkPKIInstall(params)
- .Then(function(res)
- {
- SuccessService(res);
- })
- .Catch(function (res)
- {
- //连接失败 返回错误
- FailedService(res);
- });
- }
- function SuccessService(res)
- {
- checkVersion();
- }
- function FailedService(res)
- {
- alert(res.msg);
- }
- function getNetcaKeyId(certObj) {
- //绑定值顺序 2019-8-1
- //证书客户服务号(23)->证书实体唯一标识(36)->绑定姆印(1);*/
- if (certObj.userCertServiceId != null && certObj.userCertServiceId.length != 0) {
- return certObj.userCertServiceId;
- }
- else if (certObj.netcaSubjectUniqueId != null && certObj.netcaSubjectUniqueId.length != 0) {
- return certObj.netcaSubjectUniqueId;
- }
- else {
- return certObj.Thumbprint;
- }
- }
- function getCertListSuccess(res, comefrom)
- {
- if (res && res.deviceCount === 0) {
- toastr.error('请插入UKey获取证书');
- return;
- } else if (res.deviceCount === 1) {
- toastr.success('获取证书信息成功');
- const cert = res.certInfo[0];
- const tip = "证书主题:"+cert.subjectCN+",keyId:"+getNetcaKeyId(cert)+"\n";
- // for( s = 0; s < res.certCount; ++s)
- // {
- // const cert = res.certInfo[s];
- // tip += "证书主题:"+cert.subjectCN+",keyId:"+getNetcaKeyId(cert)+"\n";
- // }
- DeviceOutputId.value = tip;
- $('#name').val(cert.subjectCN);
- $('#keyId').val(getNetcaKeyId(cert));
- } else if (res.deviceCount === 2) {
- toastr.error('请拔出多个UKey,保留一个并获取证书信息');
- return;
- } else {
- toastr.error('获取证书失败');
- }
- }
- function getUserCert() {
- var selectType = "{\"UIFlag\":\"default\", \"InValidity\":true,\"Type\":\"signature\", \"Method\":\"device\",\"Value\":\"any\"}";
- var selectCondition = "IssuerCN~'NETCA' && InValidity='True' && CertType='Signature'";
- netca_getCertStringAttribute(null, selectType, selectCondition, -1, successGetCertEncodeCallBack,
- failedGetCertEncodeCallBack);
- }
- function successGetCertEncodeCallBack(res) {
- // alert("从key里面读取证书成功");
- data.cert_base64 = res.certCode;
- }
- function failedGetCertEncodeCallBack(res) {
- // alert(res.msg);
- toastr.error(res.msg);
- }
- function getCertListFail(res)
- {
- // alert("获取证书列表成功\n" + res.msg);
- $('#netcasign-drive').modal('show');
- }
- function getCertList()
- {
- var params={};
- NetcaPKI.GetCertList(params)
- .Then(function(res){
- getCertListSuccess(res);
- })
- .Catch(function (res) {
- getCertListFail(res);
- });
- }
- function DoClearPwdCache() {
- var params = {};
- NetcaPKI.clearPwdCache(params)
- .Then(function (res) {
- alert("清除密码缓存成功");
- })
- .Catch(function (res) {
- alert(res.msg);
- });
- }
- function publicKeyEncrypt()
- {
- var selectType = "Device";
- var selectCondition = "CertType='Encrypt'";
- switch (publicKeyEncSelectOp.value)
- {
- case 'pubkeyEnc_op1':
- var params = {
- cert: { //证书(CertificateParams)
- type: selectType,
- condition: selectCondition
- },
- data: { //数据(DataParams)
- fileName: publicKeyEncFile.value
- }
- }
- NetcaPKI.publicKeyEncrypt(params)
- .Then(function (res) {
- SuccessPublicKeyEncryptFileCallBack(res);
- })
- .Catch(function (res) {
- FailedPublicKeyEncryptFileCallBack(res);
- })
- break;
- case 'pubkeyEnc_op2':
- var params = {
- cert: { //证书(CertificateParams)
- type: selectType,
- condition: selectCondition
- },
- data: { //数据(DataParams)
- text: utf8_to_b64(publicKeyEncClearText.value)
- }};
- NetcaPKI.publicKeyEncrypt(params)
- .Then(function (res) {
- SuccessPublicKeyEncryptFileCallBack(res);
- })
- .Catch(function (res) {
- FailedPublicKeyEncryptFileCallBack(res);
- })
- break;
- }
- }
- function SuccessPublicKeyEncryptFileCallBack(res)
- {
- publicKeyEncResult.value =res.encryptValue;
- lastPublicKeyEncResult.value = res.encryptValue;
- }
- function FailedPublicKeyEncryptFileCallBack(res)
- {
- alert("公钥加密失败\n" + res.msg);
- }
- function privateKeyDecrypt()
- {
- var selectType = "Device";
- var selectCondition = "CertType='Encrypt'";
- var cipherData=lastPublicKeyEncResult.value;
- savefile=null;
- if(publicKeyDecryptFile.value.length > 0)
- {
- savefile=publicKeyDecryptFile.value;
- }
- var params = {
- cert: {
- type: selectType,
- condition: selectCondition
- },
- // algo: 0, //非对称加密算法
- encData: cipherData,
- savefileName:savefile
- };
- NetcaPKI.privateKeyDecrypt(params)
- .Then(function (res) {
- SuccessPrivateKeyDecryptCallBack(res);
- })
- .Catch(function (res) {
- FailedPrivateKeyDecryptCallBack(res);
- })
- }
- function SuccessPrivateKeyDecryptCallBack(res)
- {
- if( res.clearEncodeType == "base64" )
- {
- privateKeyDecResult.value = b64_to_utf8(res.clearValue);
- }
- else if( res.clearEncodeType == "file" )
- {
- privateKeyDecResult.value = "文件解密成功,明文文件路径:\n " + savefile;
- }
- }
- function FailedPrivateKeyDecryptCallBack(res)
- {
- alert("解密失败\n" + res.msg);
- }
- //PKCS#1 签名
- function SuccessSignCallBack(res)
- {
- p1SignResult.value = "P1签名成功,签名值:\n" + res.signValue;
- lastP1SignResult.value = res.signValue;
- }
- function FailedSignCallBack(res)
- {
- if (res.netcaCryptoCode != null && res.netcaCryptoCode == -54)
- {
- alert("P1签名失败\n" + res.msg + ":请确认签名算法和密钥是否匹配!");
- return;
- }
- alert("P1签名失败\n" + res.msg);
- }
- function signSample()
- {
- var certEncode = "";
- var selectType = "Device";
- var selectCondition = "InValidity='True' && CertType='Signature'";
- var origindata= utf8_to_b64(p1SignClearText.value);
- var signAlgo = parseInt(P1SignAlgo.value);
- var params = {
- cert: {
- "encode": certEncode,
- "type": selectType,
- "condition": selectCondition
- },
- data: {
- text: origindata
- },
- algo: signAlgo
- };
- NetcaPKI.sign(params)
- .Then(function (res) {
- SuccessSignCallBack(res);
- })
- .Catch(function (res) {
- FailedSignCallBack(res);
- });
- }
- function SuccessSignVerifyCallBack(res) {
- alert("p1验证签名成功\n" + res.certObject.certCode);
- }
- function FailedSignVerifyCallBack(res) {
- if (res.netcaCryptoCode != null && res.netcaCryptoCode == -54) {
- alert("P1验证签名失败\n" + res.msg + ":请确认签名算法和密钥是否匹配!");
- return;
- }
- alert("P1验证签名失败\n" + res.msg);
- }
- function signVerifyTest()
- {
- var certEncode = "";
- var selectType = "Device";
- var selectCondition = "InValidity='True' && CertType='Signature'";
- var origindata = utf8_to_b64(lastP1SignClearText.value);
- var signAlgo = parseInt(P1VerifySignAlgo.value);
- var signValue = lastP1SignResult.value;
- var params = {
- cert: {
- "encode": certEncode,
- "type": selectType,
- "condition": selectCondition
- },
- data: {
- text: origindata
- },
- signature:signValue,
- algo: signAlgo
- };
- NetcaPKI.verifySignature(params)
- .Then(function (res) {
- SuccessSignVerifyCallBack(res);
- })
- .Catch(function (res) {
- FailedSignVerifyCallBack(res);
- });
- }
- function signedDataSign() {
- var certEncode = "";
- var selectType = "Device";
- var selectCondition = "InValidity='True' && CertType='Signature'";
- var _certPwd = CertPwd.value;
- var tbs = utf8_to_b64(SignedDataTBS.value);
- var _useSubjectKeyId = signedDataUseSubjectKeyId.value;
- var _useQ7 = false;
- var _detached = signedDataDetach.value;
- var _tsaURL = "http://tsa.cnca.net/NETCATimeStampServer/TSAServer.jsp";
- var _includeCertOption = 2;
- var params={};
- if(_certPwd=="")
- {
- params = {
- cert: { //证书(CertificateParams)
- encode: certEncode, //可选字段但不能为空
- type: selectType,
- condition: selectCondition
- },
- data: { //数据(DataParams)
- text: tbs
- },
- useSubjectKeyId: _useSubjectKeyId, //是否使用主体密钥标识符来标识证书,默认为true
- useQ7:_useQ7, //布尔值 是否使用国密Q7的方式,默认为false
- detached: parseInt(_detached),
- tsaURL: _tsaURL,
- includeCertOption: _includeCertOption//整数 包含证书的标识
- };
- }else
- {
- params = {
- cert: { //证书(CertificateParams)
- encode: certEncode, //可选字段但不能为空
- type: selectType,
- condition: selectCondition
- },
- data: { //数据(DataParams)
- text: tbs
- },
- useSubjectKeyId: _useSubjectKeyId, //是否使用主体密钥标识符来标识证书,默认为true
- useQ7:_useQ7, //布尔值 是否使用国密Q7的方式,默认为false
- detached: parseInt(_detached),
- tsaURL: _tsaURL,
- includeCertOption: _includeCertOption,//整数 包含证书的标识
- certPwd:_certPwd
- };
- }
- NetcaPKI.signedDataSign(params)
- .Then(function (res) {
- SuccessSignedDataSignCallBack(res);
- })
- .Catch(function (res) {
- FailedSignedDataSignCallBack(res);
- })
- }
- function SuccessSignedDataSignCallBack(res)
- {
- var retSignValue = res.signValue;
- //处理base填充问题,这里去掉Base64的填充内容
- if(retSignValue!=null&&retSignValue.length>2)
- {
- var paddingCount=0;
- if(retSignValue[retSignValue.length-1]=="=")
- {
- paddingCount++;
- }
- if(retSignValue[retSignValue.length-2]=="=")
- {
- paddingCount++;
- }
- if(paddingCount>0)
- {
- //裁剪后面的=号
- retSignValue=retSignValue.substring(0,retSignValue.length-paddingCount);
- }
- }
- if(res.result==-5||res.result==-81)
- {
- retSignValue = "失败\n密码错误,密码重试次数为:"+res.retrynum;
- }
- SignedDataPVAL.value = "SignedData签名成功,签名值为:\n"+retSignValue;
- SignedDataSignature.value = retSignValue;
- SignedDataGetInfoSignature.value = retSignValue;
- }
- function FailedSignedDataSignCallBack(res)
- {
- alert("SignedData签名失败\n" + res.msg);
- }
- function signedDataVerify()
- {
- var _verifyLevel=1;//默认为1
- var _signedData = SignedDataSignature.value;
- var tbs=null;
- if (SignedDataVerifyTBS.value.length > 0 && signedDataDetach.value == "1")
- {
- tbs=utf8_to_b64(SignedDataVerifyTBS.value);
- }
- var params = {
- verifyLevel: _verifyLevel, //验证级别,默认为验证签名本身,不验证证书,默认为1
- signedData: _signedData //signedData的编码值
- };
- if (tbs != null) {
- params.originData = {
- text: tbs
- };
- }
- NetcaPKI.signedDataVerify(params)
- .Then(function (res) {
- SuccessSignedDataVerifyCallBack(res);
- })
- .Catch(function (res) {
- FailedSignedDataVerifyCallBack(res);
- })
- }
- function SuccessSignedDataVerifyCallBack(res)
- {
- alert("验证签名成功" + JSON.stringify(res));
- }
- function FailedSignedDataVerifyCallBack(res)
- {
- alert("验证签名失败"+res.msg);
- }
- function envelopedDataEncrypt() {
- var certCode = "";
- var selectType = "Device";
- var selectCondition = "CertType='Encrypt'";
- var _algo = 0;
- var _useSubjectKeyId = (envelopedDataUseSubjectKeyId.value == 1) ? true : false;
- switch (EnvelopedDataEncryptSelectOp.value) {
- case 'EnvelopedDataEncrypt_op1':
- var params = {
- cert: { //证书(CertificateParams)
- encode: certCode,
- type: selectType,
- condition: selectCondition
- },
- algo : _algo, //对称加密算法,默认为128位的AES CBC模式
- data: {
- fileName: EnvelopedDataEncryptFile.value
- },
- useSubjectKeyId : _useSubjectKeyId
- };
- NetcaPKI.envelopedDataEncrypt(params)
- .Then(function (res) {
- SuccessEnvelopedDataEncryptCallBack(res);
- })
- .Catch(function (res) {
- FailedEnvelopedDataEncryptCallBack(res);
- })
- break;
- case 'EnvelopedDataEncrypt_op2':
- var params = {
- cert: { //证书(CertificateParams)
- encode: certCode,
- type: selectType,
- condition: selectCondition
- },
- algo : _algo, //对称加密算法,默认为128位的AES CBC模式
- data: {
- text: utf8_to_b64(EnvelopedDataEncryptClearText.value)
- }
- };
- NetcaPKI.envelopedDataEncrypt(params)
- .Then(function (res) {
- SuccessEnvelopedDataEncryptCallBack(res);
- })
- .Catch(function (res) {
- FailedEnvelopedDataEncryptCallBack(res);
- })
- break;
- }
- }
- function SuccessEnvelopedDataEncryptCallBack(res){
- EnvelopedDataEncryptPVAL.value = "数字信封加密成功,密文为:\n"+res.encryptValue;
- EnvelopedDataDecryptCipher.value = res.encryptValue;
- }
- function FailedEnvelopedDataEncryptCallBack(res)
- {
- alert("数字信封加密失败\n" + res.msg);
- }
- function envelopedDataDecrypt() {
- var _encData = EnvelopedDataDecryptCipher.value;
- var _saveFile=null;//解密后如果需要使用文件保存,传入的文件路径
- if(EnvelopedDataDecryptFile.value.length > 0)
- {
- _saveFile=EnvelopedDataDecryptFile.value;
- }
- var params = {
- encData: _encData, //要解密的数据
- savefileName:_saveFile
- };
- NetcaPKI.envelopedDataDecrypt(params)
- .Then(function (res) {
- SuccessEnvDecryptCallBack(res);
- })
- .Catch(function (res) {
- FailedEnvDecryptCallBack(res);
- })
- }
- function SuccessEnvDecryptCallBack(res)
- {
- if( res.clearEncodeType == "base64" )
- {
- EnvelopedDataDecryptClearText.value = b64_to_utf8(res.clearValue);
- }
- else if( res.clearEncodeType == "file" )
- {
- EnvelopedDataDecryptClearText.value = "文件解密成功,明文文件路径为 " + EnvelopedDataDecryptFile.value;
- }
- }
- function FailedEnvDecryptCallBack(res)
- {
- alert("解密失败 " + res.msg);
- }
- function AutoSignField() {
- var _hashAlgo = "SHA-256";//例如:“sha-1”,“sha-256”
- var _srcFile = src_path_for_field.value; //源pdf文件
- var _destFile = des_path_for_field.value;
- var _revInfoIncludeFlag=false; //签名时是否包含签名证书状态信息,true包含
- var _tsaURL= "";//时间戳地址
- var _tsaUsr= ""; //时间戳服务对应用户名
- var _tsaPwd= ""; //时间戳服务对应用户的密码
- var _tsaHashAlgo= ""; //时间戳使用的hash算法,例如”sha-1”,”sha-256”等
- var _allowCertType="";
- /**
- * allowCertType为NULL或者ANY表示不进行限制。
- * RSA为RSA类型,SM2为SM2类型,ECC为ECC类型包括SM2,ECC!SM2为不包括SM2的ECC类型。
- * RSA:SM2为既包括RSA也包括SM2。
- * 默认支持RSA,SM2类型的证书。
- * 中间件 5.2版本新增的
- */
- var _selMode= select_mode.value == "0" ? 0 : 1; //选择模式,有两种:按证书选择(0)和按印章选择(1)
- var _fieldName = pdfsign_field.value;//要进行签名的签名域名称
- var params = {
- hashAlgo: _hashAlgo, //例如:“sha-1”,“sha-256”
- srcFile: _srcFile, //源pdf文件
- destFile: _destFile, //源pdf文件
- revInfoIncludeFlag: _revInfoIncludeFlag, //签名时是否包含签名证书状态信息,true包含
- selMode: _selMode, //选择模式,有两种:按证书选择(0)和按印章选择(1)
- tsaURL: _tsaURL, //时间戳地址
- tsaUsr: _tsaUsr, //时间戳服务对应用户名
- tsaPwd:_tsaPwd, //时间戳服务对应用户的密码
- tsaHashAlgo: _tsaHashAlgo, //时间戳使用的hash算法,例如”sha-1”,”sha-256”等
- allowCertType: _allowCertType,
- /**
- * allowCertType为NULL或者ANY表示不进行限制。
- * RSA为RSA类型,SM2为SM2类型,ECC为ECC类型包括SM2,ECC!SM2为不包括SM2的ECC类型。
- * RSA:SM2为既包括RSA也包括SM2。
- * 默认支持RSA,SM2类型的证书。
- * 中间件 5.2版本新增的
- */
- signField: {
- fieldName: _fieldName //要进行签名的签名域名称
- }
- };
- NetcaPKI.pdfAutoSign(params)
- .Then(function (res) {
- SignSuccessCallBack();
- })
- .Catch(function (res) {
- SignFailedCallBack(res);
- });
- }
- function AutoSignPosition() {
- var _hashAlgo = "SHA-256";//例如:“sha-1”,“sha-256”
- var _srcFile = src_path_for_position.value; //源pdf文件
- var _destFile = des_path_for_position.value;
- var _revInfoIncludeFlag=false; //签名时是否包含签名证书状态信息,true包含
- var _tsaURL= "";//时间戳地址
- var _tsaUsr= ""; //时间戳服务对应用户名
- var _tsaPwd= ""; //时间戳服务对应用户的密码
- var _tsaHashAlgo= ""; //时间戳使用的hash算法,例如”sha-1”,”sha-256”等
- var _allowCertType="";
- /**
- * allowCertType为NULL或者ANY表示不进行限制。
- * RSA为RSA类型,SM2为SM2类型,ECC为ECC类型包括SM2,ECC!SM2为不包括SM2的ECC类型。
- * RSA:SM2为既包括RSA也包括SM2。
- * 默认支持RSA,SM2类型的证书。
- * 中间件 5.2版本新增的
- */
- var _selMode= select_mode.value == "0" ? 0 : 1; //选择模式,有两种:按证书选择(0)和按印章选择(1)
- var _pageNum= parseInt(pdfSign_pageNumber.value); //输入参数,整型,PDF文档的页码,页码从1开始计算。
- var _xPos= parseInt(pdfSign_xpos.value); //输入参数,整型,签章左下角的水平向右方向坐标。
- var _yPos=parseInt(pdfSign_ypos.value); //输入参数,整型,签章左下角的垂直向上方向坐标。
- var _width= parseInt(pdfSign_seal_width.value); //输入参数,整型,签章的宽度。
- var _height=parseInt(pdfSign_seal_height.value) ;//输入参数,整型,签章的高度。
- var params = {
- hashAlgo: _hashAlgo, //例如:“sha-1”,“sha-256”
- srcFile: _srcFile, //源pdf文件
- destFile: _destFile, //源pdf文件
- revInfoIncludeFlag: _revInfoIncludeFlag, //签名时是否包含签名证书状态信息,true包含
- selMode: _selMode, //选择模式,有两种:按证书选择(0)和按印章选择(1)
- tsaURL: _tsaURL, //时间戳地址
- tsaUsr: _tsaUsr, //时间戳服务对应用户名
- tsaPwd:_tsaPwd, //时间戳服务对应用户的密码
- tsaHashAlgo: _tsaHashAlgo, //时间戳使用的hash算法,例如”sha-1”,”sha-256”等
- allowCertType: _allowCertType,
- /**
- * allowCertType为NULL或者ANY表示不进行限制。
- * RSA为RSA类型,SM2为SM2类型,ECC为ECC类型包括SM2,ECC!SM2为不包括SM2的ECC类型。
- * RSA:SM2为既包括RSA也包括SM2。
- * 默认支持RSA,SM2类型的证书。
- * 中间件 5.2版本新增的
- */
- signPosition: {
- pageNum: _pageNum, //输入参数,整型,PDF文档的页码,页码从1开始计算。
- xPos: _xPos, //输入参数,整型,签章左下角的水平向右方向坐标。
- yPos: _yPos, //输入参数,整型,签章左下角的垂直向上方向坐标。
- width: _width, //输入参数,整型,签章的宽度。
- height: _height //输入参数,整型,签章的高度。
- }
- };
- NetcaPKI.pdfAutoSign(params)
- .Then(function (res) {
- SignSuccessCallBack();
- })
- .Catch(function (res) {
- SignFailedCallBack(res);
- });
- }
- function SignSuccessCallBack()
- {
- alert("签章成功");
- }
- function SignFailedCallBack(res)
- {
- alert("签章失败 " + res.msg);
- }
- function getCertStringAttribute()
- {
- /* 从USBKey中选择NETCA 颁发的签名证书 */
- var certEncode = CertCodeText.value;
- var selectType = "";
- var selectCondition = "";
- var attId = parseInt(CertAttributeIdText.value);
- if( CertCodeText.value.length == 0 )
- {
- selectType = "Device";
- selectCondition = "IssuerCN~'NETCA' && InValidity='True' && CertType='Signature'";
- }
- var params = {
- cert: {
- "encode":certEncode,
- "type":selectType,
- "condition":selectCondition
- },
- id:attId
- };
- NetcaPKI.getCertStringAttribute(params)
- .Then(function(res){
- successGetCertStringAttributeCallBack(res);
- })
- .Catch(function (res) {
- failedGetCertStringAttributeCallBack(res);
- });
- }
- function successGetCertStringAttributeCallBack(res)
- {
- var idvalue="";
- if(CertAttributeIdText.value > 0 )
- idvalue = "id " + CertAttributeIdText.value + "对应的属性值为 " + formatPrint(res.value);
- CertCodeText.value = res.certCode;
- var tip = "证书解析成功\n" + idvalue +
- "\n公钥算法(1-RSA,2-DSA,3-DH,4-ECC)为 " + res.publicKeyAlgorithm +
- " 公钥类型(1-RSA,2-SM2,3-ECC)为 " + res.publicKeyType +
- " 公钥长度为 " + res.publicKeyBits +
- "\n颁发者为 " + formatPrint(res.issuer) +
- "\n颁发者C为 " + formatPrint(res.issuerC) +
- "\n颁发者ST为 " + formatPrint(res.issuerST) +
- "\n颁发者L为 " + formatPrint(res.issuerL) +
- "\n颁发者O为 " + formatPrint(res.issuerO) +
- "\n颁发者OU为 " + formatPrint(res.issuerOU) +
- "\n颁发者CN为 " + formatPrint(res.issuerCN) +
- "\n主体者C为 " + formatPrint(res.subjectC) +
- "\n主体ST为 " + formatPrint(res.subjectST) +
- "\n主体L为 " + formatPrint(res.subjectL) +
- "\n主体O为 " + formatPrint(res.subjectO) +
- "\n主体OU为 " + formatPrint(res.subjectOU) +
- "\n主体EMAIL为 " + formatPrint(res.subjectEmail) +
- "\n主体CN为 " + formatPrint(res.subjectCN) +
- "\n有效期开始时间为 " + formatPrint(res.validFromDate) +
- "\n有效期结束时间为 " + formatPrint(res.validToDate) +
- "\nHex编码的证书序列号为 " + formatPrint(res.serialNumber) +
- "\n密钥用法为 " + formatPrint(res.keyUsage) +
- "\n用户证书服务号为 " + formatPrint(res.userCertServiceId) +
- "\n证书类别为 " + formatPrint( res.certClassExtValue) +
- "\n深圳地标唯一标识为 " + formatPrint(res.shenzhenSubjectUniqueId) +
- "\nNETCA唯一标识为 " + formatPrint(res.netcaSubjectUniqueId)+
- "\n实施证书唯一标识 " + formatPrint(res.AppUsrCertNO);
- if(res.netcaIdentifyItemsCount==null||res.netcaIdentifyItemsCount==0)
- {
- tip+="\n个人身份标识扩展不存在";
- }
- else
- {
- tip+="\n个人身份标识编码个数: " + res.netcaIdentifyItemsCount;
- var i=0;
- for(i=0;i<res.netcaIdentifyItemsCount;++i)
- {
- tip+="\n个人身份标识编码值:"+res.netcaIdentifyItems[i];
- }
- }
- if(res.netcaEnterpriseidItemsCount==null||res.netcaEnterpriseidItemsCount==0)
- {
- tip+="\n企业机构身份标识扩展不存在";
- }
- else
- {
- tip+="\n企业机构身份标识编码个数: " + res.netcaEnterpriseidItemsCount;
- var i=0;
- for(i=0;i<res.netcaEnterpriseidItemsCount;++i)
- {
- tip+="\n企业机构身份标识编码值:"+res.netcaEnterpriseidItems[i];
- }
- }
- CertAttributeValue.value = tip;
- }
- function failedGetCertStringAttributeCallBack(res)
- {
- alert("失败\n" + res.msg);
- }
- function isInsertKey()
- {
- var _cert = CertCodeText.value;
- var _sn = keySN.value;
- var _type = parseInt(keyType.value);
- var params = {
- cert: {
- "encode":_cert
- },//可选,指定证书所在的Key是否插入
- sn:_sn, //可选
- type:_type //可选
- };
- NetcaPKI.isInsertKey(params)
- .Then(function(res){
- if (res.insertCount > 0)
- {
- InsertCallBack(res);
- }
- else
- {
- UnInsertCallBack(res);
- }
- })
- .Catch(function (res) {
- UnInsertCallBack(res);
- });
- }
- function InsertCallBack(res)
- {
- var tip = "检测是否插入key接口调用成功\n设备数量为 " + res.insertCount;
- for( s = 1; s <= res.insertCount; ++s)
- {
- var temp = "type" + s;
- tip += "\n设备" + s +"的类型为" + res[temp];
- var temp2 = "sn" + s;
- tip += " 序列号为 " + res[temp2];
- var temp3="retrynum"+s;
- tip += "密码重试次数为 " + res[temp3];
- if(s == 1 && keySN.value == "" && keyType.value == "")
- {
- keySN.value = res[temp2];
- keyType.value = res[temp];
- }
- }
- DeviceOutputId.value = tip;
- }
- function UnInsertCallBack(res)
- {
- if (res.insertCount == 0)
- DeviceOutputId.value = "检测是否插入key接口调用成功,没有发现符合条件的Key";
- else
- DeviceOutputId.value = res.msg;
- }
- function monitorDevice()
- {
- var _delayTime=0;//延迟时间,单位是毫秒,默认是0毫秒
- var params = {
- delayTime: _delayTime //延迟时间,默认为0毫秒
- };
- NetcaPKI.monitorDevice(params)
- .Then(function(res)
- {
- SuccessMonitorDeviceCallBack(res);
- })
- .Catch(function (res)
- {
- FailedMonitorDeviceCallBack(res);
- });
- }
- function SuccessMonitorDeviceCallBack(res)
- {
- if(res !=null)
- {
- var deviceType=res.type;
- var deviceStatus;
- var isPullOut=res.pullOut;
- deviceSn=res.sn;
- if(isPullOut==1)
- {
- deviceStatus="拔出";
- alert("设备序列号为:"+deviceSn+"\n设备类型为:"+deviceType+"\n设备状态为:"+deviceStatus);
- }
- else{
- deviceStatus="插入";
- alert("设备序列号为:"+deviceSn+"\n设备类型为:"+deviceType+"\n设备状态为:"+deviceStatus);
- }
- }
- }
- function FailedMonitorDeviceCallBack(res)
- {
- alert("失败\n"+res.msg);
- }
- function checkVersion()
- {
- var params ={};
- NetcaPKI.getVersionInfo(params)
- .Then(function(res)
- {
- SuccessGetVersionInfoCallBack(res);
- })
- .Catch(function (res)
- {
- FailedGetVersionInfoCallBack(res);
- });
- }
- function SuccessGetVersionInfoCallBack(res)
- {
- var versionInfo=res.VersionInfo;
- var version =res.Version;
- alert("网证通相关驱动已经成功安装\n版本号为:"+version+"\n版本号信息为:"+versionInfo+"\n版本UID为:"+res.UID);
- }
- function FailedGetVersionInfoCallBack(res)
- {
- alert("多浏览器应用插件相关文件回调失败\n" + res.msg);
- }
- function FailedGetCertOidCallBack(res) {
- alert("获取证书扩展项失败\n" + res.msg);
- }
- function SuccessGetCertOidCallBack(res) {
- if(res.isExist==0)
- {
- alert("获取证书扩展项成功,但证书没有对应的扩展项");
- return;
- }
- alert("获取证书扩展项成功\n"+ res.extensionValue);
- }
- function getCertOid() {
- var _encode = CertCodeText.value;
- var _selectType = "Device";
- var _condition = "CertType='Signature'&& InValidity='True'";
- var _oidstr = certOid.value;
- var _oidType = parseInt(certOidType.value);
- var params = {
- cert: {
- "encode":_encode,
- "type":_selectType,
- "condition":_condition
- },
- oidstr:_oidstr,
- type: _oidType
- };
- NetcaPKI.getCertStringExtensionValue(params)
- .Then(function (res) {
- SuccessGetCertOidCallBack(res);
- })
- .Catch(function (res) {
- FailedGetCertOidCallBack(res);
- });
- }
- function verifyPwd()
- {
- var _pwd = pwdId.value;
- var _encode = CertCodeText.value;
- var _sn = keySN.value;
- var _type = parseInt(keyType.value);
- var params = {
- pwd:_pwd,
- cert: {
- "encode":_encode
- },//可选,指定证书所在的Key是否插入
- sn:_sn, //可选
- type:_type //可选
- };
- NetcaPKI.verifyKeyPwd(params)
- .Then(function(res){
- if (res.result == 1)
- {
- verifySuccess(res);
- }
- else
- {
- verifyFailed(res);
- }
- })
- .Catch(function (res) {
- alert(res.msg);
- });
- }
- function verifySuccess(res)
- {
- var tip = "密码验证成功,验证的设备类型为 " + res.type +
- "; 验证的设备序列号为 " + res.sn
- + "; 密码剩余重试次数为 " + res.retrynum;
- DeviceOutputId.value = tip;
- }
- function verifyFailed(res)
- {
- var tip = "密码验证失败,错误码为" + res.result +
- "; 验证的设备类型为 " + res.type +
- "; 验证的设备序列号为 " + res.sn
- + "; 密码剩余重试次数为 " + res.retrynum;
- DeviceOutputId.value = tip;
- }
- function formatPrint(outValue){
- if(outValue == null || outValue == undefined || outValue.length == 0)
- return "null";
- else
- return outValue;
- }
- function getHardDeviceInformation()
- {
- var params ={};
- NetcaPKI.getHardDeviceInformation(params)
- .Then(function(res)
- {
- SuccessGetHardDeviceCallBack(res);
- })
- .Catch(function (res)
- {
- FailedGetHardDeviceCallBack(res);
- });
- }
- function SuccessGetHardDeviceCallBack(res)
- {
- var tip = "当前时间为 " + res.time +
- ", mac 为 " + res.mac +
- ", 硬盘序列号为 " + res.diskSN +
- ", CPUID为 " + res.cpuid +
- ", 主板序列号为 " + res.boardsn +
- ", 主板类型为 " + res.boardtype;
- alert(tip);
- }
- function FailedGetHardDeviceCallBack(res)
- {
- alert("获取硬件信息失败 " + res.msg);
- }
- function getNetworkInformation()
- {
- var params = {};
- NetcaPKI.getNetworkInformation(params)
- .Then(function(res)
- {
- SuccessGetNetworkCallBack(res);
- })
- .Catch(function(res)
- {
- FailedGetNetworkCallBack(res);
- });
- }
- function SuccessGetNetworkCallBack(res)
- {
- 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}};
- var tip = "所有网卡信息:\n";
- for(i in res.AdaptorInfo)
- {
- var adapterInfo = "{" +
- "\"Name\"=" + Base64.decode(res.AdaptorInfo[i]["Name"]) +
- ", \"Mac\"=" + res.AdaptorInfo[i]["Mac"] +
- ", \"IPV4\"=" + res.AdaptorInfo[i]["IPV4"] +
- ", \"GateWay\"=" + res.AdaptorInfo[i]["GateWay"] +
- ", DNS信息= [";
- var dnsInfo = "";
- for(j in res.AdaptorInfo[i]["DNS"])
- {
- dnsInfo += "\"DNS" + j + "\"=" + res.AdaptorInfo[i]["DNS"][j] + " ";
- }
- dnsInfo += "]}\n"
- tip = tip + adapterInfo + dnsInfo;
- }
- // "网络IP地址:" + res.InuseAdaptor.IPV4 +
- // "\n网关地址:" + res.InuseAdaptor.GateWay +
- // "\nDNS地址:" + res.InuseAdaptor.DNS;
- tip += "\n当前用户登录名:" + Base64.decode(res.LoginName) +
- "\n操作系统版本号:" + res.OSVersion;
- tip += "\n已连接wifi:{" +
- "\"Name\"=" + Base64.decode(res.ConnectedWifi["Name"]) +
- ", \"Mac\"=" + res.ConnectedWifi["Mac"] + "}";
- tip += "\n可连接的所有潜在wifi:\n";
- for(i in res.AttachableWifis)
- {
- var wifiStr = "{" +
- "\"Name\"=" + Base64.decode(res.AttachableWifis[i]["Name"]) +
- ", \"Mac\"=" + res.AttachableWifis[i]["Mac"] +
- "}\n";
- tip += wifiStr;
- }
- alert(tip);
- console.log(tip);
- }
- function FailedGetNetworkCallBack(res)
- {
- alert("获取网络信息失败:" + res.msg);
- }
- function seal_SignSealField(_selMode)
- {
- var _srcFile = signatureCreator_src_path.value; //源Pdf文件路径
- var _srcBytes = signatureCreator_srcBytes.value; //源Pdf文件字节流
- var _destFile = signatureCreator_des_path.value; //目标pdf文件
- var _certEncode = signatureCreator_certEncode.value; //签名证书Base64编码
- var _selMode = parseInt(_selMode.name); //操作模式
- var _signFieldText = signatureCreator_signFieldText.value; //签名域显示的文字
- var _sealImageEncode = signatureCreator_sealImageEncode.value;//签章图片Base64编码
- var _fieldName = signatureCreator_field.value; //签名域名称
- var _revInfoIncludeFlag = (signatureCreator_revInfoIncludeFlag.value == 1) ? true : false; //是否包含吊销信息
- var _tsaUrl= ""; //时间戳地址
- var _tsaUsr= ""; //时间戳服务对应用户名
- var _tsaPwd= ""; //时间戳服务对应用户的密码
- var _tsaHashAlgo= ""; //时间戳使用的hash算法,例如”sha-1”,”sha-256”等
- var params = {
- srcFile: _srcFile, //源pdf文件
- srcBytes: _srcBytes, //源Pdf文件的Base64编码
- destFile: _destFile, //目标pdf文件
- certEncode: _certEncode, //签名证书Base64编码
- selMode: _selMode, //操作模式
- signFieldText: _signFieldText, //签名域显示的文字
- sealImageEncode: _sealImageEncode, //签章图片Base64编码
- revInfoIncludeFlag: _revInfoIncludeFlag,//是否包含吊销信息
- SignField: //签名域对象
- {
- fieldName: _fieldName //签名域名称
- },
- Tsa: //时间戳对象
- {
- tsaUrl: _tsaUrl, //时间戳地址
- tsaUsr: _tsaUsr, //时间戳服务对应用户名
- tsaPwd: _tsaPwd, //时间戳服务对应用户的密码
- tsaHashAlgo: _tsaHashAlgo //时间戳使用的hash算法,例如”sha-1”,”sha-256”等
- }
- };
- NetcaPKI.signatureCreatorSignSeal(params)
- .Then(function (res)
- {
- SignatureCreatorSuccessCallBack(res);
- })
- .Catch(function (res)
- {
- SignatureCreatorFailedCallBack(res);
- });
- }
- function seal_SignSealPosition(_selMode)
- {
- var _srcFile = signatureCreator_src_path.value; //源Pdf文件
- var _srcBytes = signatureCreator_srcBytes.value; //源Pdf文件字节流
- var _destFile = signatureCreator_des_path.value; //目标pdf文件
- var _certEncode = signatureCreator_certEncode.value; //签名证书Base64编码
- var _selMode = parseInt(_selMode.name); //操作模式
- var _signFieldText = signatureCreator_signFieldText.value; //签名域显示的文字
- var _sealImageEncode = signatureCreator_sealImageEncode.value;//签章图片Base64编码
- var _revInfoIncludeFlag = (signatureCreator_revInfoIncludeFlag.value == 1) ? true : false; //是否包含吊销信息
- var _pageNum = parseInt(signatureCreator_pageNumber.value); //PDF文档的页码
- var _xPos = parseInt(signatureCreator_xpos.value); //签名域/签章左下角的水平向右方向坐标
- var _yPos = parseInt(signatureCreator_ypos.value); //签名域/签章左下角的垂直向上方向坐标
- var _width = parseInt(signatureCreator_width.value); //签名域/签章的宽度
- var _height = parseInt(signatureCreator_height.value); //签名域/签章的高度
- var _tsaUrl= "http://tsa.cnca.net/NETCATimeStampServer/TSAServer.jsp"; //时间戳地址
- var _tsaUsr= ""; //时间戳服务对应用户名
- var _tsaPwd= ""; //时间戳服务对应用户的密码
- var _tsaHashAlgo= ""; //时间戳使用的hash算法,例如”sha-1”,”sha-256”等
- var params = {
- srcFile: _srcFile, //源pdf文件
- srcBytes: _srcBytes, //源Pdf文件的Base64编码
- destFile: _destFile, //目标pdf文件
- certEncode: _certEncode, //签名证书Base64编码
- selMode: _selMode, //操作模式
- signFieldText: _signFieldText, //签名域显示的文字
- sealImageEncode: _sealImageEncode, //签章图片Base64编码
- revInfoIncludeFlag: _revInfoIncludeFlag,//是否包含吊销信息
- SignPosition: //签名位置对象
- {
- pageNum: _pageNum, //PDF文档的页码
- xPos: _xPos, //签名域/签章左下角的水平向右方向坐标
- yPos: _yPos, //签名域/签章左下角的垂直向上方向坐标
- width: _width, //签名域/签章的宽度
- height: _height //签名域/签章的高度
- },
- Tsa: //时间戳对象
- {
- tsaUrl: _tsaUrl, //时间戳地址
- tsaUsr: _tsaUsr, //时间戳服务对应用户名
- tsaPwd: _tsaPwd, //时间戳服务对应用户的密码
- tsaHashAlgo: _tsaHashAlgo //时间戳使用的hash算法,例如”sha-1”,”sha-256”等
- }
- };
- NetcaPKI.signatureCreatorSignSeal(params)
- .Then(function (res)
- {
- SignatureCreatorSuccessCallBack(res);
- })
- .Catch(function (res)
- {
- SignatureCreatorFailedCallBack(res);
- });
- }
- function SignatureCreatorSuccessCallBack(res)
- {
- var result = "签名/章成功, 目标文件的Base64编码:\n" + res.destFileEncode;
- alert(result);
- console.log(res.destFileEncode);
- if(res.destFileEncode.length >= 20*1024*1024)
- {
- alert("注意:目标文件大于20M,会造成浏览器卡顿");
- }
- NetcaPDFSeal.preViewPDF(1, res.destFileEncode);
- }
- function SignatureCreatorFailedCallBack(res)
- {
- alert("签名/章失败 " + res.msg);
- }
- function seal_SignSealFieldEx(selMode)
- {
- var _srcFile = signatureCreator_src_pathEx.value; //源Pdf文件路径
- var _srcBytes = signatureCreator_srcBytesEx.value; //源Pdf文件字节流
- var _destFile = signatureCreator_des_pathEx.value; //目标pdf文件
- var _certEncode = signatureCreator_certEncodeEx.value; //签名证书Base64编码
- var _selMode = parseInt(selMode.name); //操作模式
- var _signFieldText = signatureCreator_signFieldTextEx.value; //签名域显示的文字
- var _sealImageEncode = signatureCreator_sealImageEncodeEx.value;//签章图片Base64编码
- var _fieldName = signatureCreator_fieldEx.value; //签名域名称
- var _revInfoIncludeFlag = (signatureCreator_revInfoIncludeFlagEx.value == 1) ? true : false; //是否包含吊销信息
- var _tsaUrl= ""; //时间戳地址
- var _tsaUsr= ""; //时间戳服务对应用户名
- var _tsaPwd= ""; //时间戳服务对应用户的密码
- var _tsaHashAlgo= ""; //时间戳使用的hash算法,例如”sha-1”,”sha-256”等
- var _text=signatureCreator_textEx.value; //自定义文本信息
- var _timeFormat=signatureCreator_timeFormatEx.value; //日期格式
- var _widthPercentage=parseFloat(signatureCreator_widthPercentageEx.value); //宽偏移百分比
- var _heightPercentage=parseFloat(signatureCreator_heightPercentageEx.value); //高偏移百分比
- var _fontName=signatureCreator_fontNameEx.value; //字体
- var _fontSize=parseInt(signatureCreator_fontSizeEx.value); //字体大小
- var _A=parseInt(signatureCreator_fontColorAEx.value); //透明度
- var _R=parseInt(signatureCreator_fontColorREx.value); //红色
- var _G=parseInt(signatureCreator_fontColorGEx.value); //绿色
- var _B=parseInt(signatureCreator_fontColorBEx.value); //蓝色
- var params = {
- srcFile: _srcFile, //源pdf文件
- srcBytes: _srcBytes, //源Pdf文件的Base64编码
- destFile: _destFile, //目标pdf文件
- certEncode: _certEncode, //签名证书Base64编码
- selMode: _selMode, //操作模式
- signFieldText: _signFieldText, //签名域显示的文字
- sealImageEncode: _sealImageEncode, //签章图片Base64编码
- revInfoIncludeFlag: _revInfoIncludeFlag,//是否包含吊销信息
- SignField: //签名域对象
- {
- fieldName: _fieldName //签名域名称
- },
- Tsa: //时间戳对象
- {
- tsaUrl: _tsaUrl, //时间戳地址
- tsaUsr: _tsaUsr, //时间戳服务对应用户名
- tsaPwd: _tsaPwd, //时间戳服务对应用户的密码
- tsaHashAlgo: _tsaHashAlgo //时间戳使用的hash算法,例如”sha-1”,”sha-256”等
- },
- TimeObj:
- {
- text: _text, //自定义文本信息
- timeFormat: _timeFormat, //日期格式
- widthPercentage: _widthPercentage, //宽偏移百分比
- heightPercentage: _heightPercentage,//高偏移百分比
- fontName: _fontName, //字体
- fontSize: _fontSize, //字体大小
- FontColor:
- {
- A: _A,
- R: _R,
- G: _G,
- B: _B
- }
- },
- AppearanceObj:
- {
- appearanceType:parseInt(signatureCreator_appearanceType.value), //外观类型
- width:parseInt(signatureCreator_appearanceWidth.value), //外观宽度
- height:parseInt(signatureCreator_appearanceHeight.value), //外观高度
- textSpirits:g_textSpirits //文本信息
- }
- };
- NetcaPKI.SignatureCreatorSignSealEx(params)
- .Then(function (res)
- {
- SignatureCreatorSuccessCallBackEx(res);
- })
- .Catch(function (res)
- {
- SignatureCreatorFailedCallBackEx(res);
- });
- }
- function seal_SignSealPositionEx(selMode)
- {
- var _srcFile = signatureCreator_src_pathEx.value; //源Pdf文件
- var _srcBytes = signatureCreator_srcBytesEx.value; //源Pdf文件字节流
- var _destFile = signatureCreator_des_pathEx.value; //目标pdf文件
- var _certEncode = signatureCreator_certEncodeEx.value; //签名证书Base64编码
- var _selMode = parseInt(selMode.name); //操作模式
- var _signFieldText = signatureCreator_signFieldTextEx.value; //签名域显示的文字
- var _sealImageEncode = signatureCreator_sealImageEncodeEx.value;//签章图片Base64编码
- var _revInfoIncludeFlag = (signatureCreator_revInfoIncludeFlagEx.value == 1) ? true : false; //是否包含吊销信息
- var _positionStartPage = parseInt(signatureCreator_position_startPageEx.value); //PDF文档的开始页码
- var _positionEndPage = parseInt(signatureCreator_position_endPageEx.value); //PDF文档的结束页码
- var _xPos = parseInt(signatureCreator_xposEx.value); //签名域/签章左下角的水平向右方向坐标
- var _yPos = parseInt(signatureCreator_yposEx.value); //签名域/签章左下角的垂直向上方向坐标
- var _positioinWidth = parseInt(signatureCreator_position_widthEx.value); //签名域/签章的宽度
- var _positionHeight = parseInt(signatureCreator_position_heightEx.value); //签名域/签章的高度
- var _tsaUrl= ""; //时间戳地址
- var _tsaUsr= ""; //时间戳服务对应用户名
- var _tsaPwd= ""; //时间戳服务对应用户的密码
- var _tsaHashAlgo= ""; //时间戳使用的hash算法,例如”sha-1”,”sha-256”等
- var _text=signatureCreator_textEx.value; //自定义文本信息
- var _timeFormat=signatureCreator_timeFormatEx.value; //日期格式
- var _widthPercentage=parseFloat(signatureCreator_widthPercentageEx.value); //宽偏移百分比
- var _heightPercentage=parseFloat(signatureCreator_heightPercentageEx.value); //高偏移百分比
- var _fontName=signatureCreator_fontNameEx.value; //字体
- var _fontSize=parseInt(signatureCreator_fontSizeEx.value); //字体大小
- var _A=parseInt(signatureCreator_fontColorAEx.value); //透明度
- var _R=parseInt(signatureCreator_fontColorREx.value); //红色
- var _G=parseInt(signatureCreator_fontColorGEx.value); //绿色
- var _B=parseInt(signatureCreator_fontColorBEx.value); //蓝色
- var params = {
- srcFile: _srcFile, //源pdf文件
- srcBytes: _srcBytes, //源Pdf文件的Base64编码
- destFile: _destFile, //目标pdf文件
- certEncode: _certEncode, //签名证书Base64编码
- selMode: _selMode, //操作模式
- signFieldText: _signFieldText, //签名域显示的文字
- sealImageEncode: _sealImageEncode, //签章图片Base64编码
- revInfoIncludeFlag: _revInfoIncludeFlag,//是否包含吊销信息
- SignPosition: //签名位置对象
- {
- startPage: _positionStartPage, //PDF文档的开始页码
- endPage: _positionEndPage, //PDF文档的结束页码
- xPos: _xPos, //签名域/签章左下角的水平向右方向坐标
- yPos: _yPos, //签名域/签章左下角的垂直向上方向坐标
- width: _positioinWidth, //签名域/签章的宽度
- height: _positionHeight //签名域/签章的高度
- },
- Tsa: //时间戳对象
- {
- tsaUrl: _tsaUrl, //时间戳地址
- tsaUsr: _tsaUsr, //时间戳服务对应用户名
- tsaPwd: _tsaPwd, //时间戳服务对应用户的密码
- tsaHashAlgo: _tsaHashAlgo //时间戳使用的hash算法,例如”sha-1”,”sha-256”等
- },
- TimeObj:
- {
- text: _text, //自定义文本信息
- timeFormat: _timeFormat, //日期格式
- widthPercentage: _widthPercentage, //宽偏移百分比
- heightPercentage: _heightPercentage,//高偏移百分比
- fontName: _fontName, //字体
- fontSize: _fontSize, //字体大小
- FontColor:
- {
- A: _A,
- R: _R,
- G: _G,
- B: _B
- }
- },
- AppearanceObj:
- {
- appearanceType:parseInt(signatureCreator_appearanceType.value), //外观类型
- width:parseInt(signatureCreator_appearanceWidth.value), //外观宽度
- height:parseInt(signatureCreator_appearanceHeight.value), //外观高度
- textSpirits:g_textSpirits //文本信息
- }
- };
- NetcaPKI.SignatureCreatorSignSealEx(params)
- .Then(function (res)
- {
- SignatureCreatorSuccessCallBackEx(res);
- })
- .Catch(function (res)
- {
- SignatureCreatorFailedCallBackEx(res);
- });
- }
- function seal_SealKeyWord(selMode)
- {
- var _srcFile = signatureCreator_src_pathEx.value; //源Pdf文件
- var _srcBytes = signatureCreator_srcBytesEx.value; //源Pdf文件字节流
- var _destFile = signatureCreator_des_pathEx.value; //目标pdf文件
- var _certEncode = signatureCreator_certEncodeEx.value; //签名证书Base64编码
- var _selMode = parseInt(selMode.name); //操作模式
- var _signFieldText = signatureCreator_signFieldTextEx.value; //签名域显示的文字
- var _sealImageEncode = signatureCreator_sealImageEncodeEx.value;//签章图片Base64编码
- var _revInfoIncludeFlag = (signatureCreator_revInfoIncludeFlagEx.value == 1) ? true : false; //是否包含吊销信息
- var _tsaUrl= ""; //时间戳地址
- var _tsaUsr= ""; //时间戳服务对应用户名
- var _tsaPwd= ""; //时间戳服务对应用户的密码
- var _tsaHashAlgo= ""; //时间戳使用的hash算法,例如”sha-1”,”sha-256”等
- var _text=signatureCreator_textEx.value; //自定义文本信息
- var _timeFormat=signatureCreator_timeFormatEx.value; //日期格式
- var _widthPercentage=parseFloat(signatureCreator_widthPercentageEx.value); //宽偏移百分比
- var _heightPercentage=parseFloat(signatureCreator_heightPercentageEx.value); //高偏移百分比
- var _fontName=signatureCreator_fontNameEx.value; //字体
- var _fontSize=parseInt(signatureCreator_fontSizeEx.value); //字体大小
- var _A=parseInt(signatureCreator_fontColorAEx.value); //透明度
- var _R=parseInt(signatureCreator_fontColorREx.value); //红色
- var _G=parseInt(signatureCreator_fontColorGEx.value); //绿色
- var _B=parseInt(signatureCreator_fontColorBEx.value); //蓝色
- var _keyWord = signatureCreator_keyWordEx.value; //关键字
- var _keyWordStartPage = parseInt(signatureCreator_keyword_startPageEx.value); //PDF文档的开始页码
- var _keyWordEndPage = parseInt(signatureCreator_keyword_endPageEx.value); //PDF文档的开始页码
- var _keyWordIndex = parseInt(signatureCreator_keyWordIndexEx.value); //关键字索引
- var _keyWordWidth = parseInt(signatureCreator_keyword_widthEx.value); //签名域矩形的宽度
- var _keyWordHeight = parseInt(signatureCreator_keyword_heightEx.value); //签名域矩形的高度
- var _offsetX = parseInt(signatureCreator_offsetXEx.value); //水平偏移量
- var _offsetY = parseInt(signatureCreator_offsetYEx.value); //垂直偏移量
- var params = {
- srcFile: _srcFile, //源pdf文件
- srcBytes: _srcBytes, //源Pdf文件的Base64编码
- destFile: _destFile, //目标pdf文件
- certEncode: _certEncode, //签名证书Base64编码
- selMode: _selMode, //操作模式
- signFieldText: _signFieldText, //签名域显示的文字
- sealImageEncode: _sealImageEncode, //签章图片Base64编码
- revInfoIncludeFlag: _revInfoIncludeFlag,//是否包含吊销信息
- SealKeyWord: //关键字对象
- {
- keyWord: _keyWord, //关键字
- startPage: _keyWordStartPage, //PDF文档的开始页码
- endPage: _keyWordEndPage, //PDF文档的结束页码
- keyWordIndex: _keyWordIndex, //关键字索引
- width: _keyWordWidth, //签名域矩形的宽度
- height: _keyWordHeight, //签名域矩形的高度
- offsetX: _offsetX, //水平偏移量
- offsetY: _offsetY //垂直偏移量
- },
- Tsa: //时间戳对象
- {
- tsaUrl: _tsaUrl, //时间戳地址
- tsaUsr: _tsaUsr, //时间戳服务对应用户名
- tsaPwd: _tsaPwd, //时间戳服务对应用户的密码
- tsaHashAlgo: _tsaHashAlgo //时间戳使用的hash算法,例如”sha-1”,”sha-256”等
- },
- TimeObj:
- {
- text: _text, //自定义信息
- timeFormat: _timeFormat, //日期格式
- widthPercentage: _widthPercentage, //宽偏移百分比
- heightPercentage: _heightPercentage,//高偏移百分比
- fontName: _fontName, //字体
- fontSize: _fontSize, //字体大小
- FontColor:
- {
- A: _A,
- R: _R,
- G: _G,
- B: _B
- }
- },
- AppearanceObj:
- {
- appearanceType:parseInt(signatureCreator_appearanceType.value), //外观类型
- width:parseInt(signatureCreator_appearanceWidth.value), //外观宽度
- height:parseInt(signatureCreator_appearanceHeight.value), //外观高度
- textSpirits:g_textSpirits //文本信息
- }
- };
- NetcaPKI.SignatureCreatorSignSealEx(params)
- .Then(function (res)
- {
- SignatureCreatorSuccessCallBackEx(res);
- })
- .Catch(function (res)
- {
- SignatureCreatorFailedCallBackEx(res);
- });
- }
- function SignatureCreatorSuccessCallBackEx(res)
- {
- var result = "签名/章成功, 目标文件的Base64编码:\n" + res.destFileEncode;
- alert(result);
- console.log(res.destFileEncode);
- NetcaPDFSeal.preViewPDF(1, res.destFileEncode);
- }
- function SignatureCreatorFailedCallBackEx(res)
- {
- alert("签名/章失败 " + res.msg);
- }
- //获取签章软件版本号
- function seal_getVersion() {
- var params ={};
- NetcaPKI.getSealClientVersion(params)
- .Then(function(res) {
- successGetSealClientVersionCallBack(res);
- })
- .Catch(function(res) {
- failedGetSealClientVersionCallBack(res);
- });
- }
- function successGetSealClientVersionCallBack(res) {
- alert("获取签章软件版本号成功\n版本号为:" + res.version);
- }
- function failedGetSealClientVersionCallBack(res) {
- alert("获取签章软件版本号失败," + res.msg);
- }
- function HashSuccessCallBack(res)
- {
- hashDataResult.value=res.hashValue;
- }
- function HashFailedCallBack(res)
- {
- alert(res.msg);
- }
- function hashSample() {
- var _hashAlgo = parseInt(hashAlgoId.value);
- var _text = utf8_to_b64(hashText.value);
- var _flag = parseInt(hashflagId.value);
- params = {
- hashAlgo:_hashAlgo,
- data: { //数据(DataParams)
- text: _text
- },
- flag:_flag
- };
- NetcaPKI.HashData(params)
- .Then(function(res){
- HashSuccessCallBack(res);
- })
- .Catch(function (res) {
- HashFailedCallBack(res);
- });
- }
- function CipherSuccessCallBack(res)
- {
- var cipherUseEnc = cipherUseEncId.value=="1"?true:false;
- if(cipherUseEnc)
- {
- cipherResult.value=res.cipherValue;
- }
- else
- {
- cipherResult.value=b64_to_utf8(res.clearValue);
- }
- }
- function CipherFailedCallBack(res)
- {
- alert("对称加解密失败\n"+res.msg);
- }
- function cipherSample() {
- var _algo=parseInt(cipherAlgoId.value);
- var _useEnc = cipherUseEncId.value=="1"?true:false;
- var _text ;
- if(_useEnc==1)
- {
- _text=utf8_to_b64(cipherData.value);
- }
- else
- {
- _text=cipherData.value;
- }
- var _hexText = cipherKeyId.value;
- params = {
- algo:_algo,
- data: { //数据(DataParams)
- text: _text
- },
- key: { //数据(DataParams)
- hexText: _hexText
- },
- useEnc:_useEnc
- };
- NetcaPKI.cipher(params)
- .Then(function(res){
- CipherSuccessCallBack(res);
- })
- .Catch(function (res) {
- CipherFailedCallBack(res);
- });
- }
- //验证证书
- function verifyCertificate() {
- var _certEncode = VerifyCertificate_certEncode.value;
- var _bUseCrl = (VerifyCertificateverify_crlFlag.value == 1) ? true : false;
- var _bUseOcsp = (VerifyCertificate_ocspFlag.value == 1) ? true : false;
- var _crlEncode = VerifyCertificate_crlEncode.value;
- var _ocspUrl = VerifyCertificate_ocspUrl.value;
- var _time = VerifyCertificate_time.value;
- var params = {
- cert : {
- "encode" : _certEncode
- },
- bUseCrl: _bUseCrl,
- bUseOcsp: _bUseOcsp,
- crlEncode: _crlEncode,
- ocspUrl: _ocspUrl,
- time: _time
- };
- NetcaPKI.verifyCertificate(params)
- .Then(function(res) {
- successVerifyCertificateCallBack(res);
- })
- .Catch(function(res) {
- failedVerifyCertificateCallBack(res);
- });
- }
- function successVerifyCertificateCallBack(res) {
- alert("验证成功," + res.info);
- }
- function failedVerifyCertificateCallBack(res) {
- alert("验证失败," + res.msg);
- }
- //验证签名PDF
- function seal_verifySignPDF() {
- var _srcFile = signatureVerifierVerify_src_path.value;
- var _srcBytes = signatureVerifierVerify_srcBytes.value;
- var _level = parseInt(signatureVerifier_level.value);
- var params = {
- srcFile : _srcFile,
- srcBytes : _srcBytes,
- level : _level
- };
- NetcaPKI.signatureVerifierVerifyPDF(params)
- .Then(function(res) {
- successSignatureVerifierVerifyPDF(res);
- })
- .Catch(function(res) {
- failedSignatureVerifierVerifyPDF(res);
- });
- }
- function successSignatureVerifierVerifyPDF(res) {
- info = "";
- for(i in res.VerifyInfos)
- {
- index = parseInt(i)+1;
- info += "第"+ index +"个签名信息, " +
- res.VerifyInfos[i].status +
- ", 签名者:" + res.VerifyInfos[i].signerName +
- ", 签名域:" + res.VerifyInfos[i].fieldName +
- ", 签名证书:" + res.VerifyInfos[i].certEncode +
- ", 签名摘要算法:" + res.VerifyInfos[i].hashAlgo +
- ", 签名创建日期:" + res.VerifyInfos[i].signDate;
- if(res.VerifyInfos[i].hasRevoke)
- {
- info += ",存在吊销信息" +
- ", 证书吊销状态:" + res.VerifyInfos[i].revokeStatus;
- }
- else
- {
- info += ",不存在吊销信息";
- }
- if(res.VerifyInfos[i].hasTsa)
- {
- info += ", 存在时间戳信息";
- }
- else
- {
- info += ", 不存在时间戳信息";
- }
- if(res.VerifyInfos[i].isTsaValid)
- {
- info += ", 时间戳有效";
- }
- else
- {
- info += ", 时间戳无效";
- }
- info += ", 时间戳日期:" + res.VerifyInfos[i].tsaDate + "\n";
- }
- alert("验证证书成功:" + info);
- console.log(info);
- }
- function failedSignatureVerifierVerifyPDF(res) {
- alert("验证失败," + res.msg);
- }
- //撤销签名/章
- function seal_undoSignPDF() {
- var _signFile = signatureVerifierUndo_src_path.value;
- var _signBytes = signatureVerifierUndo_srcBytes.value;
- var _index = parseInt(signatureVerifierUndo_index.value);
- var params = {
- signFile : _signFile,
- signBytes : _signBytes,
- index : _index
- };
- NetcaPKI.signatureVerifierUndoPDF(params)
- .Then(function(res) {
- successSignatureVerifierUndoPDF(res);
- })
- .Catch(function(res) {
- failedSignatureVerifierUndoPDF(res);
- });
- }
- function successSignatureVerifierUndoPDF(res) {
- alert("撤销成功,原文base64编码:" + res.srcBytes);
- console.log(res.srcBytes);
- document.getElementById("signatureVerifierUndo_destBytes").value = res.srcBytes;
- }
- function failedSignatureVerifierUndoPDF(res) {
- alert("撤销失败," + res.msg);
- }
- function showNetcaAAVerifyStatusMsg(res)
- {
- if(res.certVerifyStatus=="0")
- {
- alert("验证证书有效");
- }
- else if(res.certVerifyStatus=="1")
- {
- alert("验证处理失败");
- }
- else if(res.certVerifyStatus=="2")
- {
- alert("证书格式有误");
- }
- else if(res.certVerifyStatus=="3")
- {
- alert("证书不在有效期内");
- }
- else if(res.certVerifyStatus=="4")
- {
- alert("密钥用途不合(KU和EKU)");
- }
- else if(res.certVerifyStatus=="5")
- {
- alert("证书名字不合(DN和SAN)");
- }
- else if(res.certVerifyStatus=="6")
- {
- alert("证书策略不合(取决于CVS的配置)");
- }
- else if(res.certVerifyStatus=="7")
- {
- alert("证书扩展不合(取决于CVS的配置)");
- }
- else if(res.certVerifyStatus=="8")
- {
- alert("证书链验证失败(包括了签名检查;基本约束检查;名字约束检查;策略约束检查;ACL检查等)");
- }
- else if(res.certVerifyStatus=="9")
- {
- alert("证书被注销");
- }
- else if(res.certVerifyStatus=="10")
- {
- alert("注销状态不能确定(如果设置了已过期的CRL或OCSP无法连接)");
- }
- else if(res.certVerifyStatus=="11")
- {
- alert("证书不受信任/未被授权");
- }
- else if(res.certVerifyStatus=="12")
- {
- alert("证书被暂时锁定/未激活");
- }
- else
- {
- alert("证书验证失败");
- }
- }
- function netcaaaverifycertsuccess(res)
- {
- netcaaaResult.value=JSON.stringify(res);
- showNetcaAAVerifyStatusMsg(res);
- }
- function netcaaaverifycertfail(res)
- {
- alert("验证证书失败:" + res.msg);
- }
- function netcaaa_verifycert_example()
- {
- /* 从USBKey中选择NETCA 颁发的签名证书 */
- var _url = netcaaaurl.value;
- var _verifytime = "";
- var _encode="";
- var _type = "";
- var _condition = "";
- //如果是输入的证书编码 可以直接射设置certEncode值
- if( netcaaacert.value.length != 0 )
- {
- _encode=netcaaacert.value;
- }
- else
- {
- _type = "{\"UIFlag\":\"default\", \"InValidity\":true,\"Type\":\"signature\", \"Method\":\"device\",\"Value\":\"any\"}";
- _condition = "IssuerCN~'NETCA' && InValidity='True' && CertType='Signature'";
- }
- var params = {
- url:_url,
- verifytime : _verifytime,
- cert: { //证书(CertificateParams)
- encode: _encode,
- type: _type,
- condition: _condition
- }
- };
- NetcaPKI.netcaAA_VerifyUserCert(params)
- .Then(function(res) {
- netcaaaverifycertsuccess(res);
- })
- .Catch(function(res) {
- netcaaaverifycertfail(res);
- });
- }
- function netcaaachkonecertsuccess(res)
- {
- netcaaachkonecertResult.value=JSON.stringify(res);
- showNetcaAAVerifyStatusMsg(res);
- }
- function netcaaachkonecertfail(res)
- {
- alert("验证证书失败:" + res.msg);
- }
- function netcaaachk_chkonecert_example()
- {
- /* 从USBKey中选择NETCA 颁发的签名证书 */
- var _url = netcaaachkonecerturl.value;
- var _encode = "";
- var _type = "";
- var _condition = "";
- //如果是输入的证书编码 可以直接射设置certEncode值
- if( netcaaachkonecert.value.length != 0 )
- {
- _encode=netcaaachkonecert.value;
- }
- else
- {
- _type = "{\"UIFlag\":\"default\", \"InValidity\":true,\"Type\":\"signature\", \"Method\":\"device\",\"Value\":\"any\"}";
- _condition = "IssuerCN~'NETCA' && InValidity='True' && CertType='Signature'";
- }
- var params = {
- url:_url,
- cert: { //证书(CertificateParams)
- encode: _encode,
- type: _type,
- condition: _condition
- }
- };
- NetcaPKI.netcaAA_ChkOneCert(params)
- .Then(function(res) {
- netcaaachkonecertsuccess(res);
- })
- .Catch(function(res) {
- netcaaachkonecertfail(res);
- });
- }
- function modifyPwd()
- {
- var _sn = keySN.value;
- var _type = parseInt(keyType.value);
- var _oldPwd = oldPwd.value;
- var _newPwd = modify_newPwd.value;
- var params = {
- sn: _sn,
- type: _type,
- oldPwd: _oldPwd,
- newPwd: _newPwd
- };
- NetcaPKI.modifyKeyPwd(params)
- .Then(function(res){
- if (res.result == 1)
- {
- modifySuccess(res);
- }
- else
- {
- modifyFailed(res);
- }
- })
- .Catch(function (res) {
- alert(res.msg);
- });
- }
- function modifySuccess(res)
- {
- var tip = "密码修改成功,密码剩余重试次数为" + res.retrynum;
- DeviceOutputId.value = tip;
- }
- function modifyFailed(res)
- {
- var tip = "密码修改失败,密码剩余重试次数为" + res.retrynum + ",错误码=" + res.result;
- DeviceOutputId.value = tip;
- }
- function unlockPwd()
- {
- var _sn = keySN.value;
- var _type = parseInt(keyType.value);
- var _unlockPwd = unlock_unlockPwd.value;
- var _newPwd = unlock_newPwd.value;
- var params = {
- sn: _sn,
- type: parseInt(_type),
- unlockPwd: _unlockPwd,
- newPwd: _newPwd
- };
- NetcaPKI.unlockKeyPwd(params)
- .Then(function(res){
- if (res.result == 1)
- {
- unlockSuccess(res);
- }
- else
- {
- unlockFailed(res);
- }
- })
- .Catch(function (res) {
- alert(res.msg);
- });
- }
- function unlockSuccess(res)
- {
- var tip = "密码解锁成功,密码剩余重试次数为" + res.retrynum;
- DeviceOutputId.value = tip;
- }
- function unlockFailed(res)
- {
- var tip = "密码解锁失败,密码剩余重试次数为" + res.retrynum + ",错误码=" + res.result;
- DeviceOutputId.value = tip;
- }
- function generateP10()
- {
- var _sn = GenerateP10_sn.value;
- var _type = parseInt(GenerateP10_type.value);
- var _useKeypair = (GenerateP10_useKeypairFlag.value == 1)? true : false;
- var _keypairAlgo = parseInt(GenerateP10_keypairAlgo.value);
- var _keypairLabel = GenerateP10_keypairLabel.value;
- var _keypairBits = parseInt(GenerateP10_keypairBits.value);
- var _signAlgo = parseInt(GenerateP10_signAlgo.value);
- var _c = GenerateP10_c.value;
- var _st = GenerateP10_st.value;
- var _l = GenerateP10_l.value;
- var _o = GenerateP10_o.value;
- var _email = GenerateP10_email.value;
- var _ou = GenerateP10_ou.value;
- var _cn = GenerateP10_cn.value;
- var params = {
- sn: _sn,
- type: parseInt(_type),
- useKeypair: _useKeypair,
- keypairAlgo: parseInt(_keypairAlgo),
- keypairLabel: _keypairLabel,
- keypairBits: parseInt(_keypairBits),
- signAlgo: parseInt(_signAlgo),
- SubjectObj : {
- c: _c,
- st: _st,
- l: _l,
- o: _o,
- email: _email,
- ou: _ou,
- cn: _cn
- }
- };
- NetcaPKI.generateP10(params)
- .Then(function(res) {
- generateP10Success(res);
- })
- .Catch(function(res) {
- generateP10Failed(res);
- });
- }
- function generateP10Success(res)
- {
- alert("产生证书请求成功,编码:" + res.certReq);
- console.log(res.certReq);
- }
- function generateP10Failed(res)
- {
- alert("产生证书请求失败," + res.msg);
- }
- function installCertificate()
- {
- var _sn = InstallCertificate_sn.value;
- var _type = InstallCertificate_type.value;
- var _encKeypair = InstallCertificate_encKeypairEncode.value;
- var _encCert = InstallCertificate_encCertEncode.value;
- var _signCert = InstallCertificate_signCertEncode.value;
- var params = {
- sn: _sn,
- type: parseInt(_type),
- encKeypair: _encKeypair,
- encCert: _encCert,
- signCert: _signCert
- };
- NetcaPKI.installCertificate(params)
- .Then(function(res) {
- installCertificateSuccess(res);
- })
- .Catch(function(res) {
- installCertificateFailed(res);
- });
- }
- function installCertificateSuccess(res)
- {
- alert("安装证书成功");
- }
- function installCertificateFailed(res)
- {
- alert("安装证书失败:" + res.msg);
- }
- function getNetcaSealImage(certEncode) {
- var params = {
- "cert":{
- "encode":certEncode
- }
- };
- NetcaPKI.getNetcaSealImage(params)
- .Then(function(res){
- GetNetcaSealImageSuccessCallBack(res);
- })
- .Catch(function (res) {
- GetNetcaSealImageFailCallBack(res);
- });
- }
- function GetNetcaSealImageSuccessCallBack(res)
- {
- alert("获取签章图片成功!");
- alert(res.sealImageBase64);
- console.log(res.sealImageBase64);
- }
- function GetNetcaSealImageFailCallBack(res)
- {
- alert(res.msg);
- }
- function uIDisplayCert()
- {
- var certEncode = DeviceOutputId.value;
- var selectType = "Device";
- var selectCondition = "InValidity='True' && CertType='Signature'";
- var params = {
- cert: {
- "encode": certEncode,
- "type": selectType,
- "condition": selectCondition
- }
- };
- NetcaPKI.displayCert(params)
- .Then(function(res){
- alert("证书显示成功");
- })
- .Catch(function (res) {
- alert(res.msg);
- });
- }
- function createData()
- {
- var certEncode = Data_certEncode.value;
- var selectType = "Device";
- var selectCondition = "InValidty='True' && CertType='Signature'";
- var params = {
- cert: {
- "encode": certEncode,
- "type": selectType,
- "condition": selectCondition
- },
- device: {
- "sn": Data_sn.value,
- "type": parseInt(Data_type.value)
- },
- id: parseInt(CreateData_id.value),
- noVerifyPermission: {
- canRead: ((CreateData_noVerifyPermission_canRead.value == 1) ? true : false),
- canWrite: ((CreateData_noVerifyPermission_canWrite.value == 1) ? true : false),
- canDelete: ((CreateData_noVerifyPermission_canDelete.value == 1) ? true : false)
- },
- verifyUserPermission: {
- canRead: ((CreateData_verifyUserPermission_canRead.value == 1) ? true : false),
- canWrite: ((CreateData_verifyUserPermission_canWrite.value == 1) ? true : false),
- canDelete: ((CreateData_verifyUserPermission_canDelete.value == 1) ? true : false)
- },
- length: parseInt(CreateData_length.value)
- };
- NetcaPKI.createData(params)
- .Then(function(res) {
- alert("创建数据成功");
- })
- .Catch(function(res) {
- alert(res.msg);
- });
- }
- function readData()
- {
- var certEncode = Data_certEncode.value;
- var selectType = "Device";
- var selectCondition = "InValidty='True' && CertType='Signature'";
- var params = {
- cert: {
- "encode": certEncode,
- "type": selectType,
- "condition": selectCondition
- },
- device: {
- "sn": Data_sn.value,
- "type": parseInt(Data_type.value)
- },
- id: parseInt(ReadData_id.value),
- offset: parseInt(ReadData_offset.value),
- length: parseInt(ReadData_length.value)
- };
- NetcaPKI.readData(params)
- .Then(function(res) {
- alert("读取数据成功");
- ReadData_data.value = res.data;
- })
- .Catch(function(res) {
- alert(res.msg);
- });
- }
- function writeData()
- {
- var certEncode = Data_certEncode.value;
- var selectType = "Device";
- var selectCondition = "InValidty='True' && CertType='Signature'";
- var params = {
- cert: {
- "encode": certEncode,
- "type": selectType,
- "condition": selectCondition
- },
- device: {
- "sn": Data_sn.value,
- "type": parseInt(Data_type.value)
- },
- id: parseInt(WriteData_id.value),
- offset: parseInt(WriteData_offset.value),
- data: { //数据(DataParams)
- text: WriteData_data.value
- }
- };
- NetcaPKI.writeData(params)
- .Then(function(res) {
- alert("写入数据成功");
- })
- .Catch(function(res) {
- alert(res.msg);
- });
- }
- function deleteData()
- {
- var certEncode = Data_certEncode.value;
- var selectType = "Device";
- var selectCondition = "InValidty='True' && CertType='Signature'";
- var params = {
- cert: {
- "encode": certEncode,
- "type": selectType,
- "condition": selectCondition
- },
- device: {
- "sn": Data_sn.value,
- "type": parseInt(Data_type.value)
- },
- id: parseInt(DeleteData_id.value)
- };
- NetcaPKI.deleteData(params)
- .Then(function(res) {
- alert("删除数据成功");
- })
- .Catch(function(res) {
- alert(res.msg);
- });
- }
- function MacSuccessCallBack(res)
- {
- macDataResult.value=res.macValue;
- }
- function MacFailedCallBack(res)
- {
- alert(res.msg);
- }
- function macSample() {
- var _macAlgo = parseInt(macAlgoId.value);
- var _key = macKey.value;
- var _text = utf8_to_b64(macText.value);
- var _flag = parseInt(macflagId.value);
- params = {
- macAlgo:_macAlgo,
- key: { //数据(DataParams)
- hexText: _key
- },
- data: { //数据(DataParams)
- text: _text
- },
- flag:_flag
- };
- NetcaPKI.macData(params)
- .Then(function(res){
- MacSuccessCallBack(res);
- })
- .Catch(function (res) {
- MacFailedCallBack(res);
- });
- }
- function GenerateRandom()
- {
- var certEncode = GenerateRandom_certEncode.value;
- var selectType = "Device";
- var selectCondition = "InValidty='True' && CertType='Signature'";
- var params = {
- cert: {
- "encode": certEncode,
- "type": selectType,
- "condition": selectCondition
- },
- device: {
- "sn": GenerateRandom_sn.value,
- "type": parseInt(GenerateRandom_type.value)
- },
- length: parseInt(GenerateRandom_length.value)
- };
- NetcaPKI.generateRandom(params)
- .Then(function(res) {
- GenerateRandom_randomData.value = res.randomData;
- })
- .Catch(function(res) {
- alert(res.msg);
- });
- }
- function signedDataGetInfo()
- {
- var _signedData = SignedDataGetInfoSignature.value;
- var params = {
- signedData: _signedData //signedData的编码值
- };
- NetcaPKI.signedDataGetInfo(params)
- .Then(function (res) {
- SuccessSignedDataGetInfoCallBack(res);
- })
- .Catch(function (res) {
- FailedSignedDataGetInfoCallBack(res);
- })
- }
- function SuccessSignedDataGetInfoCallBack(res)
- {
- SignedDataInfo.value = "signedData解析成功\n"+JSON.stringify(res);
- }
- function FailedSignedDataGetInfoCallBack(res)
- {
- alert("signedData解析失败\n"+res.msg);
- }
- //获取签名域信息
- function getSignatureFieldInfo() {
- var _srcFile = fieldInfo_src_path.value;
- var _srcBytes = fieldInfo_srcBytes.value;
- var params = {
- srcFile : _srcFile,
- srcBytes : _srcBytes
- };
- NetcaPKI.getSignatureFieldInfo(params)
- .Then(function(res) {
- successGetSignatureFieldInfo(res);
- })
- .Catch(function(res) {
- alert("获取签名域信息失败," + res.msg);
- });
- }
- function successGetSignatureFieldInfo(res) {
- info = "";
- for(i in res.signFields)
- {
- index = parseInt(i)+1;
- info += "第"+ index +"个签名域信息, " +
- "名称:" + res.signFields[i].name +
- ", 页码:" + res.signFields[i].pageNum +
- ", xPos:" + res.signFields[i].xPos +
- ", yPos:" + res.signFields[i].yPos +
- ", width:" + res.signFields[i].width +
- ", height:" + res.signFields[i].height +
- "\n";
- }
- alert("获取签名域信息成功:\n" + info);
- console.log(info);
- }
- function getSealConfigInfo() {
- var params = {};
- NetcaPKI.getSealConfigInfo(params)
- .Then(function(res) {
- alert("获取配置信息成功:\n" + JSON.stringify(res));
- console.log(JSON.stringify(res));
- })
- .Catch(function(res) {
- alert("获取配置信息失败," + res.msg);
- });
- }
- function SelectSealSigntureInfoWithDispaly() {
- var params = {};
- NetcaPKI.selectSealSigntureInfoWithDispaly (params)
- .Then(function(res) {
- document.getElementById("signatureCreator_sealImageEncode").value=res.picture;
- document.getElementById("signatureCreator_sealImageEncodeEx").value=res.picture;
- document.getElementById("insertImage_sealImageEncode").value=res.picture;
- })
- .Catch(function(res) {
- alert("获取印章信息失败," + res.msg);
- });
- }
- var g_textSpirits = new Array();
- function addTextSpirit()
- {
- var _A=parseInt(signatureCreator_appearanceFontColorAEx.value); //透明度
- var _R=parseInt(signatureCreator_appearanceFontColorREx.value); //红色
- var _G=parseInt(signatureCreator_appearanceFontColorGEx.value); //绿色
- var _B=parseInt(signatureCreator_appearanceFontColorBEx.value); //蓝色
- var textSpirit = {
- textSymbol : parseInt(signatureCreator_textSymbolEx.value),
- timeFormat : signatureCreator_appearanceTimeFormatEx.value,
- text : signatureCreator_appearanceTextEx.value,
- widthPercentage : parseFloat(signatureCreator_appearanceWidthPercentageEx.value),
- heightPercentage : parseFloat(signatureCreator_appearanceHeightPercentageEx.value),
- fontName : signatureCreator_appearanceFontNameEx.value,
- fontSize : parseInt(signatureCreator_appearanceFontSizeEx.value),
- FontColor:
- {
- A: _A,
- R: _R,
- G: _G,
- B: _B
- },
- }
- g_textSpirits.push(textSpirit);
- alert("增加外观信息成功,现有"+g_textSpirits.length + "个信息");
- }
- function clearTextSpirit()
- {
- g_textSpirits = [];
- alert("清空外观信息成功");
- }
- function kdfSuccessCallBack(res)
- {
- kdfDataResult.value=res.key;
- alert("密钥派生成功");
- }
- function kdfFailedCallBack(res)
- {
- alert(res.msg);
- }
- function kdfSample() {
- var _kdfAlgo = parseInt(kdfAlgoId.value);
- var _keyLen = parseInt(kdfKeyLen.value);
- var _flag = parseInt(kdfflagId.value);
- params = {
- kdfAlgo:_kdfAlgo,
- pwd: { //数据(DataParams)
- hexText: kdfPwd.value
- },
- keyLen: _keyLen,
- pkcs5Params: {
- hashAlgo: parseInt(kdfPkcs5Hashalgo.value),
- salt: { //数据(DataParams)
- hexText: kdfSalt.value
- },
- iterCount: parseInt(kdfPkcs5IterCount.value)
- },
- flag: _flag
- };
- NetcaPKI.kdf(params)
- .Then(function(res){
- kdfSuccessCallBack(res);
- })
- .Catch(function (res) {
- kdfFailedCallBack(res);
- });
- }
- var g_imagePositions = new Array();
- function addImagePosition() {
- var _imageEncode = insertImage_sealImageEncode.value;
- var _pageNum = parseInt(insertImage_pageNum.value);
- var _xPos = parseInt(insertImage_xPos.value);
- var _yPos = parseInt(insertImage_yPos.value);
- var _width = parseInt(insertImage_width.value);
- var _height = parseInt(insertImage_height.value);
- var imagePosition = {
- imageEncode : _imageEncode,
- pageNum : _pageNum,
- xPos : _xPos,
- yPos : _yPos,
- width : _width,
- height : _height
- }
- g_imagePositions.push(imagePosition);
- alert("增加图片位置信息成功,现有"+g_imagePositions.length + "个信息");
- }
- function clearImagePosition() {
- g_imagePositions = [];
- alert("清空图片位置信息成功");
- }
- function insertImageSuccessCallBack(res)
- {
- var result = "插入图片成功, 目标文件的Base64编码:\n" + res.destFileEncode;
- alert(result);
- if(res.destFileEncode.length >= 20*1024*1024)
- {
- alert("注意:目标文件大于20M,会造成浏览器卡顿");
- }
- NetcaPDFSeal.preViewPDF(1, res.destFileEncode);
- }
- function insertImageFailedCallBack(res)
- {
- alert(res.msg);
- }
- function insertImage() {
- var _srcFile = insertImage_src_path.value;
- var _srcBytes = insertImage_srcBytes.value;
- var _destFile = insertImage__des_path.value;
- var _imagePositions = g_imagePositions;
- params = {
- srcFile : _srcFile,
- srcBytes : _srcBytes,
- destFile : _destFile,
- imagePositions : _imagePositions
- };
- NetcaPKI.insertImage(params)
- .Then(function(res){
- insertImageSuccessCallBack(res);
- })
- .Catch(function (res) {
- insertImageFailedCallBack(res);
- });
- }
- function getPdfPageInfoSuccessCallBack(res)
- {
- alert("获取PDF页面信息成功:" + JSON.stringify(res));
- }
- function getPdfPageInfoFailedCallBack(res)
- {
- alert(res.msg);
- }
- function getPdfPageInfo()
- {
- var _srcFile = getPdfPageInfo_src_path.value;
- var _srcBytes = getPdfPageInfo_srcBytes.value;
- params = {
- srcFile : _srcFile,
- srcBytes : _srcBytes
- };
- NetcaPKI.getPdfPageInfo(params)
- .Then(function(res){
- getPdfPageInfoSuccessCallBack(res);
- })
- .Catch(function (res) {
- getPdfPageInfoFailedCallBack(res);
- });
- }
- function printPDFSuccessCallBack(res)
- {
- alert("打印成功");
- }
- function printPDFFailedCallBack(res)
- {
- alert(res.msg);
- }
- function printPDF()
- {
- var _srcFile = printPDF_src_path.value;
- var _srcBytes = printPDF_srcBytes.value;
- params = {
- srcFile : _srcFile,
- srcBytes : _srcBytes
- };
- NetcaPKI.printPDF(params)
- .Then(function(res){
- printPDFSuccessCallBack(res);
- })
- .Catch(function (res) {
- printPDFFailedCallBack(res);
- });
- }
- function batchSeal()
- {
- var _srcFile = signatureCreator_batchseal_src_path.value; //源Pdf文件
- var _srcBytes = signatureCreator_batchseal_srcBytes.value; //源Pdf文件字节流
- var _destFile = signatureCreator_batchseal_des_path.value; //目标pdf文件
- var _certEncode = signatureCreator_batchseal_certEncode.value; //签名证书Base64编码
- var _sealImageEncode = signatureCreator_batchseal_sealImageEncode.value;//签章图片Base64编码
- var _revInfoIncludeFlag = (signatureCreator_batchseal_revInfoIncludeFlag.value == 1) ? true : false; //是否包含吊销信息
- var _signaturePage = parseInt(signatureCreator_batchseal_signaturePage.value); //P电子签章所在页码
- var _startPage = parseInt(signatureCreator_batchseal_startPage.value); //开始页码
- var _endPage = parseInt(signatureCreator_batchseal_endPage.value); //结束页码
- var _xPos = parseInt(signatureCreator_batchseal_xpos.value); //签名域/签章左下角的水平向右方向坐标
- var _yPos = parseInt(signatureCreator_batchseal_ypos.value); //签名域/签章左下角的垂直向上方向坐标
- var _width = parseInt(signatureCreator_batchseal_width.value); //签名域/签章的宽度
- var _height = parseInt(signatureCreator_batchseal_height.value); //签名域/签章的高度
- var _tsaUrl= "http://tsa.cnca.net/NETCATimeStampServer/TSAServer.jsp"; //时间戳地址
- var _tsaUsr= ""; //时间戳服务对应用户名
- var _tsaPwd= ""; //时间戳服务对应用户的密码
- var _tsaHashAlgo= ""; //时间戳使用的hash算法,例如”sha-1”,”sha-256”等
- var params = {
- srcFile: _srcFile, //源pdf文件
- srcBytes: _srcBytes, //源Pdf文件的Base64编码
- destFile: _destFile, //目标pdf文件
- certEncode: _certEncode, //签名证书Base64编码
- sealImageEncode: _sealImageEncode, //签章图片Base64编码
- revInfoIncludeFlag: _revInfoIncludeFlag,//是否包含吊销信息
- batchSeal: //签名位置对象
- {
- signaturePage: _signaturePage, //电子签章所在页码
- startPage: _startPage, //开始页码
- endPage: _endPage, //结束页码
- xPos: _xPos, //签名域/签章左下角的水平向右方向坐标
- yPos: _yPos, //签名域/签章左下角的垂直向上方向坐标
- width: _width, //签名域/签章的宽度
- height: _height //签名域/签章的高度
- },
- Tsa: //时间戳对象
- {
- tsaUrl: _tsaUrl, //时间戳地址
- tsaUsr: _tsaUsr, //时间戳服务对应用户名
- tsaPwd: _tsaPwd, //时间戳服务对应用户的密码
- tsaHashAlgo: _tsaHashAlgo //时间戳使用的hash算法,例如”sha-1”,”sha-256”等
- }
- };
- NetcaPKI.batchSeal(params)
- .Then(function (res)
- {
- SignatureCreatorBatchSealSuccessCallBack(res);
- })
- .Catch(function (res)
- {
- SignatureCreatorBatchSealFailedCallBack(res);
- });
- }
- function SignatureCreatorBatchSealSuccessCallBack(res)
- {
- var result = "签名/章成功, 目标文件的Base64编码:\n" + res.destFileEncode;
- alert(result);
- console.log(res.destFileEncode);
- if(res.destFileEncode.length >= 20*1024*1024)
- {
- alert("注意:目标文件大于20M,会造成浏览器卡顿");
- }
- NetcaPDFSeal.preViewPDF(1, res.destFileEncode);
- }
- function SignatureCreatorBatchSealFailedCallBack(res)
- {
- alert("签名/章失败 " + res.msg);
- }
- function acrosspageSeal()
- {
- var _srcFile = signatureCreator_acrosspageseal_src_path.value; //源Pdf文件
- var _srcBytes = signatureCreator_acrosspageseal_srcBytes.value; //源Pdf文件字节流
- var _destFile = signatureCreator_acrosspageseal_des_path.value; //目标pdf文件
- var _certEncode = signatureCreator_acrosspageseal_certEncode.value; //签名证书Base64编码
- var _sealImageEncode = signatureCreator_acrosspageseal_sealImageEncode.value;//签章图片Base64编码
- var _revInfoIncludeFlag = (signatureCreator_acrosspageseal_revInfoIncludeFlag.value == 1) ? true : false; //是否包含吊销信息
- var _signaturePage = parseInt(signatureCreator_acrosspageseal_signaturePage.value); //P电子签章所在页码
- var _startPage = parseInt(signatureCreator_acrosspageseal_startPage.value); //开始页码
- var _endPage = parseInt(signatureCreator_acrosspageseal_endPage.value); //结束页码
- var _xPos = parseInt(signatureCreator_acrosspageseal_xpos.value); //签名域/签章左下角的水平向右方向坐标
- var _yPos = parseInt(signatureCreator_acrosspageseal_ypos.value); //签名域/签章左下角的垂直向上方向坐标
- var _width = parseInt(signatureCreator_acrosspageseal_width.value); //签名域/签章的宽度
- var _height = parseInt(signatureCreator_acrosspageseal_height.value); //签名域/签章的高度
- var _tsaUrl= "http://tsa.cnca.net/NETCATimeStampServer/TSAServer.jsp"; //时间戳地址
- var _tsaUsr= ""; //时间戳服务对应用户名
- var _tsaPwd= ""; //时间戳服务对应用户的密码
- var _tsaHashAlgo= ""; //时间戳使用的hash算法,例如”sha-1”,”sha-256”等
- var params = {
- srcFile: _srcFile, //源pdf文件
- srcBytes: _srcBytes, //源Pdf文件的Base64编码
- destFile: _destFile, //目标pdf文件
- certEncode: _certEncode, //签名证书Base64编码
- sealImageEncode: _sealImageEncode, //签章图片Base64编码
- revInfoIncludeFlag: _revInfoIncludeFlag,//是否包含吊销信息
- acrossPageSeal: //签名位置对象
- {
- signaturePage: _signaturePage, //电子签章所在页码
- startPage: _startPage, //开始页码
- endPage: _endPage, //结束页码
- xPos: _xPos, //签名域/签章左下角的水平向右方向坐标
- yPos: _yPos, //签名域/签章左下角的垂直向上方向坐标
- width: _width, //签名域/签章的宽度
- height: _height //签名域/签章的高度
- },
- Tsa: //时间戳对象
- {
- tsaUrl: _tsaUrl, //时间戳地址
- tsaUsr: _tsaUsr, //时间戳服务对应用户名
- tsaPwd: _tsaPwd, //时间戳服务对应用户的密码
- tsaHashAlgo: _tsaHashAlgo //时间戳使用的hash算法,例如”sha-1”,”sha-256”等
- }
- };
- NetcaPKI.acrosspageSeal(params)
- .Then(function (res)
- {
- SignatureCreatorAcrosspageSealSuccessCallBack(res);
- })
- .Catch(function (res)
- {
- SignatureCreatorAcrosspageSealFailedCallBack(res);
- });
- }
- function SignatureCreatorAcrosspageSealSuccessCallBack(res)
- {
- var result = "签名/章成功, 目标文件的Base64编码:\n" + res.destFileEncode;
- alert(result);
- console.log(res.destFileEncode);
- if(res.destFileEncode.length >= 20*1024*1024)
- {
- alert("注意:目标文件大于20M,会造成浏览器卡顿");
- }
- NetcaPDFSeal.preViewPDF(1, res.destFileEncode);
- }
- function SignatureCreatorAcrosspageSealFailedCallBack(res)
- {
- alert("签名/章失败 " + res.msg);
- }
- var g_drawtexTtextSpirits = new Array();
- function graphicsProcessDrawtext_addTextSpirit()
- {
- var _A=parseInt(graphicsProcessDrawtext_appearanceFontColorAEx.value); //透明度
- var _R=parseInt(graphicsProcessDrawtext_appearanceFontColorREx.value); //红色
- var _G=parseInt(graphicsProcessDrawtext_appearanceFontColorGEx.value); //绿色
- var _B=parseInt(graphicsProcessDrawtext_appearanceFontColorBEx.value); //蓝色
- var textSpirit = {
- text : graphicsProcessDrawtext_appearanceTextEx.value,
- widthPercentage : parseFloat(graphicsProcessDrawtext_appearanceWidthPercentageEx.value),
- heightPercentage : parseFloat(graphicsProcessDrawtext_appearanceHeightPercentageEx.value),
- fontName : graphicsProcessDrawtext_appearanceFontNameEx.value,
- fontSize : parseInt(graphicsProcessDrawtext_appearanceFontSizeEx.value),
- FontColor:
- {
- A: _A,
- R: _R,
- G: _G,
- B: _B
- },
- }
- g_drawtexTtextSpirits.push(textSpirit);
- alert("增加外观信息成功,现有"+g_drawtexTtextSpirits.length + "个信息");
- }
- function graphicsProcessDrawtext_clearTextSpirit()
- {
- g_drawtexTtextSpirits = [];
- alert("清空外观信息成功");
- }
- function graphicsProcessDrawText()
- {
- var _srcFile = graphicsProcessDrawtext_src_path.value; //源Pdf文件路径
- var _srcBytes = graphicsProcessDrawtext_srcBytes.value; //源Pdf文件字节流
- var _destFile = graphicsProcessDrawtext_des_path.value; //目标pdf文件
- var _autoSize = graphicsProcessDrawtext_autoSize.value=="1"?true:false;
- var params = {
- srcFile: _srcFile, //源pdf文件
- srcBytes: _srcBytes, //源Pdf文件的Base64编码
- destFile: _destFile, //目标pdf文件
- AppearanceObj:
- {
- appearanceType:parseInt(graphicsProcessDrawtext_appearanceType.value), //外观类型
- width:parseInt(graphicsProcessDrawtext_appearanceWidth.value), //外观宽度
- height:parseInt(graphicsProcessDrawtext_appearanceHeight.value), //外观高度
- autoSize:_autoSize, //外观高度
- textSpirits:g_drawtexTtextSpirits //文本信息
- }
- };
- NetcaPKI.graphicsProcessDrawText(params)
- .Then(function (res)
- {
- GraphicsProcessDrawtextSuccessCallBackEx(res);
- })
- .Catch(function (res)
- {
- GraphicsProcessDrawtextFailedCallBackEx(res);
- });
- }
- function GraphicsProcessDrawtextSuccessCallBackEx(res)
- {
- var result = "产生新图片成功, 目标文件的Base64编码:\n" + res.destFileEncode;
- alert(result);
- }
- function GraphicsProcessDrawtextFailedCallBackEx(res)
- {
- alert("产生新图片失败 " + res.msg);
- }
- function writeSeal()
- {
- var certEncode = Seal_certEncode.value;
- var selectType = "Device";
- var selectCondition = "InValidity='True' && CertType='Signature'";
- var params = {
- cert: {
- "encode": certEncode,
- "type": selectType,
- "condition": selectCondition
- },
- device: {
- "sn": Seal_sn.value,
- "type": parseInt(Seal_type.value)
- },
- seSeals: [
- {
- sealData: Seal_write_se_sealData.value
- }
- ]
- };
- NetcaPKI.writeSeal(params)
- .Then(function(res) {
- alert("写入印章成功");
- })
- .Catch(function(res) {
- alert(res.msg);
- });
- }
- function readSeal()
- {
- var certEncode = Seal_certEncode.value;
- var selectType = "Device";
- var selectCondition = "InValidity='True' && CertType='Signature'";
- var params = {
- cert: {
- "encode": certEncode,
- "type": selectType,
- "condition": selectCondition
- },
- device: {
- "sn": Seal_sn.value,
- "type": parseInt(Seal_type.value)
- }
- };
- NetcaPKI.readSeal(params)
- .Then(function(res) {
- alert("读取印章成功:" + JSON.stringify(res));
- })
- .Catch(function(res) {
- alert(res.msg);
- });
- }
- NetcaPKI.writeSeal=function(params){
- var requestQueryParams = {};
- requestQueryParams["function"] ="WriteSeal";
- requestQueryParams["param"] = params;
- return NetcaPKI.SendNetcaCryptoJsonRpcMessage(requestQueryParams);
- }
- NetcaPKI.readSeal=function(params){
- var requestQueryParams = {};
- requestQueryParams["function"] ="ReadSeal";
- requestQueryParams["param"] = params;
- return NetcaPKI.SendNetcaCryptoJsonRpcMessage(requestQueryParams);
- }
|