123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970 |
- 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)
- {
- 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 getCertListFail(res)
- {
- alert("获取证书列表成功\n" + res.msg);
- }
- 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);
- }
|