mToken.js 110 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173
  1. /*******************************************************
  2. *
  3. * 使用此JS脚本之前请先仔细阅读帮助文档!
  4. *
  5. * @author longmai
  6. * @version 4.1.22.0915
  7. * @date 2022/9/15
  8. *
  9. **********************************************************/
  10. var split;
  11. var _curDevName = "";
  12. var separatorExp;
  13. // Avoid running twice; that would break the `nativeSplit` reference
  14. split = split || function (undef) {
  15. var nativeSplit = String.prototype.split,
  16. compliantExecNpcg = /()??/.exec("")[1] === undef, // NPCG: nonparticipating capturing group
  17. self;
  18. self = function (str, separator, limit) {
  19. // If `separator` is not a regex, use `nativeSplit`
  20. if (Object.prototype.toString.call(separator) !== "[object RegExp]") {
  21. return nativeSplit.call(str, separator, limit);
  22. }
  23. var output = [],
  24. flags = (separator.ignoreCase ? "i" : "") +
  25. (separator.multiline ? "m" : "") +
  26. (separator.extended ? "x" : "") + // Proposed for ES6
  27. (separator.sticky ? "y" : ""), // Firefox 3+
  28. lastLastIndex = 0,
  29. // Make `global` and avoid `lastIndex` issues by working with a copy
  30. separatorExp = new RegExp(separator.source, flags + "g"),
  31. separator2, match, lastIndex, lastLength;
  32. str += ""; // Type-convert
  33. if (!compliantExecNpcg) {
  34. // Doesn't need flags gy, but they don't hurt
  35. separator2 = new RegExp("^" + separator.source + "$(?!\\s)", flags);
  36. }
  37. /* Values for `limit`, per the spec:
  38. * If undefined: 4294967295 // Math.pow(2, 32) - 1
  39. * If 0, Infinity, or NaN: 0
  40. * If positive number: limit = Math.floor(limit); if (limit > 4294967295) limit -= 4294967296;
  41. * If negative number: 4294967296 - Math.floor(Math.abs(limit))
  42. * If other: Type-convert, then use the above rules
  43. */
  44. limit = limit === undef ?
  45. -1 >>> 0 : // Math.pow(2, 32) - 1
  46. limit >>> 0; // ToUint32(limit)
  47. while (match = separatorExp.exec(str)) {
  48. // `separator.lastIndex` is not reliable cross-browser
  49. lastIndex = match.index + match[0].length;
  50. if (lastIndex > lastLastIndex) {
  51. output.push(str.slice(lastLastIndex, match.index));
  52. // Fix browsers whose `exec` methods don't consistently return `undefined` for
  53. // nonparticipating capturing groups
  54. if (!compliantExecNpcg && match.length > 1) {
  55. match[0].replace(separator2, function () {
  56. for (var i = 1; i < arguments.length - 2; i++) {
  57. if (arguments[i] === undef) {
  58. match[i] = undef;
  59. }
  60. }
  61. });
  62. }
  63. if (match.length > 1 && match.index < str.length) {
  64. Array.prototype.push.apply(output, match.slice(1));
  65. }
  66. lastLength = match[0].length;
  67. lastLastIndex = lastIndex;
  68. if (output.length >= limit) {
  69. break;
  70. }
  71. }
  72. if (separatorExp.lastIndex === match.index) {
  73. separatorExp.lastIndex++; // Avoid an infinite loop
  74. }
  75. }
  76. if (lastLastIndex === str.length) {
  77. if (lastLength || !separatorExp.test("")) {
  78. output.push("");
  79. }
  80. } else {
  81. output.push(str.slice(lastLastIndex));
  82. }
  83. return output.length > limit ? output.slice(0, limit) : output;
  84. };
  85. // For convenience
  86. String.prototype.split = function (separator, limit) {
  87. return self(this, separator, limit);
  88. };
  89. return self;
  90. }();
  91. function mToken(obj) {
  92. this.obj = obj;
  93. this.SAR_OK = 0;
  94. this.SAR_FALSE = 1;
  95. //分组加密算法标识
  96. this.SGD_SM1_ECB = 0x00000101;
  97. this.SGD_SM1_CBC = 0x00000102;
  98. this.SGD_SM1_CFB = 0x00000104;
  99. this.SGD_SM1_OFB = 0x00000108;
  100. this.SGD_SM1_MAC = 0x00000110;
  101. this.SGD_SSF33_ECB = 0x00000201;
  102. this.SGD_SSF33_CBC = 0x00000202;
  103. this.SGD_SSF33_CFB = 0x00000204;
  104. this.SGD_SSF33_OFB = 0x00000208;
  105. this.SGD_SSF33_MAC = 0x00000210;
  106. this.SGD_SM4_ECB = 0x00000401;
  107. this.SGD_SM4_CBC = 0x00000402;
  108. this.SGD_SM4_CFB = 0x00000404;
  109. this.SGD_SM4_OFB = 0x00000408;
  110. this.SGD_SM4_MAC = 0x00000410;
  111. this.SGD_VENDOR_DEFINED = 0x80000000;
  112. this.SGD_DES_ECB = this.SGD_VENDOR_DEFINED + 0x00000211
  113. this.SGD_DES_CBC = this.SGD_VENDOR_DEFINED + 0x00000212
  114. this.SGD_3DES168_ECB = this.SGD_VENDOR_DEFINED + 0x00000241
  115. this.SGD_3DES168_CBC = this.SGD_VENDOR_DEFINED + 0x00000242
  116. this.SGD_3DES112_ECB = this.SGD_VENDOR_DEFINED + 0x00000221
  117. this.SGD_3DES112_CBC = this.SGD_VENDOR_DEFINED + 0x00000222
  118. this.SGD_AES128_ECB = this.SGD_VENDOR_DEFINED + 0x00000111
  119. this.SGD_AES128_CBC = this.SGD_VENDOR_DEFINED + 0x00000112
  120. this.SGD_AES192_ECB = this.SGD_VENDOR_DEFINED + 0x00000121
  121. this.SGD_AES192_CBC = this.SGD_VENDOR_DEFINED + 0x00000122
  122. this.SGD_AES256_ECB = this.SGD_VENDOR_DEFINED + 0x00000141
  123. this.SGD_AES256_CBC = this.SGD_VENDOR_DEFINED + 0x00000142
  124. //非对称密码算法标识
  125. this.SGD_RSA = 0x00010000;
  126. this.SGD_SM2_1 = 0x00020100; //ECC签名
  127. this.SGD_SM2_2 = 0x00020200; //ECC密钥交换
  128. this.SGD_SM2_3 = 0x00020400; //ECC加密
  129. //密码杂凑算法标识
  130. this.SGD_SM3 = 0x00000001;
  131. this.SGD_SHA1 = 0x00000002;
  132. this.SGD_SHA256 = 0x00000004;
  133. this.SGD_RAW = 0x00000080;
  134. this.SGD_MD5 = 0x00000081;
  135. this.SGD_SHA384 = 0x00000082;
  136. this.SGD_SHA512 = 0x00000083;
  137. this.SGD_CERT_VERSION = 0x00000001;
  138. this.SGD_CERT_SERIAL = 0x00000002;
  139. this.SGD_CERT_ISSUE = 0x00000005;
  140. this.SGD_CERT_VALID_TIME = 0x00000006;
  141. this.SGD_CERT_SUBJECT = 0x00000007;
  142. this.SGD_CERT_DER_PUBLIC_KEY = 0x00000008;
  143. this.SGD_CERT_DER_EXTENSIONS = 0x00000009;
  144. this.SGD_CERT_NOT_BEFORE = 0x00000010;
  145. this.SGD_CERT_ISSUER_CN = 0x00000021;
  146. this.SGD_CERT_ISSUER_O = 0x00000022;
  147. this.SGD_CERT_ISSUER_OU = 0x00000023;
  148. this.SGD_CERT_ISSUER_C = 0x00000024;
  149. this.SGD_CERT_ISSUER_P = 0x00000025;
  150. this.SGD_CERT_ISSUER_L = 0x00000026;
  151. this.SGD_CERT_ISSUER_S = 0x00000027;
  152. this.SGD_CERT_ISSUER_EMAIL = 0x00000028;
  153. this.SGD_CERT_SUBJECT_CN = 0x00000031;
  154. this.SGD_CERT_SUBJECT_O = 0x00000032;
  155. this.SGD_CERT_SUBJECT_OU = 0x00000033;
  156. this.SGD_CERT_SUBJECT_EMALL = 0x00000034;
  157. this.SGD_REMAIN_TIME = 0x00000035;
  158. this.SGD_SIGNATURE_ALG = 0x00000036;
  159. this.SGD_CERT_SUBJECT_C = 0x00000037;
  160. this.SGD_CERT_SUBJECT_P = 0x00000038;
  161. this.SGD_CERT_SUBJECT_L = 0x00000039;
  162. this.SGD_CERT_SUBJECT_S = 0x0000003A;
  163. this.SGD_CERT_CRL = 0x00000041;
  164. this.SGD_DEVICE_SORT = 0x00000201;
  165. this.SGD_DEVICE_TYPE = 0x00000202;
  166. this.SGD_DEVICE_NAME = 0x00000203;
  167. this.SGD_DEVICE_MANUFACTURER = 0x00000204;
  168. this.SGD_DEVICE_HARDWARE_VERSION = 0x00000205;
  169. this.SGD_DEVICE_SOFTWARE_VERSION = 0x00000206;
  170. this.SGD_DEVICE_STANDARD_VERSION = 0x00000207;
  171. this.SGD_DEVICE_SERIAL_NUMBER = 0x00000208;
  172. this.SGD_DEVICE_SUPPORT_SYM_ALG = 0x00000209;
  173. this.SGD_DEVICE_SUPPORT_ASYM_ALG = 0x0000020A;
  174. this.SGD_DEVICE_SUPPORT_HASH_ALG = 0x0000020B;
  175. this.SGD_DEVICE_SUPPORT_STORANGE_SPACE = 0x0000020C;
  176. this.SGD_DEVICE_SUPPORT_FREE_SAPCE = 0x0000020D;
  177. this.SGD_DEVICE_RUNTIME = 0x0000020E;
  178. this.SGD_DEVICE_USED_TIMES = 0x0000020F;
  179. this.SGD_DEVICE_LOCATION = 0x00000210;
  180. this.SGD_DEVICE_DESCRIPTION = 0x00000211;
  181. this.SGD_DEVICE_MANAGER_INFO = 0x00000212;
  182. this.SGD_DEVICE_MAX_DATA_SIZE = 0x00000213;
  183. this.TRUE = 1;
  184. this.FALSE = 0;
  185. this.GM3000PCSC = 0;
  186. this.GM3000 = 1;
  187. this.K7 = 2;
  188. this.K5 = 3;
  189. this.TF = 4;
  190. this.TYPE_UKEY = 1; //普通UKEY
  191. this.TYPE_FPKEY = 2; //指纹UKEY
  192. var g_mTokenPlugin = null;
  193. var g_deviceNames = null;
  194. this.SOF_GetLastError = function () {
  195. if (g_mTokenPlugin == null) {
  196. return -1;
  197. }
  198. return g_mTokenPlugin.SOF_GetLastError();
  199. }
  200. function isIe() {
  201. return ("ActiveXObject" in window);
  202. }
  203. function isMobile() {
  204. var browser = {
  205. versions: function () {
  206. var u = navigator.userAgent;
  207. return {//移动终端浏览器版本信息
  208. trident: u.indexOf('Trident') > -1, //IE内核
  209. presto: u.indexOf('Presto') > -1, //opera内核
  210. webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
  211. gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐内核
  212. mobile: !!u.match(/AppleWebKit.*Mobile.*/), //是否为移动终端
  213. ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
  214. android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或者uc浏览器
  215. iPhone: u.indexOf('iPhone') > -1, //是否为iPhone或者QQHD浏览器
  216. iPad: u.indexOf('iPad') > -1, //是否iPad
  217. webApp: u.indexOf('Safari') == -1
  218. //是否web应该程序,没有头部与底部
  219. };
  220. }(),
  221. language: (navigator.browserLanguage || navigator.language).toLowerCase()
  222. }
  223. if (browser.versions.mobile) {
  224. return true;
  225. }
  226. else {
  227. return false;
  228. }
  229. }
  230. this.SOF_LoadLibrary = function (type) {
  231. os = check_os();
  232. var ret;
  233. if (g_mTokenPlugin == null) {
  234. g_mTokenPlugin = new mTokenPlugin();
  235. }
  236. if (type == this.GM3000PCSC) {
  237. if (isMobile()) {
  238. ret = g_mTokenPlugin.SOF_LoadLibrary("1", "mToken OTG", "com.longmai.security.plugin.driver.otg.OTGDriver");
  239. }
  240. else {
  241. ret = g_mTokenPlugin.SOF_LoadLibrary("mtoken_gm3000_pcsc.dll", "libgm3000_scard.1.0.so", "libgm3000_scard.1.0.dylib");
  242. }
  243. }
  244. else if (type == this.GM3000) {
  245. if (isMobile()) {
  246. ret = g_mTokenPlugin.SOF_LoadLibrary("1", "mToken OTG", "com.longmai.security.plugin.driver.otg.OTGDriver");
  247. }
  248. else {
  249. ret = g_mTokenPlugin.SOF_LoadLibrary("mtoken_gm3000.dll", "libgm3000.1.0.so", "libgm3000.1.0.dylib");
  250. }
  251. }
  252. else if (type == this.K7) {
  253. ret = g_mTokenPlugin.SOF_LoadLibrary("mtoken_k7.dll", "libk7.1.0.so", "libk7.1.0.dylib");
  254. }
  255. else if (type == this.K5) {
  256. if (isMobile()) {
  257. ret = g_mTokenPlugin.SOF_LoadLibrary("2", "mToken K5 Bluetooth", "com.longmai.security.plugin.driver.ble.BLEDriver");
  258. }
  259. else {
  260. ret = g_mTokenPlugin.SOF_LoadLibrary("mtoken_k5.dll", "libk5.1.0.so", "libk5.1.0.dylib");
  261. }
  262. }
  263. else if (type == this.TF) {
  264. if (isMobile()) {
  265. ret = g_mTokenPlugin.SOF_LoadLibrary("0", "mToken TF/SD Card", "com.longmai.security.plugin.driver.tf.TFDriver");
  266. } else {
  267. ret = g_mTokenPlugin.SOF_LoadLibrary("mtoken_tf.dll", "libtf.so", "libtf.dylib");
  268. }
  269. }
  270. else {
  271. return -1;
  272. }
  273. if (ret != 0) {
  274. return -2;
  275. }
  276. return this.SAR_OK;
  277. };
  278. this.SOF_EnumDevice = function () {
  279. if (g_mTokenPlugin == null) {
  280. return null;
  281. }
  282. var array = g_mTokenPlugin.SOF_EnumDevice();
  283. if (array == null || array.length <= 0) {
  284. return null;
  285. }
  286. return array.split("||");
  287. };
  288. this.SOF_DevAuth = function (deviceName, authCode) {
  289. if (g_mTokenPlugin == null) {
  290. return null;
  291. }
  292. return g_mTokenPlugin.SOF_DevAuth(deviceName, authCode)
  293. };
  294. this.SOF_ChangeDevAuthKey = function (newAuthCode) {
  295. if (g_mTokenPlugin == null) {
  296. return null;
  297. }
  298. return g_mTokenPlugin.SOF_ChangeDevAuthKey(newAuthCode);
  299. }
  300. this.SOF_CreateApplication = function (applicationName, adminPin, adminPinRetryCount, userPin, userPinRetryCount,fileRights) {
  301. if (g_mTokenPlugin == null) {
  302. return null;
  303. }
  304. return g_mTokenPlugin.SOF_CreateApplication(applicationName, adminPin, adminPinRetryCount, userPin, userPinRetryCount,fileRights);
  305. }
  306. this.SOF_GetApplicationList = function (deviceName) {
  307. if (g_mTokenPlugin == null) {
  308. return null;
  309. }
  310. var array = g_mTokenPlugin.SOF_GetApplicationList(deviceName);
  311. if (array == null || array.length <= 0) {
  312. return null;
  313. }
  314. return array.split("||");
  315. }
  316. this.SOF_DeleteApplication = function (applicationName) {
  317. if (g_mTokenPlugin == null) {
  318. return null;
  319. }
  320. return g_mTokenPlugin.SOF_DeleteApplication(applicationName);
  321. }
  322. this.SOF_CheckExists = function (deviceName) {
  323. if (g_mTokenPlugin == null) {
  324. return null;
  325. }
  326. return g_mTokenPlugin.SOF_CheckExists(deviceName);
  327. }
  328. this.SOF_GetVersion = function () {
  329. if (g_mTokenPlugin == null) {
  330. return null;
  331. }
  332. return g_mTokenPlugin.SOF_GetVersion();
  333. };
  334. this.SOF_GetDeviceInstance = function (DeviceName, ApplicationName) {
  335. if (g_mTokenPlugin == null) {
  336. return -1;
  337. }
  338. return g_mTokenPlugin.SOF_GetDeviceInstance(DeviceName, ApplicationName);
  339. };
  340. this.SOF_ReleaseDeviceInstance = function () {
  341. if (g_mTokenPlugin == null) {
  342. return -1;
  343. }
  344. return g_mTokenPlugin.SOF_ReleaseDeviceInstance()
  345. }
  346. this.SOF_GetUserList = function () {
  347. if (g_mTokenPlugin == null) {
  348. return null;
  349. }
  350. var array = g_mTokenPlugin.SOF_GetUserList();
  351. if (array == null || array.length <= 0)
  352. return null;
  353. var list = new Array();
  354. var user = array.split("&&&");
  355. var length = user.length;
  356. for (var i = 0; i < length; i++) {
  357. list[i] = user[i].split("||");
  358. }
  359. return list;
  360. };
  361. this.SOF_ExportUserCert = function (ContainerName, KeySpec) {
  362. if (g_mTokenPlugin == null) {
  363. return null;
  364. }
  365. return g_mTokenPlugin.SOF_ExportUserCert(ContainerName, KeySpec);
  366. };
  367. this.SOF_GetDeviceInfo = function (Type) {
  368. if (g_mTokenPlugin == null) {
  369. return null;
  370. }
  371. return g_mTokenPlugin.SOF_GetDeviceInfo(Type);
  372. };
  373. this.SOF_GetCertInfo = function (Base64EncodeCert, Type) {
  374. if (g_mTokenPlugin == null) {
  375. return null;
  376. }
  377. return g_mTokenPlugin.SOF_GetCertInfo(Base64EncodeCert, Type);
  378. };
  379. this.SOF_GetCertInfoByOid = function (Base64EncodeCert, OID) {
  380. if (g_mTokenPlugin == null) {
  381. return null;
  382. }
  383. return g_mTokenPlugin.SOF_GetCertInfoByOid(Base64EncodeCert, OID);
  384. }
  385. this.SOF_Login = function (PassWd) {
  386. if (g_mTokenPlugin == null) {
  387. return -1;
  388. }
  389. return g_mTokenPlugin.SOF_Login(PassWd);
  390. };
  391. this.SOF_LoginSoPin = function (PassWd) {
  392. if (g_mTokenPlugin == null) {
  393. return -1;
  394. }
  395. return g_mTokenPlugin.SOF_LoginSoPin(PassWd);
  396. }
  397. this.SOF_LogOut = function () {
  398. if (g_mTokenPlugin == null) {
  399. return -1;
  400. }
  401. return g_mTokenPlugin.SOF_LogOut();
  402. };
  403. this.SOF_SetLabel = function (Label) {
  404. if (g_mTokenPlugin == null) {
  405. return -1;
  406. }
  407. return g_mTokenPlugin.SOF_SetLabel(Label);
  408. }
  409. this.SOF_GetPinRetryCount = function () {
  410. if (g_mTokenPlugin == null) {
  411. return -1;
  412. }
  413. return g_mTokenPlugin.SOF_GetPinRetryCount();
  414. };
  415. this.SOF_GetPinMaxRetryCount = function () {
  416. if (g_mTokenPlugin == null) {
  417. return -1;
  418. }
  419. return g_mTokenPlugin.SOF_GetPinMaxRetryCount();
  420. };
  421. this.SOF_ChangePassWd = function (OldPassWd, NewPassWd) {
  422. if (g_mTokenPlugin == null) {
  423. return -1;
  424. }
  425. return g_mTokenPlugin.SOF_ChangePassWd(OldPassWd, NewPassWd);
  426. };
  427. this.SOF_ChangeSoPin = function (OldPassWd, NewPassWd) {
  428. if (g_mTokenPlugin == null) {
  429. return -1;
  430. }
  431. return g_mTokenPlugin.SOF_ChangeSoPin(OldPassWd, NewPassWd);
  432. };
  433. this.SOF_SetDigestMethod = function (DigestMethod) {
  434. if (g_mTokenPlugin == null) {
  435. return -1;
  436. }
  437. return g_mTokenPlugin.SOF_SetDigestMethod(DigestMethod);
  438. };
  439. this.SOF_SetUserID = function (UserID) {
  440. if (g_mTokenPlugin == null) {
  441. return -1;
  442. }
  443. return g_mTokenPlugin.SOF_SetUserID(UserID);
  444. };
  445. this.SOF_SetEncryptMethodAndIV = function (EncryptMethod, EncryptIV) {
  446. if (g_mTokenPlugin == null) {
  447. return -1;
  448. }
  449. return g_mTokenPlugin.SOF_SetEncryptMethodAndIV(EncryptMethod, EncryptIV);
  450. };
  451. this.SOF_EncryptFileToPKCS7 = function (Cert, InFile, OutFile, type) {
  452. if (g_mTokenPlugin == null) {
  453. return -1;
  454. }
  455. return g_mTokenPlugin.SOF_EncryptFileToPKCS7(Cert, InFile, OutFile, type);
  456. };
  457. this.SOF_SignFileToPKCS7 = function (ContainerName, InFile, OutFile) {
  458. if (g_mTokenPlugin == null) {
  459. return -1;
  460. }
  461. return g_mTokenPlugin.SOF_SignFileToPKCS7(ContainerName, InFile, OutFile);
  462. };
  463. this.SOF_VerifyFileToPKCS7 = function (strPkcs7Data, InFilePath) {
  464. if (g_mTokenPlugin == null) {
  465. return -1;
  466. }
  467. return g_mTokenPlugin.SOF_VerifyFileToPKCS7(strPkcs7Data, InFilePath);
  468. };
  469. this.SOF_DecryptFileToPKCS7 = function (ContainerName, keySpec, Pkcs7Data, InFile, OutFile, type) {
  470. if (g_mTokenPlugin == null) {
  471. return -1;
  472. }
  473. return g_mTokenPlugin.SOF_DecryptFileToPKCS7(ContainerName, keySpec, Pkcs7Data, InFile, OutFile, type);
  474. };
  475. this.SOF_DigestData = function (ContainerName, nData, InDataLen) {
  476. if (g_mTokenPlugin == null) {
  477. return null;
  478. }
  479. return g_mTokenPlugin.SOF_DigestData(ContainerName, nData, InDataLen);
  480. };
  481. this.SOF_SignData = function (ContainerName, ulKeySpec, InData, InDataLen, mode) {
  482. if (g_mTokenPlugin == null) {
  483. return null;
  484. }
  485. return g_mTokenPlugin.SOF_SignData(ContainerName, ulKeySpec, InData, InDataLen, mode);
  486. };
  487. //交互式签名
  488. this.SOF_SignDataInteractive = function (ContainerName, ulKeySpec, InData, InDataLen) {
  489. if (g_mTokenPlugin == null) {
  490. return null;
  491. }
  492. return g_mTokenPlugin.SOF_SignDataInteractive(ContainerName, ulKeySpec, InData, InDataLen);
  493. }
  494. this.SOF_SignDataToPKCS7 = function (ContainerName, ulKeySpec, InData, ulDetached) {
  495. if (g_mTokenPlugin == null) {
  496. return null;
  497. }
  498. return g_mTokenPlugin.SOF_SignDataToPKCS7(ContainerName, ulKeySpec, InData, ulDetached);
  499. };
  500. this.SOF_VerifyDataToPKCS7 = function (Base64EncodeCert, InData, SignedValue) {
  501. if (g_mTokenPlugin == null) {
  502. return -1;
  503. }
  504. return g_mTokenPlugin.SOF_VerifyDataToPKCS7(Base64EncodeCert, InData, SignedValue);
  505. };
  506. this.SOF_VerifySignedData = function (Base64EncodeCert, digestMethod, InData, SignedValue, mode) {
  507. if (g_mTokenPlugin == null) {
  508. return -1;
  509. }
  510. return g_mTokenPlugin.SOF_VerifySignedData(Base64EncodeCert, digestMethod, InData, SignedValue, mode);
  511. };
  512. this.SOF_EncryptDataPKCS7 = function (Base64EncodeCert, InData, InDataLen) {
  513. if (g_mTokenPlugin == null) {
  514. return null;
  515. }
  516. return g_mTokenPlugin.SOF_EncryptDataPKCS7(Base64EncodeCert, InData, InDataLen);
  517. };
  518. this.SOF_EncryptDataPKCS7EX = function (Base64EncodeCert, InData, InDataLen) {
  519. if (g_mTokenPlugin == null) {
  520. return null;
  521. }
  522. return g_mTokenPlugin.SOF_EncryptDataPKCS7EX(Base64EncodeCert, InData, InDataLen);
  523. };
  524. this.SOF_DecryptDataPKCS7 = function (ContainerName, ulKeySpec, InData) {
  525. if (g_mTokenPlugin == null) {
  526. return null;
  527. }
  528. return g_mTokenPlugin.SOF_DecryptDataPKCS7(ContainerName, ulKeySpec, InData);
  529. };
  530. this.SOF_DecryptDataPKCS7EX = function (ContainerName, ulKeySpec, InData) {
  531. if (g_mTokenPlugin == null) {
  532. return null;
  533. }
  534. return g_mTokenPlugin.SOF_DecryptDataPKCS7EX(ContainerName, ulKeySpec, InData);
  535. };
  536. this.SOF_GenRemoteUnblockRequest = function () {
  537. if (g_mTokenPlugin == null) {
  538. return null;
  539. }
  540. return g_mTokenPlugin.SOF_GenRemoteUnblockRequest();
  541. };
  542. this.SOF_GenResetpwdResponse = function (request, soPin, userPin) {
  543. if (g_mTokenPlugin == null) {
  544. return null;
  545. }
  546. return g_mTokenPlugin.SOF_GenResetpwdResponse(request, soPin, userPin);
  547. };
  548. this.SOF_RemoteUnblockPIN = function (request) {
  549. if (g_mTokenPlugin == null) {
  550. return null;
  551. }
  552. return g_mTokenPlugin.SOF_RemoteUnblockPIN(request);
  553. };
  554. this.SOF_SignDataToPKCS7 = function (ContainerName, ulKeySpec, InData, ulDetached) {
  555. if (g_mTokenPlugin == null) {
  556. return null;
  557. }
  558. return g_mTokenPlugin.SOF_SignDataToPKCS7(ContainerName, ulKeySpec, InData, ulDetached);
  559. };
  560. this.SOF_VerifyDataToPKCS7 = function (strPkcs7Data, OriginalText, ulDetached) {
  561. if (g_mTokenPlugin == null) {
  562. return null;
  563. }
  564. return g_mTokenPlugin.SOF_VerifyDataToPKCS7(strPkcs7Data, OriginalText, ulDetached);
  565. };
  566. this.CSOF_VerifyDigestDataToPKCS7 = function (strPkcs7Data, OriginalText, ulDetached) {
  567. if (g_mTokenPlugin == null) {
  568. return null;
  569. }
  570. return g_mTokenPlugin.CSOF_VerifyDigestDataToPKCS7(strPkcs7Data, OriginalText, ulDetached);
  571. };
  572. //按expType导出的公钥,格式为国密规范指定的格式或DER格式
  573. this.SOF_ExportPubKey = function (containerName, cerType, expType) {
  574. if (g_mTokenPlugin == null) {
  575. return null;
  576. }
  577. return g_mTokenPlugin.SOF_ExportPubKey(containerName, cerType, expType);
  578. }
  579. this.SOF_PublicVerify = function (pubKey, inData, signedValue, digestMethod) {
  580. if (g_mTokenPlugin == null) {
  581. return null;
  582. }
  583. return g_mTokenPlugin.SOF_PublicVerify(pubKey, inData, signedValue, digestMethod);
  584. }
  585. this.SOF_EncryptByPubKey = function (strPubKey, strInput, cerType) {
  586. if (g_mTokenPlugin == null) {
  587. return null;
  588. }
  589. return g_mTokenPlugin.SOF_EncryptByPubKey(strPubKey, strInput, cerType);
  590. }
  591. this.SOF_DecryptByPrvKey = function (containerName, cerType, strAsymCipher) {
  592. if (g_mTokenPlugin == null) {
  593. return null;
  594. }
  595. return g_mTokenPlugin.SOF_DecryptByPrvKey(containerName, cerType, strAsymCipher);
  596. }
  597. //RA客户端相关接口:P10及证书导入等
  598. this.SOF_GenerateP10Request = function (deviceName, container, dn, asymAlg, keySpec, keyLength) {
  599. if (g_mTokenPlugin == null) {
  600. return null;
  601. }
  602. return g_mTokenPlugin.SOF_GenerateP10Request(deviceName, container, dn, asymAlg, keySpec, keyLength);
  603. }
  604. this.SOF_CreateContainer = function (containerName) {
  605. if (g_mTokenPlugin == null) {
  606. return null;
  607. }
  608. return g_mTokenPlugin.SOF_CreateContainer(containerName);
  609. }
  610. this.SOF_EnumCertContiner = function () {
  611. if (g_mTokenPlugin == null) {
  612. return null;
  613. }
  614. return g_mTokenPlugin.SOF_EnumCertContiner();
  615. }
  616. this.SOF_FindContainer = function (certSN) {
  617. if (g_mTokenPlugin == null) {
  618. return null;
  619. }
  620. return g_mTokenPlugin.SOF_FindContainer(certSN);
  621. }
  622. this.SOF_DeleteCert = function (certSN) {
  623. if (g_mTokenPlugin == null) {
  624. return null;
  625. }
  626. return g_mTokenPlugin.SOF_DeleteCert(certSN);
  627. }
  628. this.SOF_DeleteContainer = function (certSN) {
  629. if (g_mTokenPlugin == null) {
  630. return null;
  631. }
  632. return g_mTokenPlugin.SOF_DeleteContainer(certSN);
  633. }
  634. this.SOF_SignByCert = function (certSN, plain) {
  635. if (g_mTokenPlugin == null) {
  636. return null;
  637. }
  638. return g_mTokenPlugin.SOF_SignByCert(certSN, plain);
  639. }
  640. this.SOF_VerifyByCert = function (certSN, plain, signature) {
  641. if (g_mTokenPlugin == null) {
  642. return null;
  643. }
  644. return g_mTokenPlugin.SOF_VerifyByCert(certSN, plain, signature);
  645. }
  646. this.SOF_ImportCert = function (container, cert, keySpec) {
  647. if (g_mTokenPlugin == null) {
  648. return null;
  649. }
  650. return g_mTokenPlugin.SOF_ImportCert(container, cert, keySpec);
  651. }
  652. this.SOF_ImportCryptoCertAndKey = function (container, cert, nAsymAlg, EncryptedSessionKeyData, symAlg, EncryptedPrivateKeyData, mode) {
  653. if (g_mTokenPlugin == null) {
  654. return null;
  655. }
  656. return g_mTokenPlugin.SOF_ImportCryptoCertAndKey(container, cert, nAsymAlg, EncryptedSessionKeyData, symAlg, EncryptedPrivateKeyData, mode);
  657. }
  658. this.SOF_VerifyByExtCert = function (cert, plain, signature, digestMethod) {
  659. if (g_mTokenPlugin == null) {
  660. return null;
  661. }
  662. return g_mTokenPlugin.SOF_VerifyByExtCert(cert, plain, signature, digestMethod);
  663. }
  664. this.SOF_GenerateRandom = function (length) {
  665. if (g_mTokenPlugin == null) {
  666. return null;
  667. }
  668. return g_mTokenPlugin.SOF_GenerateRandom(length);
  669. }
  670. this.SOF_SymEncryptFile = function (sessionKey, srcfile, destfile, type) {
  671. if (g_mTokenPlugin == null) {
  672. return null;
  673. }
  674. return g_mTokenPlugin.SOF_SymEncryptFile(sessionKey, srcfile, destfile, type);
  675. }
  676. this.SOF_SymDecryptFile = function (sessionKey, srcfile, destfile, type) {
  677. if (g_mTokenPlugin == null) {
  678. return null;
  679. }
  680. return g_mTokenPlugin.SOF_SymDecryptFile(sessionKey, srcfile, destfile, type);
  681. }
  682. this.SOF_SymEncryptData = function (sessionKey, inData) {
  683. if (g_mTokenPlugin == null) {
  684. return null;
  685. }
  686. return g_mTokenPlugin.SOF_SymEncryptData(sessionKey, inData);
  687. }
  688. this.SOF_SymDecryptData = function (sessionKey, inData) {
  689. if (g_mTokenPlugin == null) {
  690. return null;
  691. }
  692. return g_mTokenPlugin.SOF_SymDecryptData(sessionKey, inData);
  693. }
  694. this.SOF_GenerateQRCode = function (qrcode_text) {
  695. if (g_mTokenPlugin == null) {
  696. return null;
  697. }
  698. return g_mTokenPlugin.SOF_GenerateQRCode(qrcode_text);
  699. }
  700. this.SOF_VerifyPinMS = function (responseKey) {
  701. if (g_mTokenPlugin == null) {
  702. return null;
  703. }
  704. return g_mTokenPlugin.SOF_VerifyPinMS(responseKey);
  705. }
  706. this.SOF_GetHardwareType = function () {
  707. if (g_mTokenPlugin == null) {
  708. return null;
  709. }
  710. return g_mTokenPlugin.SOF_GetHardwareType();
  711. }
  712. this.SOF_VerifyFingerprint = function () {
  713. if (g_mTokenPlugin == null) {
  714. return null;
  715. }
  716. return g_mTokenPlugin.SOF_VerifyFingerprint();
  717. }
  718. this.SOF_VerifyFingerprintEx = function () {
  719. if (g_mTokenPlugin == null) {
  720. return null;
  721. }
  722. return g_mTokenPlugin.SOF_VerifyFingerprintEx();
  723. }
  724. this.SOF_QueryFinger = function (fignerType) {
  725. if (g_mTokenPlugin == null) {
  726. return null;
  727. }
  728. return g_mTokenPlugin.SOF_QueryFinger(fignerType);
  729. }
  730. this.SOF_EnumFiles = function () {
  731. if (g_mTokenPlugin == null) {
  732. return null;
  733. }
  734. var array = g_mTokenPlugin.SOF_EnumFiles();
  735. if (array == null || array.length <= 0) {
  736. return null;
  737. }
  738. return array.split("||");
  739. }
  740. this.SOF_ReadFile = function (fileName, offset, length) {
  741. if (g_mTokenPlugin == null) {
  742. return null;
  743. }
  744. return g_mTokenPlugin.SOF_ReadFile(fileName, Number(offset), Number(length));
  745. }
  746. this.SOF_WriteFile = function (fileName, offset, data) {
  747. if (g_mTokenPlugin == null) {
  748. return null;
  749. }
  750. return g_mTokenPlugin.SOF_WriteFile(fileName, offset, data);
  751. }
  752. this.SOF_CreateFile = function (fileName, length, readRight, writeRight) {
  753. if (g_mTokenPlugin == null) {
  754. return null;
  755. }
  756. return g_mTokenPlugin.SOF_CreateFile(fileName, length, readRight, writeRight);
  757. }
  758. this.SOF_DeleteFile = function (fileName) {
  759. if (g_mTokenPlugin == null) {
  760. return null;
  761. }
  762. return g_mTokenPlugin.SOF_DeleteFile(fileName);
  763. }
  764. this.SOF_SetCrossAccess = function (crossAccess) {
  765. if (g_mTokenPlugin == null) {
  766. return null;
  767. }
  768. return g_mTokenPlugin.SOF_SetCrossAccess(crossAccess);
  769. }
  770. this.SOF_DigestInit = function (pubKey, mode) {
  771. if (g_mTokenPlugin == null) {
  772. return null;
  773. }
  774. return g_mTokenPlugin.SOF_DigestInit(pubKey, mode);
  775. }
  776. this.SOF_DigestUpdate = function (inData) {
  777. if (g_mTokenPlugin == null) {
  778. return null;
  779. }
  780. return g_mTokenPlugin.SOF_DigestUpdate(inData);
  781. }
  782. this.SOF_DigestFinal = function () {
  783. if (g_mTokenPlugin == null) {
  784. return null;
  785. }
  786. return g_mTokenPlugin.SOF_DigestFinal();
  787. }
  788. this.SOF_DigestToSignData = function (ContainerName, ulKeySpec, singedType, hashData) {
  789. if (g_mTokenPlugin == null) {
  790. return null;
  791. }
  792. return g_mTokenPlugin.SOF_DigestToSignData(ContainerName, ulKeySpec, singedType, hashData);
  793. }
  794. this.SOF_CreateKeyPair = function (container, keySpec, asymAlg, keyLength) {
  795. if (g_mTokenPlugin == null) {
  796. return null;
  797. }
  798. return g_mTokenPlugin.SOF_CreateKeyPair(container, keySpec, asymAlg, keyLength);
  799. }
  800. this.SOF_IsVerifyPIN = function () {
  801. if (g_mTokenPlugin == null) {
  802. return null;
  803. }
  804. return g_mTokenPlugin.SOF_IsVerifyPIN();
  805. }
  806. this.SOF_VerifyCode = function (code) {
  807. if (g_mTokenPlugin == null) {
  808. return -1;
  809. }
  810. return g_mTokenPlugin.SOF_VerifyCode(code);
  811. };
  812. }
  813. //判断插件名称是否存在
  814. function hasPlugin(name) {
  815. name = name.toLowerCase();
  816. for (var i = 0; i < navigator.plugins.length; i++) {
  817. console.log(navigator.plugins[i].name.toLowerCase());
  818. if (navigator.plugins[i].name.toLowerCase().indexOf(name) > -1) {
  819. return true;
  820. }
  821. }
  822. return false;
  823. }
  824. //判断系统
  825. function check_os() {
  826. var os_type;
  827. var windows = (navigator.userAgent.indexOf("Windows", 0) != -1) ? 1 : 0;
  828. var mac = (navigator.userAgent.indexOf("mac", 0) != -1) ? 1 : 0;
  829. var linux = (navigator.userAgent.indexOf("Linux", 0) != -1) ? 1 : 0;
  830. var unix = (navigator.userAgent.indexOf("X11", 0) != -1) ? 1 : 0;
  831. if (windows) os_type = "MS Windows";
  832. else if (linux) os_type = "Lunix";
  833. if (hasPlugin("mPlugin1.0.0.1")) {
  834. linuxWin = 2;
  835. return "id_mPluginV2Router";
  836. } else {
  837. linuxWin = 1;
  838. return "mTokenPlugin";
  839. }
  840. }
  841. var linuxWin = 0;
  842. var os;
  843. function mTokenPlugin() {
  844. var _xmlhttp;
  845. var retJSON;
  846. function AjaxIO(json_in) {
  847. var linux = (navigator.userAgent.indexOf("Linux", 0) != -1) ? 1 : 0;
  848. if (os == "id_mPluginV2Router") {
  849. var router = null;
  850. var url = "http://127.0.0.1:51235/alpha";
  851. router = document.getElementById("id_mPluginV2Router");
  852. if (null == router) {
  853. return -3;
  854. }
  855. if ("https:" == document.location.protocol) {
  856. url = "https://127.0.0.1:51245/alpha";
  857. }
  858. var json_mPluginV2Router = json_in;
  859. retJSON = router.invoke(url, json_mPluginV2Router);
  860. return retJSON;
  861. } else {
  862. var _url = "http://127.0.0.1:51235/alpha";
  863. var json = json_in;
  864. if (_xmlhttp == null) {
  865. if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
  866. _xmlhttp = new XMLHttpRequest();
  867. } else { // code for IE6, IE5
  868. _xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  869. }
  870. }
  871. if ("https:" == document.location.protocol) {
  872. _url = "https://127.0.0.1:51245/alpha";
  873. }
  874. if (linux == 1){
  875. _url = "http://127.0.0.1:51235/alpha";
  876. }
  877. _xmlhttp.open("POST", _url, false);
  878. _xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  879. _xmlhttp.send("json=" + json);
  880. }
  881. }
  882. function GetHttpResult() {
  883. if (_xmlhttp.readyState == 4 && _xmlhttp.status == 200) {
  884. var obj = eval("(" + _xmlhttp.responseText + ")");
  885. return obj;
  886. }
  887. else {
  888. return null;
  889. }
  890. }
  891. this.SOF_GetLastError = function () {
  892. var json = '{"function":"SOF_GetLastError"}';
  893. if (linuxWin == 2) {
  894. var retJSON = "";
  895. try {
  896. retJSON = AjaxIO(json);
  897. } catch (e) {
  898. return -3;
  899. }
  900. if (retJSON.length > 3) {
  901. var obj = eval("(" + retJSON + ")");
  902. return obj.errorCode.toString(16);
  903. } else {
  904. return -2;
  905. }
  906. } else {
  907. try {
  908. AjaxIO(json);
  909. } catch (e) {
  910. return -3;
  911. }
  912. var ret = GetHttpResult();
  913. if (ret) {
  914. return ret.rtn.toString(16);
  915. }
  916. return -2;
  917. }
  918. }
  919. this.SOF_LoadLibrary = function (windows, linux, mac) {
  920. var json = '{"function":"SOF_LoadLibrary", "winDllName":"' + windows + '", "linuxSOName":"' + linux + '", "macDylibName":"' + mac + '"}';
  921. if (linuxWin == 2) {
  922. var retJSON = "";
  923. try {
  924. retJSON = AjaxIO(json);
  925. } catch (e) {
  926. return -3;
  927. }
  928. if (retJSON.length > 3) {
  929. var obj = eval("(" + retJSON + ")");
  930. return obj.rtn;
  931. } else {
  932. return -2;
  933. }
  934. } else {
  935. try {
  936. AjaxIO(json);
  937. } catch (e) {
  938. return -3;
  939. }
  940. var ret = GetHttpResult();
  941. if (ret) {
  942. return ret.rtn;
  943. }
  944. return -2;
  945. }
  946. };
  947. this.SOF_EnumDevice = function () {
  948. var json = '{"function":"SOF_EnumDevice"}';
  949. if (linuxWin == 2) {
  950. var retJSON = "";
  951. try {
  952. retJSON = AjaxIO(json);
  953. } catch (e) {
  954. return -3;
  955. }
  956. if (retJSON.length > 3) {
  957. var obj = eval("(" + retJSON + ")");
  958. return obj.array;
  959. } else {
  960. return -2;
  961. }
  962. } else {
  963. try {
  964. AjaxIO(json);
  965. } catch (e) {
  966. return -3;
  967. }
  968. var ret = GetHttpResult();
  969. if (ret) {
  970. return ret.array;
  971. }
  972. return -2;
  973. }
  974. };
  975. this.SOF_DevAuth = function (deviceName, authCode) {
  976. var json = '{"function":"SOF_DevAuth", "deviceName":"' + deviceName + '", "authPassWd":"' + authCode + '"}';
  977. if (linuxWin == 2) {
  978. var retJSON = "";
  979. try {
  980. _curDevName = deviceName;
  981. retJSON = AjaxIO(json);
  982. } catch (e) {
  983. return -3;
  984. }
  985. if (retJSON.length > 3) {
  986. var obj = eval("(" + retJSON + ")");
  987. return obj.rtn;
  988. } else {
  989. return -2;
  990. }
  991. } else {
  992. try {
  993. AjaxIO(json);
  994. } catch (e) {
  995. return -3;
  996. }
  997. var ret = GetHttpResult();
  998. if (ret) {
  999. if (ret.rtn == 0) {
  1000. _curDevName = deviceName;
  1001. }
  1002. return ret.rtn;
  1003. }
  1004. return -2;
  1005. }
  1006. };
  1007. this.SOF_ChangeDevAuthKey = function (newAuthCode) {
  1008. var json = '{"function":"SOF_ChangeDevAuthKey", "deviceName":"' + _curDevName + '", "authPassWd":"' + newAuthCode + '"}';
  1009. if (linuxWin == 2) {
  1010. var retJSON = "";
  1011. try {
  1012. retJSON = AjaxIO(json);
  1013. } catch (e) {
  1014. return -3;
  1015. }
  1016. if (retJSON.length > 3) {
  1017. var obj = eval("(" + retJSON + ")");
  1018. return obj.rtn;
  1019. } else {
  1020. return -2;
  1021. }
  1022. } else {
  1023. try {
  1024. AjaxIO(json);
  1025. } catch (e) {
  1026. return -3;
  1027. }
  1028. var ret = GetHttpResult();
  1029. if (ret) {
  1030. return ret.rtn;
  1031. }
  1032. return -2;
  1033. }
  1034. };
  1035. this.SOF_CreateApplication = function (ApplicationName, adminPin, adminPinRetryCount, userPin, userPinRetryCount,fileRights) {
  1036. var json = '{"function":"SOF_CreateApplication", "deviceName":"' + _curDevName + '", "applicationName":"' + ApplicationName + '", "soPin":"' + adminPin + '", "soPinRetryCount":' + adminPinRetryCount + ', "userPin":"' + userPin + '", "userPinRetryCount":' + userPinRetryCount + ',"rights":'+fileRights+'}';
  1037. if (linuxWin == 2) {
  1038. var retJSON = "";
  1039. try {
  1040. retJSON = AjaxIO(json);
  1041. } catch (e) {
  1042. return -3;
  1043. }
  1044. if (retJSON.length > 3) {
  1045. var obj = eval("(" + retJSON + ")");
  1046. return obj.rtn;
  1047. } else {
  1048. return -2;
  1049. }
  1050. } else {
  1051. try {
  1052. AjaxIO(json);
  1053. } catch (e) {
  1054. return -3;
  1055. }
  1056. var ret = GetHttpResult();
  1057. if (ret) {
  1058. return ret.rtn;
  1059. }
  1060. return -2;
  1061. }
  1062. };
  1063. this.SOF_DeleteApplication = function (ApplicationName) {
  1064. var json = '{"function":"SOF_DeleteApplication", "deviceName":"' + _curDevName + '", "applicationName":"' + ApplicationName + '"}';
  1065. if (linuxWin == 2) {
  1066. var retJSON = "";
  1067. try {
  1068. retJSON = AjaxIO(json);
  1069. } catch (e) {
  1070. return -3;
  1071. }
  1072. if (retJSON.length > 3) {
  1073. var obj = eval("(" + retJSON + ")");
  1074. return obj.rtn;
  1075. } else {
  1076. return -2;
  1077. }
  1078. } else {
  1079. try {
  1080. AjaxIO(json);
  1081. } catch (e) {
  1082. return -3;
  1083. }
  1084. var ret = GetHttpResult();
  1085. if (ret) {
  1086. return ret.rtn;
  1087. }
  1088. return -2;
  1089. }
  1090. }
  1091. this.SOF_GetApplicationList = function (deviceName) {
  1092. var json = '{"function":"SOF_GetApplicationList", "deviceName":"' + deviceName + '"}';
  1093. if (linuxWin == 2) {
  1094. var retJSON = "";
  1095. try {
  1096. _curDevName = deviceName;
  1097. retJSON = AjaxIO(json);
  1098. } catch (e) {
  1099. return -3;
  1100. }
  1101. if (retJSON.length > 3) {
  1102. var obj = eval("(" + retJSON + ")");
  1103. return obj.array;
  1104. } else {
  1105. return -2;
  1106. }
  1107. } else {
  1108. try {
  1109. AjaxIO(json);
  1110. } catch (e) {
  1111. return -3;
  1112. }
  1113. var ret = GetHttpResult();
  1114. if (ret) {
  1115. if (ret.rtn == 0) {
  1116. _curDevName = deviceName;
  1117. }
  1118. return ret.array;
  1119. }
  1120. return -2;
  1121. }
  1122. }
  1123. this.SOF_CheckExists = function (deviceName) {
  1124. var json = '{"function":"SOF_CheckExists", "deviceName":"' + deviceName + '"}';
  1125. if (linuxWin == 2) {
  1126. var retJSON = "";
  1127. try {
  1128. retJSON = AjaxIO(json);
  1129. } catch (e) {
  1130. return -3;
  1131. }
  1132. if (retJSON.length > 3) {
  1133. var obj = eval("(" + retJSON + ")");
  1134. if (obj.rtn == 0) {
  1135. return obj.isExist;
  1136. } else {
  1137. obj.rtn;
  1138. }
  1139. } else {
  1140. return -2;
  1141. }
  1142. } else {
  1143. try {
  1144. AjaxIO(json);
  1145. } catch (e) {
  1146. return -3;
  1147. }
  1148. var ret = GetHttpResult();
  1149. if (ret) {
  1150. if (ret.rtn == 0) {
  1151. return ret.isExist;
  1152. } else {
  1153. return ret.rtn;
  1154. }
  1155. return;
  1156. }
  1157. return -2;
  1158. }
  1159. };
  1160. this.SOF_GetVersion = function () {
  1161. var json = '{"function":"SOF_GetVersion"}';
  1162. if (linuxWin == 2) {
  1163. var retJSON = "";
  1164. try {
  1165. retJSON = AjaxIO(json);
  1166. } catch (e) {
  1167. return -3;
  1168. }
  1169. if (retJSON.length > 3) {
  1170. var obj = eval("(" + retJSON + ")");
  1171. return obj.version;
  1172. } else {
  1173. return -2;
  1174. }
  1175. } else {
  1176. try {
  1177. AjaxIO(json);
  1178. } catch (e) {
  1179. return -3;
  1180. }
  1181. var ret = GetHttpResult();
  1182. if (ret) {
  1183. return ret.version;
  1184. }
  1185. return -2;
  1186. }
  1187. };
  1188. this.SOF_GetDeviceInstance = function (DeviceName, ApplicationName) {
  1189. var json = '{"function":"SOF_GetDeviceInstance", "deviceName":"' + DeviceName + '", "applicationName":"' + ApplicationName + '"}';
  1190. if (linuxWin == 2) {
  1191. var retJSON = "";
  1192. try {
  1193. _curDevName = DeviceName;
  1194. retJSON = AjaxIO(json);
  1195. } catch (e) {
  1196. return -3;
  1197. }
  1198. if (retJSON.length > 3) {
  1199. var obj = eval("(" + retJSON + ")");
  1200. return obj.rtn;
  1201. } else {
  1202. return -2;
  1203. }
  1204. } else {
  1205. try {
  1206. AjaxIO(json);
  1207. } catch (e) {
  1208. return -3;
  1209. }
  1210. var ret = GetHttpResult();
  1211. if (ret) {
  1212. if (ret.rtn == 0) {
  1213. _curDevName = DeviceName;
  1214. }
  1215. return ret.rtn;
  1216. }
  1217. return -2;
  1218. }
  1219. };
  1220. this.SOF_ReleaseDeviceInstance = function () {
  1221. var json = '{"function":"SOF_ReleaseDeviceInstance", "deviceName":"' + _curDevName + '"}';
  1222. if (linuxWin == 2) {
  1223. var retJSON = "";
  1224. try {
  1225. retJSON = AjaxIO(json);
  1226. }
  1227. catch (e) {
  1228. return -3;
  1229. }
  1230. if (retJSON.length > 3) {
  1231. var obj = eval("(" + retJSON + ")");
  1232. return obj.array;
  1233. } else {
  1234. return -2;
  1235. }
  1236. } else {
  1237. try {
  1238. AjaxIO(json);
  1239. } catch (e) {
  1240. return -3;
  1241. }
  1242. var ret = GetHttpResult();
  1243. if (ret) {
  1244. return ret.rtn;
  1245. }
  1246. return -2;
  1247. }
  1248. };
  1249. this.SOF_GetUserList = function () {
  1250. var json = '{"function":"SOF_GetUserList", "deviceName":"' + _curDevName + '"}';
  1251. if (linuxWin == 2) {
  1252. var retJSON = "";
  1253. try {
  1254. retJSON = AjaxIO(json);
  1255. } catch (e) {
  1256. return -3;
  1257. }
  1258. if (retJSON.length > 3) {
  1259. var obj = eval("(" + retJSON + ")");
  1260. return obj.array;
  1261. } else {
  1262. return -2;
  1263. }
  1264. } else {
  1265. try {
  1266. AjaxIO(json);
  1267. } catch (e) {
  1268. return -3;
  1269. }
  1270. var ret = GetHttpResult();
  1271. if (ret) {
  1272. return ret.array;
  1273. }
  1274. return -2;
  1275. }
  1276. };
  1277. this.SOF_ExportUserCert = function (ContainerName, KeySpec) {
  1278. var json = '{"function":"SOF_ExportUserCert", "deviceName":"' + _curDevName + '", "containerName":"' + ContainerName + '", "keySpec":' + KeySpec + '}';
  1279. if (linuxWin == 2) {
  1280. var retJSON = "";
  1281. try {
  1282. retJSON = AjaxIO(json);
  1283. } catch (e) {
  1284. return -3;
  1285. }
  1286. if (retJSON.length > 3) {
  1287. var obj = eval("(" + retJSON + ")");
  1288. return obj.cert;
  1289. } else {
  1290. return -2;
  1291. }
  1292. } else {
  1293. try {
  1294. AjaxIO(json);
  1295. } catch (e) {
  1296. return -3;
  1297. }
  1298. var ret = GetHttpResult();
  1299. if (ret) {
  1300. return ret.cert;
  1301. }
  1302. return -2;
  1303. }
  1304. };
  1305. this.SOF_GetDeviceInfo = function (Type) {
  1306. var json = '{"function":"SOF_GetDeviceInfo", "deviceName":"' + _curDevName + '", "type":' + Type + '}';
  1307. if (linuxWin == 2) {
  1308. var retJSON = "";
  1309. try {
  1310. retJSON = AjaxIO(json);
  1311. } catch (e) {
  1312. return -3;
  1313. }
  1314. if (retJSON.length > 3) {
  1315. var obj = eval("(" + retJSON + ")");
  1316. return obj.info;
  1317. } else {
  1318. return -2;
  1319. }
  1320. } else {
  1321. try {
  1322. AjaxIO(json);
  1323. } catch (e) {
  1324. return -3;
  1325. }
  1326. var ret = GetHttpResult();
  1327. if (ret) {
  1328. return ret.info;
  1329. }
  1330. return -2;
  1331. }
  1332. };
  1333. this.SOF_GetCertInfo = function (Base64EncodeCert, Type) {
  1334. var json = '{"function":"SOF_GetCertInfo", "base64EncodeCert":"' + Base64EncodeCert + '", "type":' + Type + '}';
  1335. if (linuxWin == 2) {
  1336. var retJSON = "";
  1337. try {
  1338. retJSON = AjaxIO(json);
  1339. } catch (e) {
  1340. return -3;
  1341. }
  1342. if (retJSON.length > 3) {
  1343. var obj = eval("(" + retJSON + ")");
  1344. return obj.info;
  1345. } else {
  1346. return -2;
  1347. }
  1348. } else {
  1349. try {
  1350. AjaxIO(json);
  1351. } catch (e) {
  1352. return -3;
  1353. }
  1354. var ret = GetHttpResult();
  1355. if (ret) {
  1356. return ret.info;
  1357. }
  1358. return -2;
  1359. }
  1360. };
  1361. this.SOF_GetCertInfoByOid = function (Base64EncodeCert, OID) {
  1362. var json = '{"function":"SOF_GetCertInfoByOid", "base64EncodeCert":"' + Base64EncodeCert + '", "oid":"' + OID + '"}';
  1363. if (linuxWin == 2) {
  1364. var retJSON = "";
  1365. try {
  1366. retJSON = AjaxIO(json);
  1367. } catch (e) {
  1368. return -3;
  1369. }
  1370. if (retJSON.length > 3) {
  1371. var obj = eval("(" + retJSON + ")");
  1372. return obj.info;
  1373. } else {
  1374. return -2;
  1375. }
  1376. } else {
  1377. try {
  1378. AjaxIO(json);
  1379. }
  1380. catch (e) {
  1381. return -3;
  1382. }
  1383. var ret = GetHttpResult();
  1384. if (ret) {
  1385. return ret.info;
  1386. }
  1387. return null;
  1388. }
  1389. };
  1390. this.SOF_Login = function (PassWd) {
  1391. var json = '{"function":"SOF_Login", "deviceName":"' + _curDevName + '", "passWd":"' + PassWd + '"}';
  1392. if (linuxWin == 2) {
  1393. var retJSON = "";
  1394. try {
  1395. retJSON = AjaxIO(json);
  1396. } catch (e) {
  1397. return -3;
  1398. }
  1399. if (retJSON.length > 3) {
  1400. var obj = eval("(" + retJSON + ")");
  1401. return obj.rtn;
  1402. } else {
  1403. return -2;
  1404. }
  1405. } else {
  1406. try {
  1407. AjaxIO(json);
  1408. } catch (e) {
  1409. return -3;
  1410. }
  1411. var ret = GetHttpResult();
  1412. if (ret) {
  1413. return ret.rtn;
  1414. }
  1415. return -2;
  1416. }
  1417. };
  1418. this.SOF_LoginSoPin = function (PassWd) {
  1419. var json = '{"function":"SOF_LoginSoPin", "deviceName":"' + _curDevName + '", "passWd":"' + PassWd + '"}';
  1420. if (linuxWin == 2) {
  1421. var retJSON = "";
  1422. try {
  1423. retJSON = AjaxIO(json);
  1424. } catch (e) {
  1425. return -3;
  1426. }
  1427. if (retJSON.length > 3) {
  1428. var obj = eval("(" + retJSON + ")");
  1429. return obj.rtn;
  1430. } else {
  1431. return -2;
  1432. }
  1433. } else {
  1434. try {
  1435. AjaxIO(json);
  1436. } catch (e) {
  1437. return -3;
  1438. }
  1439. var ret = GetHttpResult();
  1440. if (ret) {
  1441. return ret.rtn;
  1442. }
  1443. return -2;
  1444. }
  1445. };
  1446. this.SOF_LogOut = function () {
  1447. var json = '{"function":"SOF_LogOut", "deviceName":"' + _curDevName + '"}';
  1448. if (linuxWin == 2) {
  1449. var retJSON = "";
  1450. try {
  1451. retJSON = AjaxIO(json);
  1452. } catch (e) {
  1453. return -3;
  1454. }
  1455. if (retJSON.length > 3) {
  1456. var obj = eval("(" + retJSON + ")");
  1457. return obj.rtn;
  1458. } else {
  1459. return -2;
  1460. }
  1461. } else {
  1462. try {
  1463. AjaxIO(json);
  1464. } catch (e) {
  1465. return -3;
  1466. }
  1467. var ret = GetHttpResult();
  1468. if (ret) {
  1469. return ret.rtn;
  1470. }
  1471. return -2;
  1472. }
  1473. };
  1474. this.SOF_GetPinRetryCount = function () {
  1475. var json = '{"function":"SOF_GetPinRetryCount", "deviceName":"' + _curDevName + '"}';
  1476. if (linuxWin == 2) {
  1477. var retJSON = "";
  1478. try {
  1479. retJSON = AjaxIO(json);
  1480. } catch (e) {
  1481. return -3;
  1482. }
  1483. if (retJSON.length > 3) {
  1484. var obj = eval("(" + retJSON + ")");
  1485. return obj.retryCount;
  1486. } else {
  1487. return -2;
  1488. }
  1489. } else {
  1490. try {
  1491. AjaxIO(json);
  1492. } catch (e) {
  1493. return -3;
  1494. }
  1495. var ret = GetHttpResult();
  1496. if (ret) {
  1497. return ret.retryCount;
  1498. }
  1499. return -2;
  1500. }
  1501. };
  1502. this.SOF_GetPinMaxRetryCount = function () {
  1503. var json = '{"function":"SOF_GetPinRetryCount", "deviceName":"' + _curDevName + '"}';
  1504. if (linuxWin == 2) {
  1505. var retJSON = "";
  1506. try {
  1507. retJSON = AjaxIO(json);
  1508. } catch (e) {
  1509. return -3;
  1510. }
  1511. if (retJSON.length > 3) {
  1512. var obj = eval("(" + retJSON + ")");
  1513. return obj.maxRetryCount;
  1514. } else {
  1515. return -2;
  1516. }
  1517. } else {
  1518. try {
  1519. AjaxIO(json);
  1520. } catch (e) {
  1521. return -3;
  1522. }
  1523. var ret = GetHttpResult();
  1524. if (ret) {
  1525. return ret.maxRetryCount;
  1526. }
  1527. return -2;
  1528. }
  1529. };
  1530. this.SOF_ChangePassWd = function (OldPassWd, NewPassWd) {
  1531. var json = '{"function":"SOF_ChangePassWd", "deviceName":"' + _curDevName + '", "oldUpin":"' + OldPassWd + '", "newUpin":"' + NewPassWd + '"}';
  1532. if (linuxWin == 2) {
  1533. var retJSON = "";
  1534. try {
  1535. retJSON = AjaxIO(json);
  1536. } catch (e) {
  1537. return -3;
  1538. }
  1539. if (retJSON.length > 3) {
  1540. var obj = eval("(" + retJSON + ")");
  1541. return obj.rtn;
  1542. } else {
  1543. return -2;
  1544. }
  1545. } else {
  1546. try {
  1547. AjaxIO(json);
  1548. } catch (e) {
  1549. return -3;
  1550. }
  1551. var ret = GetHttpResult();
  1552. if (ret) {
  1553. return ret.rtn;
  1554. }
  1555. return -2;
  1556. }
  1557. };
  1558. this.SOF_ChangeSoPin = function (OldPassWd, NewPassWd) {
  1559. var json = '{"function":"SOF_ChangeSoPin", "deviceName":"' + _curDevName + '", "oldUpin":"' + OldPassWd + '", "newUpin":"' + NewPassWd + '"}';
  1560. if (linuxWin == 2) {
  1561. var retJSON = "";
  1562. try {
  1563. retJSON = AjaxIO(json);
  1564. } catch (e) {
  1565. return -3;
  1566. }
  1567. if (retJSON.length > 3) {
  1568. var obj = eval("(" + retJSON + ")");
  1569. return obj.rtn;
  1570. } else {
  1571. return -2;
  1572. }
  1573. } else {
  1574. try {
  1575. AjaxIO(json);
  1576. } catch (e) {
  1577. return -3;
  1578. }
  1579. var ret = GetHttpResult();
  1580. if (ret) {
  1581. return ret.rtn;
  1582. }
  1583. return -2;
  1584. }
  1585. };
  1586. this.SOF_SetDigestMethod = function (DigestMethod) {
  1587. var json = '{"function":"SOF_SetDigestMethod","deviceName":"' + _curDevName + '", "digestMethod":' + DigestMethod + '}';
  1588. if (linuxWin == 2) {
  1589. var retJSON = "";
  1590. try {
  1591. retJSON = AjaxIO(json);
  1592. } catch (e) {
  1593. return -3;
  1594. }
  1595. if (retJSON.length > 3) {
  1596. var obj = eval("(" + retJSON + ")");
  1597. return obj.rtn;
  1598. } else {
  1599. return -2;
  1600. }
  1601. } else {
  1602. try {
  1603. AjaxIO(json);
  1604. } catch (e) {
  1605. return -3;
  1606. }
  1607. var ret = GetHttpResult();
  1608. if (ret) {
  1609. return ret.rtn;
  1610. }
  1611. return -2;
  1612. }
  1613. };
  1614. this.SOF_SetUserID = function (UserID) {
  1615. var json = '{"function":"SOF_SetUserID","deviceName":"' + _curDevName + '", "userID":"' + UserID + '"}';
  1616. if (linuxWin == 2) {
  1617. var retJSON = "";
  1618. try {
  1619. retJSON = AjaxIO(json);
  1620. } catch (e) {
  1621. return -3;
  1622. }
  1623. if (retJSON.length > 3) {
  1624. var obj = eval("(" + retJSON + ")");
  1625. return obj.rtn;
  1626. } else {
  1627. return -2;
  1628. }
  1629. } else {
  1630. try {
  1631. AjaxIO(json);
  1632. } catch (e) {
  1633. return -3;
  1634. }
  1635. var ret = GetHttpResult();
  1636. if (ret) {
  1637. return ret.rtn;
  1638. }
  1639. return -2;
  1640. }
  1641. };
  1642. this.SOF_SetEncryptMethodAndIV = function (EncryptMethod, EncryptIV) {
  1643. var json = '{"function":"SOF_SetEncryptMethodAndIV","deviceName":"' + _curDevName + '", "encryptMethod":' + EncryptMethod + ', "encryptIV":"' + EncryptIV + '"}';
  1644. if (linuxWin == 2) {
  1645. var retJSON = "";
  1646. try {
  1647. retJSON = AjaxIO(json);
  1648. } catch (e) {
  1649. return -3;
  1650. }
  1651. if (retJSON.length > 3) {
  1652. var obj = eval("(" + retJSON + ")");
  1653. return obj.rtn;
  1654. } else {
  1655. return -2;
  1656. }
  1657. } else {
  1658. try {
  1659. AjaxIO(json);
  1660. } catch (e) {
  1661. return -3;
  1662. }
  1663. var ret = GetHttpResult();
  1664. if (ret) {
  1665. return ret.rtn;
  1666. }
  1667. return -2;
  1668. }
  1669. };
  1670. this.SOF_EncryptFileToPKCS7 = function (Cert, InFile, OutFile, type) {
  1671. var json = '{"function":"SOF_EncryptFileToPKCS7", "deviceName":"' + _curDevName + '", "cert":"' + Cert + '", "inFile":"' + InFile.replace(/\\/g, '\\\\') + '", "outFile":"' + OutFile.replace(/\\/g, '\\\\') + '", "type":' + type + '}';
  1672. if (linuxWin == 2) {
  1673. var retJSON = "";
  1674. try {
  1675. retJSON = AjaxIO(json);
  1676. } catch (e) {
  1677. return -3;
  1678. }
  1679. if (retJSON.length > 3) {
  1680. var obj = eval("(" + retJSON + ")");
  1681. return obj.envelopData;
  1682. } else {
  1683. return -2;
  1684. }
  1685. } else {
  1686. try {
  1687. AjaxIO(json);
  1688. } catch (e) {
  1689. return -3;
  1690. }
  1691. var ret = GetHttpResult();
  1692. if (ret) {
  1693. return ret.envelopData;
  1694. }
  1695. return -2;
  1696. }
  1697. };
  1698. this.SOF_SignFileToPKCS7 = function (ContainerName, KeySpec, InFile) {
  1699. var json = '{"function":"SOF_SignFileToPKCS7", "deviceName":"' + _curDevName + '", "containerName":"' + ContainerName + '", "KeySpec":' + KeySpec + ', "inFile":"' + InFile.replace(/\\/g, '\\\\') + '"}';
  1700. if (linuxWin == 2) {
  1701. var retJSON = "";
  1702. try {
  1703. retJSON = AjaxIO(json);
  1704. } catch (e) {
  1705. return -3;
  1706. }
  1707. if (retJSON.length > 3) {
  1708. var obj = eval("(" + retJSON + ")");
  1709. return obj.signed;
  1710. } else {
  1711. return -2;
  1712. }
  1713. } else {
  1714. try {
  1715. AjaxIO(json);
  1716. } catch (e) {
  1717. return -3;
  1718. }
  1719. var ret = GetHttpResult();
  1720. if (ret) {
  1721. return ret.signed;
  1722. }
  1723. return -2;
  1724. }
  1725. };
  1726. this.SOF_VerifyFileToPKCS7 = function (strPkcs7Data, InFilePath) {
  1727. var json = '{"function":"SOF_VerifyFileToPKCS7", "deviceName":"' + _curDevName + '","strPkcs7Data":"' + strPkcs7Data + '", "inFile":"' + InFilePath.replace(/\\/g, '\\\\') + '"}';
  1728. if (linuxWin == 2) {
  1729. var retJSON = "";
  1730. try {
  1731. retJSON = AjaxIO(json);
  1732. } catch (e) {
  1733. return -3;
  1734. }
  1735. if (retJSON.length > 3) {
  1736. var obj = eval("(" + retJSON + ")");
  1737. return obj.rtn;
  1738. } else {
  1739. return -2;
  1740. }
  1741. } else {
  1742. try {
  1743. AjaxIO(json);
  1744. } catch (e) {
  1745. return -3;
  1746. }
  1747. var ret = GetHttpResult();
  1748. if (ret) {
  1749. return ret.rtn;
  1750. }
  1751. return -2;
  1752. }
  1753. };
  1754. this.SOF_DecryptFileToPKCS7 = function (ContainerName, keySpec, Pkcs7Data, InFile, OutFile, type) {
  1755. var json = '{"function":"SOF_DecryptFileToPKCS7", "deviceName":"' + _curDevName + '", "containerName":"' + ContainerName + '", "keySpec":' + keySpec + ', "pkcs7Data":"' + Pkcs7Data + '", "inFile":"' + InFile.replace(/\\/g, '\\\\') + '", "outFile":"' + OutFile.replace(/\\/g, '\\\\') + '", "type":' + type + '}';
  1756. if (linuxWin == 2) {
  1757. var retJSON = "";
  1758. try {
  1759. retJSON = AjaxIO(json);
  1760. } catch (e) {
  1761. return -3;
  1762. }
  1763. if (retJSON.length > 3) {
  1764. var obj = eval("(" + retJSON + ")");
  1765. return obj.rtn;
  1766. } else {
  1767. return -2;
  1768. }
  1769. } else {
  1770. try {
  1771. AjaxIO(json);
  1772. } catch (e) {
  1773. return -3;
  1774. }
  1775. var ret = GetHttpResult();
  1776. if (ret) {
  1777. return ret.rtn;
  1778. }
  1779. return -2;
  1780. }
  1781. };
  1782. this.SOF_DigestData = function (ContainerName, InData, InDataLen) {
  1783. var json = '{"function":"SOF_DigestData","deviceName":"' + _curDevName + '", "containerName":"' + ContainerName + '", "inData":"' + InData + '", "inDataLen":' + InDataLen + '}';
  1784. if (linuxWin == 2) {
  1785. var retJSON = "";
  1786. try {
  1787. retJSON = AjaxIO(json);
  1788. } catch (e) {
  1789. return -3;
  1790. }
  1791. if (retJSON.length > 3) {
  1792. var obj = eval("(" + retJSON + ")");
  1793. return obj.digest;
  1794. } else {
  1795. return -2;
  1796. }
  1797. } else {
  1798. try {
  1799. AjaxIO(json);
  1800. } catch (e) {
  1801. return -3;
  1802. }
  1803. var ret = GetHttpResult();
  1804. if (ret) {
  1805. return ret.digest;
  1806. }
  1807. return -2;
  1808. }
  1809. };
  1810. //交互式签名
  1811. this.SOF_SignDataInteractive = function (ContainerName, ulKeySpec, inData, InDataLen) {
  1812. var InDataBase64 = inData; //对报文进行Base64编码
  1813. var json = '{"function":"SOF_SignDataInteractive", "deviceName":"' + _curDevName + '", "containerName":"' + ContainerName + '", "keySpec":' + ulKeySpec + ', "inData":"' + InDataBase64 + '", "inDataLen":' + InDataLen + '}';
  1814. if (linuxWin == 2) {
  1815. var retJSON = "";
  1816. try {
  1817. retJSON = AjaxIO(json);
  1818. } catch (e) {
  1819. return -3;
  1820. }
  1821. if (retJSON.length > 3) {
  1822. var obj = eval("(" + retJSON + ")");
  1823. return obj.signed;
  1824. } else {
  1825. return -2;
  1826. }
  1827. } else {
  1828. try {
  1829. AjaxIO(json);
  1830. }
  1831. catch (e) {
  1832. return -3;
  1833. }
  1834. var ret = GetHttpResult();
  1835. if (ret) {
  1836. return ret.signed;
  1837. }
  1838. return null;
  1839. }
  1840. };
  1841. this.SOF_SignData = function (ContainerName, ulKeySpec, InData, InDataLen, mode) {
  1842. var json = '{"function":"SOF_SignDataEx", "deviceName":"' + _curDevName + '", "containerName":"' + ContainerName + '", "keySpec":' + ulKeySpec + ', "inData":"' + InData + '", "inDataLen":' + InDataLen + ', "mode":' + mode + '}';
  1843. if (linuxWin == 2) {
  1844. var retJSON = "";
  1845. try {
  1846. retJSON = AjaxIO(json);
  1847. } catch (e) {
  1848. return -3;
  1849. }
  1850. if (retJSON.length > 3) {
  1851. var obj = eval("(" + retJSON + ")");
  1852. return obj.signed;
  1853. } else {
  1854. return -2;
  1855. }
  1856. } else {
  1857. try {
  1858. AjaxIO(json);
  1859. } catch (e) {
  1860. return -3;
  1861. }
  1862. var ret = GetHttpResult();
  1863. if (ret) {
  1864. return ret.signed;
  1865. }
  1866. return -2;
  1867. }
  1868. };
  1869. this.SOF_VerifySignedData = function (Base64EncodeCert, digestMethod, InData, SignedValue, mode) {
  1870. var json = '{"function":"SOF_VerifySignedDataEx","deviceName":"' + _curDevName + '", "base64EncodeCert":"' + Base64EncodeCert + '", "digestMethod":' + digestMethod + ', "inData":"' + InData + '", "signedValue":"' + SignedValue + '", "mode":' + mode + '}';
  1871. if (linuxWin == 2) {
  1872. var retJSON = "";
  1873. try {
  1874. retJSON = AjaxIO(json);
  1875. } catch (e) {
  1876. return -3;
  1877. }
  1878. if (retJSON.length > 3) {
  1879. var obj = eval("(" + retJSON + ")");
  1880. return obj.rtn;
  1881. } else {
  1882. return -2;
  1883. }
  1884. } else {
  1885. try {
  1886. AjaxIO(json);
  1887. } catch (e) {
  1888. return -3;
  1889. }
  1890. var ret = GetHttpResult();
  1891. if (ret) {
  1892. return ret.rtn;
  1893. }
  1894. return -2;
  1895. }
  1896. };
  1897. this.SOF_EncryptDataPKCS7 = function (Base64EncodeCert, InData, InDataLen) {
  1898. var json = '{"function":"SOF_EncryptDataPKCS7", "deviceName":"' + _curDevName + '", "base64EncodeCert":"' + Base64EncodeCert + '", "inData":"' + InData + '", "inDataLen":' + InDataLen + '}';
  1899. if (linuxWin == 2) {
  1900. var retJSON = "";
  1901. try {
  1902. retJSON = AjaxIO(json);
  1903. } catch (e) {
  1904. return -3;
  1905. }
  1906. if (retJSON.length > 3) {
  1907. var obj = eval("(" + retJSON + ")");
  1908. return obj.encrypedData;
  1909. } else {
  1910. return -2;
  1911. }
  1912. } else {
  1913. try {
  1914. AjaxIO(json);
  1915. } catch (e) {
  1916. return -3;
  1917. }
  1918. var ret = GetHttpResult();
  1919. if (ret) {
  1920. return ret.encrypedData;
  1921. }
  1922. return -2;
  1923. }
  1924. };
  1925. this.SOF_EncryptDataPKCS7EX = function (Base64EncodeCert, InData, InDataLen) {
  1926. var json = '{"function":"SOF_EncryptDataPKCS7EX", "deviceName":"' + _curDevName + '", "base64EncodeCert":"' + Base64EncodeCert + '", "inData":"' + InData + '", "inDataLen":' + InDataLen + '}';
  1927. if (linuxWin == 2) {
  1928. var retJSON = "";
  1929. try {
  1930. retJSON = AjaxIO(json);
  1931. } catch (e) {
  1932. return -3;
  1933. }
  1934. if (retJSON.length > 3) {
  1935. var obj = eval("(" + retJSON + ")");
  1936. return obj.encrypedData;
  1937. } else {
  1938. return -2;
  1939. }
  1940. } else {
  1941. try {
  1942. AjaxIO(json);
  1943. } catch (e) {
  1944. return -3;
  1945. }
  1946. var ret = GetHttpResult();
  1947. if (ret) {
  1948. return ret.encrypedData;
  1949. }
  1950. return -2;
  1951. }
  1952. };
  1953. this.SOF_DecryptDataPKCS7 = function (ContainerName, ulKeySpec, InData) {
  1954. var json = '{"function":"SOF_DecryptDataPKCS7", "deviceName":"' + _curDevName + '", "containerName":"' + ContainerName + '", "keySpec":' + ulKeySpec + ', "inData":"' + InData + '"}';
  1955. if (linuxWin == 2) {
  1956. var retJSON = "";
  1957. try {
  1958. retJSON = AjaxIO(json);
  1959. } catch (e) {
  1960. return -3;
  1961. }
  1962. if (retJSON.length > 3) {
  1963. var obj = eval("(" + retJSON + ")");
  1964. return obj.decryptedData;
  1965. } else {
  1966. return -2;
  1967. }
  1968. } else {
  1969. try {
  1970. AjaxIO(json);
  1971. } catch (e) {
  1972. return -3;
  1973. }
  1974. var ret = GetHttpResult();
  1975. if (ret) {
  1976. return ret.decryptedData;
  1977. }
  1978. return -2;
  1979. }
  1980. };
  1981. this.SOF_DecryptDataPKCS7EX = function (ContainerName, ulKeySpec, InData) {
  1982. var json = '{"function":"SOF_DecryptDataPKCS7EX", "deviceName":"' + _curDevName + '", "containerName":"' + ContainerName + '", "keySpec":' + ulKeySpec + ', "inData":"' + InData + '"}';
  1983. if (linuxWin == 2) {
  1984. var retJSON = "";
  1985. try {
  1986. retJSON = AjaxIO(json);
  1987. } catch (e) {
  1988. return -3;
  1989. }
  1990. if (retJSON.length > 3) {
  1991. var obj = eval("(" + retJSON + ")");
  1992. return obj.decryptedData;
  1993. } else {
  1994. return -2;
  1995. }
  1996. } else {
  1997. try {
  1998. AjaxIO(json);
  1999. } catch (e) {
  2000. return -3;
  2001. }
  2002. var ret = GetHttpResult();
  2003. if (ret) {
  2004. return ret.decryptedData;
  2005. }
  2006. return -2;
  2007. }
  2008. };
  2009. this.SOF_GenRemoteUnblockRequest = function () {
  2010. var json = '{"function":"SOF_GenRemoteUnblockRequest", "deviceName":"' + _curDevName + '"}';
  2011. if (linuxWin == 2) {
  2012. var retJSON = "";
  2013. try {
  2014. retJSON = AjaxIO(json);
  2015. } catch (e) {
  2016. return -3;
  2017. }
  2018. if (retJSON.length > 3) {
  2019. var obj = eval("(" + retJSON + ")");
  2020. return obj.request;
  2021. } else {
  2022. return -2;
  2023. }
  2024. } else {
  2025. try {
  2026. AjaxIO(json);
  2027. } catch (e) {
  2028. return -3;
  2029. }
  2030. var ret = GetHttpResult();
  2031. if (ret) {
  2032. return ret.request;
  2033. }
  2034. return -2;
  2035. }
  2036. };
  2037. this.SOF_GenResetpwdResponse = function (request, soPin, userPin) {
  2038. var json = '{"function":"SOF_GenResetpwdResponse", "deviceName":"' + _curDevName + '", "request":"' + request + '", "soPin":"' + soPin + '", "userPin":"' + userPin + '"}';
  2039. if (linuxWin == 2) {
  2040. var retJSON = "";
  2041. try {
  2042. retJSON = AjaxIO(json);
  2043. } catch (e) {
  2044. return -3;
  2045. }
  2046. if (retJSON.length > 3) {
  2047. var obj = eval("(" + retJSON + ")");
  2048. return obj.request;
  2049. } else {
  2050. return -2;
  2051. }
  2052. } else {
  2053. try {
  2054. AjaxIO(json);
  2055. } catch (e) {
  2056. return -3;
  2057. }
  2058. var ret = GetHttpResult();
  2059. if (ret) {
  2060. return ret.request;
  2061. }
  2062. return -2;
  2063. }
  2064. };
  2065. this.SOF_RemoteUnblockPIN = function (request) {
  2066. var json = '{"function":"SOF_RemoteUnblockPIN", "deviceName":"' + _curDevName + '", "request":"' + request + '"}';
  2067. if (linuxWin == 2) {
  2068. var retJSON = "";
  2069. try {
  2070. retJSON = AjaxIO(json);
  2071. } catch (e) {
  2072. return -3;
  2073. }
  2074. if (retJSON.length > 3) {
  2075. var obj = eval("(" + retJSON + ")");
  2076. return obj.rtn;
  2077. } else {
  2078. return -2;
  2079. }
  2080. } else {
  2081. try {
  2082. AjaxIO(json);
  2083. } catch (e) {
  2084. return -3;
  2085. }
  2086. var ret = GetHttpResult();
  2087. if (ret) {
  2088. return ret.rtn;
  2089. }
  2090. return -2;
  2091. }
  2092. };
  2093. this.SOF_SignDataToPKCS7 = function (ContainerName, ulKeySpec, InData, ulDetached) {
  2094. var json = '{"function":"SOF_SignDataToPKCS7", "deviceName":"' + _curDevName + '", "containerName":"' + ContainerName + '", "keySpec":' + ulKeySpec + ', "inData":"' + InData + '", "detached":' + ulDetached + '}';
  2095. if (linuxWin == 2) {
  2096. var retJSON = "";
  2097. try {
  2098. retJSON = AjaxIO(json);
  2099. } catch (e) {
  2100. return -3;
  2101. }
  2102. if (retJSON.length > 3) {
  2103. var obj = eval("(" + retJSON + ")");
  2104. return obj.pkcs7;
  2105. } else {
  2106. return -2;
  2107. }
  2108. } else {
  2109. try {
  2110. AjaxIO(json);
  2111. } catch (e) {
  2112. return -3;
  2113. }
  2114. var ret = GetHttpResult();
  2115. if (ret) {
  2116. return ret.pkcs7;
  2117. }
  2118. return -2;
  2119. }
  2120. };
  2121. this.SOF_VerifyDataToPKCS7 = function (strPkcs7Data, OriginalText, ulDetached) {
  2122. var json = '{"function":"SOF_VerifyDataToPKCS7", "deviceName":"' + _curDevName + '", "pkcs7":"' + strPkcs7Data + '", "original":"' + OriginalText + '", "detached":' + ulDetached + '}';
  2123. if (linuxWin == 2) {
  2124. var retJSON = "";
  2125. try {
  2126. retJSON = AjaxIO(json);
  2127. } catch (e) {
  2128. return -3;
  2129. }
  2130. if (retJSON.length > 3) {
  2131. var obj = eval("(" + retJSON + ")");
  2132. return obj.rtn;
  2133. } else {
  2134. return -2;
  2135. }
  2136. } else {
  2137. try {
  2138. AjaxIO(json);
  2139. } catch (e) {
  2140. return -3;
  2141. }
  2142. var ret = GetHttpResult();
  2143. if (ret) {
  2144. return ret.rtn;
  2145. }
  2146. return -2;
  2147. }
  2148. };
  2149. this.SOF_VerifyDigestDataToPKCS7 = function (strPkcs7Data, OriginalText, ulDetached) {
  2150. var json = '{"function":"SOF_VerifyDigestDataToPKCS7", "deviceName":"' + _curDevName + '", "pkcs7":"' + strPkcs7Data + '", "original":"' + OriginalText + '", "detached":' + ulDetached + '}';
  2151. if (linuxWin == 2) {
  2152. var retJSON = "";
  2153. try {
  2154. retJSON = AjaxIO(json);
  2155. } catch (e) {
  2156. return -3;
  2157. }
  2158. if (retJSON.length > 3) {
  2159. var obj = eval("(" + retJSON + ")");
  2160. return obj.rtn;
  2161. } else {
  2162. return -2;
  2163. }
  2164. } else {
  2165. try {
  2166. AjaxIO(json);
  2167. } catch (e) {
  2168. return -3;
  2169. }
  2170. var ret = GetHttpResult();
  2171. if (ret) {
  2172. return ret.rtn;
  2173. }
  2174. return -2;
  2175. }
  2176. };
  2177. //按expType导出的公钥,格式为国密规范指定的格式或DER格式或裸数据格式
  2178. //expType=1: 国密格式; 2:DER; 3:RAW (SM2 public key ONLY: X|Y, X,Y各为32字节)
  2179. this.SOF_ExportPubKey = function (containerName, keySpec, expType) {
  2180. var json = '{"function":"SOF_ExportPubKeyEx","deviceName":"' + _curDevName + '", "containerName":"' + containerName + '", "keySpec":' + keySpec + ', "expType":' + expType + '}';
  2181. if (linuxWin == 2) {
  2182. var retJSON = "";
  2183. try {
  2184. retJSON = AjaxIO(json);
  2185. } catch (e) {
  2186. return -3;
  2187. }
  2188. if (retJSON.length > 3) {
  2189. var obj = eval("(" + retJSON + ")");
  2190. return obj.pubKey;
  2191. } else {
  2192. return -2;
  2193. }
  2194. } else {
  2195. try {
  2196. AjaxIO(json);
  2197. } catch (e) {
  2198. return -3;
  2199. }
  2200. var ret = GetHttpResult();
  2201. if (ret) {
  2202. return ret.pubKey;
  2203. }
  2204. return -2;
  2205. }
  2206. }
  2207. this.SOF_PublicVerify = function (pubKey, inData, signedValue, digestMethod) {
  2208. var json = '{"function":"SOF_PublicVerify", "deviceName":"' + _curDevName + '", "digestMethod":' + digestMethod + ', "pubKey":"' + pubKey + '", "inData":"' + inData + '", "signedValue":"' + signedValue + '"}';
  2209. if (linuxWin == 2) {
  2210. var retJSON = "";
  2211. try {
  2212. retJSON = AjaxIO(json);
  2213. } catch (e) {
  2214. return -3;
  2215. }
  2216. if (retJSON.length > 3) {
  2217. var obj = eval("(" + retJSON + ")");
  2218. return obj.pubKey;
  2219. } else {
  2220. return -2;
  2221. }
  2222. } else {
  2223. try {
  2224. AjaxIO(json);
  2225. } catch (e) {
  2226. return -3;
  2227. }
  2228. var ret = GetHttpResult();
  2229. if (ret) {
  2230. return ret.rtn;
  2231. }
  2232. return -2;
  2233. }
  2234. }
  2235. //公钥加密
  2236. this.SOF_EncryptByPubKey = function (strPubKey, strInput, cerType) {
  2237. var json = '{"function":"SOF_EncryptByPubKey", "deviceName":"' + _curDevName + '", "pubKey":"' + strPubKey + '", "asymPlain":"' + strInput + '", "keySpec":' + cerType + '}';
  2238. if (linuxWin == 2) {
  2239. var retJSON = "";
  2240. try {
  2241. retJSON = AjaxIO(json);
  2242. } catch (e) {
  2243. return -3;
  2244. }
  2245. if (retJSON.length > 3) {
  2246. var obj = eval("(" + retJSON + ")");
  2247. return obj.asymCipher;
  2248. } else {
  2249. return -2;
  2250. }
  2251. } else {
  2252. try {
  2253. AjaxIO(json);
  2254. }
  2255. catch (e) {
  2256. return -3;
  2257. }
  2258. var ret = GetHttpResult();
  2259. if (ret) {
  2260. return ret.asymCipher;
  2261. }
  2262. return null;
  2263. }
  2264. }
  2265. //私钥解密
  2266. this.SOF_DecryptByPrvKey = function (containerName, cerType, strAsymCipher) {
  2267. var json = '{"function":"SOF_DecryptByPrvKey", "deviceName":"' + _curDevName + '", "containerName":"' + containerName + '", "asymCipher":"' + strAsymCipher + '", "keySpec":' + cerType + '}';
  2268. if (linuxWin == 2) {
  2269. var retJSON = "";
  2270. try {
  2271. retJSON = AjaxIO(json);
  2272. } catch (e) {
  2273. return -3;
  2274. }
  2275. if (retJSON.length > 3) {
  2276. var obj = eval("(" + retJSON + ")");
  2277. return obj.asymPlain;
  2278. } else {
  2279. return -2;
  2280. }
  2281. } else {
  2282. try {
  2283. AjaxIO(json);
  2284. }
  2285. catch (e) {
  2286. return -3;
  2287. }
  2288. var ret = GetHttpResult();
  2289. if (ret) {
  2290. return ret.asymPlain;
  2291. }
  2292. return null;
  2293. }
  2294. }
  2295. //RA客户端控件
  2296. this.SOF_CreateKeyPair = function (container, keySpec, asymAlg, keyLength) {
  2297. var json = '{"function":"SOF_CreateKeyPair","deviceName":"' + _curDevName + '", "containerName":"' + container + '", "asymAlg":' + asymAlg + ', "keySpec":' + keySpec + ',"keyLength":' + keyLength + '}';
  2298. if (linuxWin == 2) {
  2299. var retJSON = "";
  2300. try {
  2301. retJSON = AjaxIO(json);
  2302. } catch (e) {
  2303. return -3;
  2304. }
  2305. if (retJSON.length > 3) {
  2306. var obj = eval("(" + retJSON + ")");
  2307. return obj.rtn;
  2308. } else {
  2309. return -2;
  2310. }
  2311. } else {
  2312. try {
  2313. AjaxIO(json);
  2314. }
  2315. catch (e) {
  2316. return -3;
  2317. }
  2318. var ret = GetHttpResult();
  2319. if (ret) {
  2320. return ret.rtn;
  2321. }
  2322. return -2;
  2323. }
  2324. }
  2325. this.SOF_EnumCertContiner = function () {
  2326. var json = '{"function":"SOF_EnumCertContiner", "deviceName":"' + _curDevName + '"}';
  2327. if (linuxWin == 2) {
  2328. var retJSON = "";
  2329. try {
  2330. retJSON = AjaxIO(json);
  2331. } catch (e) {
  2332. return -3;
  2333. }
  2334. if (retJSON.length > 3) {
  2335. var obj = eval("(" + retJSON + ")");
  2336. return obj.containerName;
  2337. } else {
  2338. return -2;
  2339. }
  2340. } else {
  2341. try {
  2342. AjaxIO(json);
  2343. }
  2344. catch (e) {
  2345. return -3;
  2346. }
  2347. var ret = GetHttpResult();
  2348. if (ret) {
  2349. return ret.containerName;
  2350. }
  2351. return "";
  2352. }
  2353. }
  2354. this.SOF_CreateContainer = function (containerName) {
  2355. var json = '{"function":"SOF_CreateContainer","deviceName":"' + _curDevName + '", "containerName":"' + containerName + '"}';
  2356. if (linuxWin == 2) {
  2357. var retJSON = "";
  2358. try {
  2359. retJSON = AjaxIO(json);
  2360. } catch (e) {
  2361. return -3;
  2362. }
  2363. if (retJSON.length > 3) {
  2364. var obj = eval("(" + retJSON + ")");
  2365. return obj.rtn;
  2366. } else {
  2367. return -2;
  2368. }
  2369. } else {
  2370. try {
  2371. AjaxIO(json);
  2372. }
  2373. catch (e) {
  2374. return -3;
  2375. }
  2376. var ret = GetHttpResult();
  2377. if (ret) {
  2378. return ret.rtn;
  2379. }
  2380. return "";
  2381. }
  2382. }
  2383. this.SOF_FindContainer = function (certSN) {
  2384. var json = '{"function":"SOF_FindContainer","deviceName":"' + _curDevName + '", "certSN":"' + certSN + '"}';
  2385. if (linuxWin == 2) {
  2386. var retJSON = "";
  2387. try {
  2388. retJSON = AjaxIO(json);
  2389. } catch (e) {
  2390. return -3;
  2391. }
  2392. if (retJSON.length > 3) {
  2393. var obj = eval("(" + retJSON + ")");
  2394. return obj.containerName;
  2395. } else {
  2396. return -2;
  2397. }
  2398. } else {
  2399. try {
  2400. AjaxIO(json);
  2401. }
  2402. catch (e) {
  2403. return -3;
  2404. }
  2405. var ret = GetHttpResult();
  2406. if (ret) {
  2407. return ret.containerName;
  2408. }
  2409. return "";
  2410. }
  2411. }
  2412. this.SOF_DeleteCert = function (certSN) {
  2413. var json = '{"function":"SOF_DeleteCert","deviceName":"' + _curDevName + '", "certSN":"' + certSN + '"}';
  2414. if (linuxWin == 2) {
  2415. var retJSON = "";
  2416. try {
  2417. retJSON = AjaxIO(json);
  2418. } catch (e) {
  2419. return -3;
  2420. }
  2421. if (retJSON.length > 3) {
  2422. var obj = eval("(" + retJSON + ")");
  2423. return obj.rtn;
  2424. } else {
  2425. return -2;
  2426. }
  2427. } else {
  2428. try {
  2429. AjaxIO(json);
  2430. }
  2431. catch (e) {
  2432. return -3;
  2433. }
  2434. var ret = GetHttpResult();
  2435. if (ret) {
  2436. return ret.rtn;
  2437. }
  2438. return -2;
  2439. }
  2440. }
  2441. this.SOF_DeleteContainer = function (certSN) {
  2442. var json = '{"function":"SOF_DeleteContainer", "deviceName":"' + _curDevName + '", "certSN":"' + certSN + '"}';
  2443. if (linuxWin == 2) {
  2444. var retJSON = "";
  2445. try {
  2446. retJSON = AjaxIO(json);
  2447. } catch (e) {
  2448. return -3;
  2449. }
  2450. if (retJSON.length > 3) {
  2451. var obj = eval("(" + retJSON + ")");
  2452. return obj.rtn;
  2453. } else {
  2454. return -2;
  2455. }
  2456. } else {
  2457. try {
  2458. AjaxIO(json);
  2459. }
  2460. catch (e) {
  2461. return -3;
  2462. }
  2463. var ret = GetHttpResult();
  2464. if (ret) {
  2465. return ret.rtn;
  2466. }
  2467. return -2;
  2468. }
  2469. }
  2470. this.SOF_SignByCert = function (certSN, plain) {
  2471. var json = '{"function":"SOF_SignByCert", "deviceName":"' + _curDevName + '", "certSN":"' + certSN + '", "inData":"' + plain + '"}';
  2472. if (linuxWin == 2) {
  2473. var retJSON = "";
  2474. try {
  2475. retJSON = AjaxIO(json);
  2476. } catch (e) {
  2477. return -3;
  2478. }
  2479. if (retJSON.length > 3) {
  2480. var obj = eval("(" + retJSON + ")");
  2481. return obj.signed;
  2482. } else {
  2483. return -2;
  2484. }
  2485. } else {
  2486. try {
  2487. AjaxIO(json);
  2488. }
  2489. catch (e) {
  2490. return -3;
  2491. }
  2492. var ret = GetHttpResult();
  2493. if (ret) {
  2494. return ret.signed;
  2495. }
  2496. return null;
  2497. }
  2498. }
  2499. this.SOF_VerifyByCert = function (certSN, plain, signature, digestMethod) {
  2500. var json = '{"function":"SOF_VerifyByCert", "deviceName":"' + _curDevName + '", "certSN":"' + certSN + '","digestMethod":' + digestMethod + ', "inData":"' + plain + '", "signed":"' + signature + '"}';
  2501. if (linuxWin == 2) {
  2502. var retJSON = "";
  2503. try {
  2504. retJSON = AjaxIO(json);
  2505. } catch (e) {
  2506. return -3;
  2507. }
  2508. if (retJSON.length > 3) {
  2509. var obj = eval("(" + retJSON + ")");
  2510. return obj.rtn;
  2511. } else {
  2512. return -2;
  2513. }
  2514. } else {
  2515. try {
  2516. AjaxIO(json);
  2517. }
  2518. catch (e) {
  2519. return -3;
  2520. }
  2521. var ret = GetHttpResult();
  2522. if (ret) {
  2523. return ret.rtn;
  2524. }
  2525. return -2;
  2526. }
  2527. }
  2528. this.SOF_VerifyByExtCert = function (cert, plain, signature, digestMethod) {
  2529. var json = '{"function":"SOF_VerifyByExtCert","deviceName":"' + _curDevName + '", "cert":"' + cert + '", "digestMethod":' + digestMethod + ', "inData":"' + plain + '", "signed":"' + signature + '"}';
  2530. if (linuxWin == 2) {
  2531. var retJSON = "";
  2532. try {
  2533. retJSON = AjaxIO(json);
  2534. } catch (e) {
  2535. return -3;
  2536. }
  2537. if (retJSON.length > 3) {
  2538. var obj = eval("(" + retJSON + ")");
  2539. return obj.rtn;
  2540. } else {
  2541. return -2;
  2542. }
  2543. } else {
  2544. try {
  2545. AjaxIO(json);
  2546. }
  2547. catch (e) {
  2548. return -3;
  2549. }
  2550. var ret = GetHttpResult();
  2551. if (ret) {
  2552. return ret.rtn;
  2553. }
  2554. return -2;
  2555. }
  2556. }
  2557. this.SOF_GenerateP10Request = function (_curDevName, container, dn, asymAlg, keySpec, keyLength) {
  2558. var json = '{"function":"SOF_GenerateP10Request", "deviceName":"' + _curDevName + '", "containerName":"' + container + '", "certDN":"' + dn + '", "asymAlg":' + asymAlg + ', "keySpec":' + keySpec + ',"keyLength":' + keyLength + '}';
  2559. if (linuxWin == 2) {
  2560. var retJSON = "";
  2561. try {
  2562. retJSON = AjaxIO(json);
  2563. } catch (e) {
  2564. return -3;
  2565. }
  2566. if (retJSON.length > 3) {
  2567. var obj = eval("(" + retJSON + ")");
  2568. return obj.outData;
  2569. } else {
  2570. return -2;
  2571. }
  2572. } else {
  2573. try {
  2574. AjaxIO(json);
  2575. }
  2576. catch (e) {
  2577. return -3;
  2578. }
  2579. var ret = GetHttpResult();
  2580. if (ret) {
  2581. return ret.outData;
  2582. }
  2583. return null;
  2584. }
  2585. }
  2586. this.SOF_ImportCert = function (container, cert, keySpec) {
  2587. var json = '{"function":"SOF_ImportCert", "deviceName":"' + _curDevName + '", "containerName":"' + container + '", "cert":"' + cert + '", "keySpec":' + keySpec + '}';
  2588. if (linuxWin == 2) {
  2589. var retJSON = "";
  2590. try {
  2591. retJSON = AjaxIO(json);
  2592. } catch (e) {
  2593. return -3;
  2594. }
  2595. if (retJSON.length > 3) {
  2596. var obj = eval("(" + retJSON + ")");
  2597. return obj.rtn;
  2598. } else {
  2599. return -2;
  2600. }
  2601. } else {
  2602. try {
  2603. AjaxIO(json);
  2604. }
  2605. catch (e) {
  2606. return -3;
  2607. }
  2608. var ret = GetHttpResult();
  2609. if (ret) {
  2610. return ret.rtn;
  2611. }
  2612. return -2;
  2613. }
  2614. }
  2615. this.SOF_ImportCryptoCertAndKey = function (container, cert, nAsymAlg, EncryptedSessionKeyData, symAlg, EncryptedPrivateKeyData, mode) {
  2616. var json = '{"function":"SOF_ImportCryptoCertAndKey", "deviceName":"' + _curDevName + '", "containerName":"' + container + '", "cert":"' + cert + '", "asymAlg":' + nAsymAlg + ', "sessionKey":"' + EncryptedSessionKeyData + '", "symAlg":"' + symAlg + '", "encrypedData":"' + EncryptedPrivateKeyData + '", "mode":"' + mode + '"}';
  2617. if (linuxWin == 2) {
  2618. var retJSON = "";
  2619. try {
  2620. retJSON = AjaxIO(json);
  2621. } catch (e) {
  2622. return -3;
  2623. }
  2624. if (retJSON.length > 3) {
  2625. var obj = eval("(" + retJSON + ")");
  2626. return obj.rtn;
  2627. } else {
  2628. return -2;
  2629. }
  2630. } else {
  2631. try {
  2632. AjaxIO(json);
  2633. }
  2634. catch (e) {
  2635. return -3;
  2636. }
  2637. var ret = GetHttpResult();
  2638. if (ret) {
  2639. return ret.rtn;
  2640. }
  2641. return -2;
  2642. }
  2643. }
  2644. this.SOF_GenerateRandom = function (length) {
  2645. var json = '{"function":"SOF_GenRandom", "deviceName":"' + _curDevName + '", "inDataLen":' + length + '}';
  2646. if (linuxWin == 2) {
  2647. var retJSON = "";
  2648. try {
  2649. retJSON = AjaxIO(json);
  2650. } catch (e) {
  2651. return -3;
  2652. }
  2653. if (retJSON.length > 3) {
  2654. var obj = eval("(" + retJSON + ")");
  2655. return obj.outData;
  2656. } else {
  2657. return -2;
  2658. }
  2659. } else {
  2660. try {
  2661. AjaxIO(json);
  2662. }
  2663. catch (e) {
  2664. return -3;
  2665. }
  2666. var ret = GetHttpResult();
  2667. if (ret) {
  2668. return ret.outData;
  2669. }
  2670. return -2;
  2671. }
  2672. }
  2673. this.SOF_SymEncryptFile = function (sessionKey, srcfile, destfile, type) {
  2674. var json = '{"function":"SOF_SymEncryptFile", "deviceName":"' + _curDevName + '", "sessionKey":"' + sessionKey + '", "inFile":"' + srcfile.replace(/\\/g, '\\\\') + '", "outFile":"' + destfile.replace(/\\/g, '\\\\') + '", "type":' + type + '}';
  2675. if (linuxWin == 2) {
  2676. var retJSON = "";
  2677. try {
  2678. retJSON = AjaxIO(json);
  2679. } catch (e) {
  2680. return -3;
  2681. }
  2682. if (retJSON.length > 3) {
  2683. var obj = eval("(" + retJSON + ")");
  2684. return obj.rtn;
  2685. } else {
  2686. return -2;
  2687. }
  2688. } else {
  2689. try {
  2690. AjaxIO(json);
  2691. }
  2692. catch (e) {
  2693. return -3;
  2694. }
  2695. var ret = GetHttpResult();
  2696. if (ret) {
  2697. return ret.rtn;
  2698. }
  2699. return -2;
  2700. }
  2701. }
  2702. this.SOF_SymDecryptFile = function (sessionKey, srcfile, destfile, type) {
  2703. var json = '{"function":"SOF_SymDecryptFile", "deviceName":"' + _curDevName + '", "sessionKey":"' + sessionKey + '", "inFile":"' + srcfile.replace(/\\/g, '\\\\') + '", "outFile":"' + destfile.replace(/\\/g, '\\\\') + '", "type":' + type + '}';
  2704. if (linuxWin == 2) {
  2705. var retJSON = "";
  2706. try {
  2707. retJSON = AjaxIO(json);
  2708. } catch (e) {
  2709. return -3;
  2710. }
  2711. if (retJSON.length > 3) {
  2712. var obj = eval("(" + retJSON + ")");
  2713. return obj.rtn;
  2714. } else {
  2715. return -2;
  2716. }
  2717. } else {
  2718. try {
  2719. AjaxIO(json);
  2720. }
  2721. catch (e) {
  2722. return -3;
  2723. }
  2724. var ret = GetHttpResult();
  2725. if (ret) {
  2726. return ret.rtn;
  2727. }
  2728. return -2;
  2729. }
  2730. }
  2731. this.SOF_SymEncryptData = function (sessionKey, inData) {
  2732. var json = '{"function":"SOF_SymEncryptData", "deviceName":"' + _curDevName + '", "sessionKey":"' + sessionKey + '", "inData":"' + inData + '"}';
  2733. if (linuxWin == 2) {
  2734. var retJSON = "";
  2735. try {
  2736. retJSON = AjaxIO(json);
  2737. } catch (e) {
  2738. return -3;
  2739. }
  2740. if (retJSON.length > 3) {
  2741. var obj = eval("(" + retJSON + ")");
  2742. return obj.outData;
  2743. } else {
  2744. return -2;
  2745. }
  2746. } else {
  2747. try {
  2748. AjaxIO(json);
  2749. }
  2750. catch (e) {
  2751. return -3;
  2752. }
  2753. var ret = GetHttpResult();
  2754. if (ret) {
  2755. return ret.outData;
  2756. }
  2757. return null;
  2758. }
  2759. }
  2760. this.SOF_SymDecryptData = function (sessionKey, inData) {
  2761. var json = '{"function":"SOF_SymDecryptData", "deviceName":"' + _curDevName + '", "sessionKey":"' + sessionKey + '", "inData":"' + inData + '"}';
  2762. if (linuxWin == 2) {
  2763. var retJSON = "";
  2764. try {
  2765. retJSON = AjaxIO(json);
  2766. } catch (e) {
  2767. return -3;
  2768. }
  2769. if (retJSON.length > 3) {
  2770. var obj = eval("(" + retJSON + ")");
  2771. return obj.outData;
  2772. } else {
  2773. return -2;
  2774. }
  2775. } else {
  2776. try {
  2777. AjaxIO(json);
  2778. }
  2779. catch (e) {
  2780. return -3;
  2781. }
  2782. var ret = GetHttpResult();
  2783. if (ret) {
  2784. return ret.outData;
  2785. }
  2786. return null;
  2787. }
  2788. }
  2789. /////////////////////////////////////////////////////////////////
  2790. this.SOF_GenerateQRCode = function (qrcode_text_in) {
  2791. var qrcode_text = qrcode_text_in.replace(/"/g, '\\"');
  2792. var json = '{"module":"libQR","function":"SOF_GenerateQRCode", "inData":"' + qrcode_text + '"}';
  2793. if (linuxWin == 2) {
  2794. var retJSON = "";
  2795. try {
  2796. retJSON = AjaxIO(json);
  2797. } catch (e) {
  2798. return -3;
  2799. }
  2800. if (retJSON.length > 3) {
  2801. var obj = eval("(" + retJSON + ")");
  2802. return obj.outData;
  2803. } else {
  2804. return -2;
  2805. }
  2806. } else {
  2807. try {
  2808. AjaxIO(json);
  2809. }
  2810. catch (e) {
  2811. return -3;
  2812. }
  2813. var ret = GetHttpResult();
  2814. if (ret) {
  2815. return ret.outData;
  2816. }
  2817. return null;
  2818. }
  2819. }
  2820. this.SOF_VerifyPinMS = function (responseKey) {
  2821. var json = '{"function":"SOF_VerifyPinMS", "deviceName":"' + _curDevName + '", "passWd":"' + responseKey + '"}';
  2822. if (linuxWin == 2) {
  2823. var retJSON = "";
  2824. try {
  2825. retJSON = AjaxIO(json);
  2826. } catch (e) {
  2827. return -3;
  2828. }
  2829. if (retJSON.length > 3) {
  2830. var obj = eval("(" + retJSON + ")");
  2831. return obj.rtn;
  2832. } else {
  2833. return -2;
  2834. }
  2835. } else {
  2836. try {
  2837. AjaxIO(json);
  2838. }
  2839. catch (e) {
  2840. return -3;
  2841. }
  2842. var ret = GetHttpResult();
  2843. if (ret) {
  2844. return ret.rtn;
  2845. }
  2846. return -2;
  2847. }
  2848. }
  2849. /////////////////////////////////////////////////////////////////
  2850. this.SOF_GetHardwareType = function () {
  2851. var json = '{"function":"SOF_GetHardwareType", "deviceName":"' + _curDevName + '"}';
  2852. if (linuxWin == 2) {
  2853. var retJSON = "";
  2854. try {
  2855. retJSON = AjaxIO(json);
  2856. } catch (e) {
  2857. return -3;
  2858. }
  2859. if (retJSON.length > 3) {
  2860. var obj = eval("(" + retJSON + ")");
  2861. return obj.type;
  2862. } else {
  2863. return -2;
  2864. }
  2865. } else {
  2866. try {
  2867. AjaxIO(json);
  2868. }
  2869. catch (e) {
  2870. return -3;
  2871. }
  2872. var ret = GetHttpResult();
  2873. if (ret) {
  2874. return ret.type;
  2875. }
  2876. return -2;
  2877. }
  2878. }
  2879. this.SOF_VerifyFingerprint = function () {
  2880. var json = '{"function":"SOF_VerifyFingerprint", "deviceName":"' + _curDevName + '"}';
  2881. if (linuxWin == 2) {
  2882. var retJSON = "";
  2883. try {
  2884. retJSON = AjaxIO(json);
  2885. } catch (e) {
  2886. return -3;
  2887. }
  2888. if (retJSON.length > 3) {
  2889. var obj = eval("(" + retJSON + ")");
  2890. return obj.rtn;
  2891. } else {
  2892. return -2;
  2893. }
  2894. } else {
  2895. try {
  2896. AjaxIO(json);
  2897. }
  2898. catch (e) {
  2899. return -3;
  2900. }
  2901. var ret = GetHttpResult();
  2902. if (ret) {
  2903. return ret.rtn;
  2904. }
  2905. return -2;
  2906. }
  2907. }
  2908. this.SOF_VerifyFingerprintEx = function () {
  2909. var json = '{"function":"SOF_VerifyFingerprintEx", "deviceName":"' + _curDevName + '"}';
  2910. if (linuxWin == 2) {
  2911. var retJSON = "";
  2912. try {
  2913. retJSON = AjaxIO(json);
  2914. } catch (e) {
  2915. return -3;
  2916. }
  2917. if (retJSON.length > 3) {
  2918. var obj = eval("(" + retJSON + ")");
  2919. return obj.FingerId;
  2920. } else {
  2921. return -2;
  2922. }
  2923. } else {
  2924. try {
  2925. AjaxIO(json);
  2926. }
  2927. catch (e) {
  2928. return -3;
  2929. }
  2930. var ret = GetHttpResult();
  2931. if (ret) {
  2932. if (ret.rtn != 0) {
  2933. return ret.RetryCount;
  2934. }
  2935. else {
  2936. return ret.FingerId;
  2937. }
  2938. }
  2939. return -2;
  2940. }
  2941. }
  2942. this.SOF_QueryFinger = function (fignerType) {
  2943. var json = '{"function":"SOF_QueryFinger", "deviceName":"' + _curDevName + '", "fignerType":"' + fignerType + '"}';
  2944. if (linuxWin == 2) {
  2945. var retJSON = "";
  2946. try {
  2947. retJSON = AjaxIO(json);
  2948. } catch (e) {
  2949. return -3;
  2950. }
  2951. if (retJSON.length > 3) {
  2952. var obj = eval("(" + retJSON + ")");
  2953. return obj.FingerId;
  2954. } else {
  2955. return -2;
  2956. }
  2957. } else {
  2958. try {
  2959. AjaxIO(json);
  2960. }
  2961. catch (e) {
  2962. return -3;
  2963. }
  2964. var ret = GetHttpResult();
  2965. if (ret) {
  2966. if (ret.rtn != 0) {
  2967. return ret.rtn;
  2968. }
  2969. else {
  2970. return ret.FingerId;
  2971. }
  2972. }
  2973. return -2;
  2974. }
  2975. }
  2976. this.SOF_EnumFiles = function () {
  2977. var json = '{"function":"SOF_EnumFiles", "deviceName":"' + _curDevName + '"}';
  2978. if (linuxWin == 2) {
  2979. var retJSON = "";
  2980. try {
  2981. retJSON = AjaxIO(json);
  2982. } catch (e) {
  2983. return -3;
  2984. }
  2985. if (retJSON.length > 3) {
  2986. var obj = eval("(" + retJSON + ")");
  2987. return obj.array;
  2988. } else {
  2989. return -2;
  2990. }
  2991. } else {
  2992. try {
  2993. AjaxIO(json);
  2994. }
  2995. catch (e) {
  2996. return -3;
  2997. }
  2998. var ret = GetHttpResult();
  2999. if (ret) {
  3000. return ret.array;
  3001. }
  3002. return -2;
  3003. }
  3004. }
  3005. this.SOF_ReadFile = function (fileName, offset, length) {
  3006. var json = '{"function":"SOF_ReadFile", "deviceName":"' + _curDevName + '", "fileName":"' + fileName + '", "offset":' + offset + ',"length":' + length + '}';
  3007. if (linuxWin == 2) {
  3008. var retJSON = "";
  3009. try {
  3010. retJSON = AjaxIO(json);
  3011. } catch (e) {
  3012. return -3;
  3013. }
  3014. if (retJSON.length > 3) {
  3015. var obj = eval("(" + retJSON + ")");
  3016. return obj.outData;
  3017. } else {
  3018. return -2;
  3019. }
  3020. } else {
  3021. try {
  3022. AjaxIO(json);
  3023. }
  3024. catch (e) {
  3025. return -3;
  3026. }
  3027. var ret = GetHttpResult();
  3028. if (ret) {
  3029. return ret.outData;
  3030. }
  3031. }
  3032. }
  3033. this.SOF_WriteFile = function (fileName, offset, data) {
  3034. var json = '{"function":"SOF_WriteFile", "deviceName":"' + _curDevName + '", "fileName":"' + fileName + '", "offset":' + offset + ',"inData":"' + data + '"}';
  3035. if (linuxWin == 2) {
  3036. var retJSON = "";
  3037. try {
  3038. retJSON = AjaxIO(json);
  3039. } catch (e) {
  3040. return -3;
  3041. }
  3042. if (retJSON.length > 3) {
  3043. var obj = eval("(" + retJSON + ")");
  3044. return obj.rtn;
  3045. } else {
  3046. return -2;
  3047. }
  3048. } else {
  3049. try {
  3050. AjaxIO(json);
  3051. }
  3052. catch (e) {
  3053. return -3;
  3054. }
  3055. var ret = GetHttpResult();
  3056. if (ret) {
  3057. return ret.rtn;
  3058. }
  3059. }
  3060. }
  3061. this.SOF_CreateFile = function (fileName, length, readRight, writeRight) {
  3062. var json = '{"function":"SOF_CreateFile", "deviceName":"' + _curDevName + '","fileName":"' + fileName + '", "length" :' + length + ', "readRight":' + readRight + ',"writeRight":' + writeRight + '}';
  3063. if (linuxWin == 2) {
  3064. var retJSON = "";
  3065. try {
  3066. retJSON = AjaxIO(json);
  3067. } catch (e) {
  3068. return -3;
  3069. }
  3070. if (retJSON.length > 3) {
  3071. var obj = eval("(" + retJSON + ")");
  3072. return obj.rtn;
  3073. } else {
  3074. return -2;
  3075. }
  3076. } else {
  3077. try {
  3078. AjaxIO(json);
  3079. }
  3080. catch (e) {
  3081. return -3;
  3082. }
  3083. var ret = GetHttpResult();
  3084. if (ret) {
  3085. return ret.rtn;
  3086. }
  3087. }
  3088. }
  3089. this.SOF_VerifyCode = function (code) {
  3090. var json = '{"function":"SOF_VerifyCode", "deviceName":"' + _curDevName + '", "inData":"' + code + '"}';
  3091. if (linuxWin == 2) {
  3092. var retJSON = "";
  3093. try {
  3094. retJSON = AjaxIO(json);
  3095. } catch (e) {
  3096. return -3;
  3097. }
  3098. if (retJSON.length > 3) {
  3099. var obj = eval("(" + retJSON + ")");
  3100. return obj.rtn;
  3101. } else {
  3102. return -2;
  3103. }
  3104. } else {
  3105. try {
  3106. AjaxIO(json);
  3107. } catch (e) {
  3108. return -3;
  3109. }
  3110. var ret = GetHttpResult();
  3111. if (ret) {
  3112. return ret.rtn;
  3113. }
  3114. return -2;
  3115. }
  3116. };
  3117. this.SOF_DeleteFile = function (fileName) {
  3118. var json = '{"function":"SOF_DeleteFile", "deviceName":"' + _curDevName + '","fileName":"' + fileName + '"}';
  3119. if (linuxWin == 2) {
  3120. var retJSON = "";
  3121. try {
  3122. retJSON = AjaxIO(json);
  3123. } catch (e) {
  3124. return -3;
  3125. }
  3126. if (retJSON.length > 3) {
  3127. var obj = eval("(" + retJSON + ")");
  3128. return obj.rtn;
  3129. } else {
  3130. return -2;
  3131. }
  3132. } else {
  3133. try {
  3134. AjaxIO(json);
  3135. }
  3136. catch (e) {
  3137. return -3;
  3138. }
  3139. var ret = GetHttpResult();
  3140. if (ret) {
  3141. return ret.rtn;
  3142. }
  3143. }
  3144. }
  3145. this.SOF_SetCrossAccess = function (crossAccess) {
  3146. var json = '{"function":"SOF_SetCrossAccess", "deviceName":"' + _curDevName + '", "crossAccess":"' + crossAccess + '"}';
  3147. if (linuxWin == 2) {
  3148. var retJSON = "";
  3149. try {
  3150. retJSON = AjaxIO(json);
  3151. } catch (e) {
  3152. return -3;
  3153. }
  3154. if (retJSON.length > 3) {
  3155. var obj = eval("(" + retJSON + ")");
  3156. return obj.rtn;
  3157. } else {
  3158. return -2;
  3159. }
  3160. } else {
  3161. try {
  3162. AjaxIO(json);
  3163. } catch (e) {
  3164. return -3;
  3165. }
  3166. var ret = GetHttpResult();
  3167. if (ret) {
  3168. return ret.rtn;
  3169. }
  3170. }
  3171. }
  3172. this.SOF_DigestInit = function (pubKey, mode) {
  3173. var json = '{"function":"SOF_DigestInit", "deviceName":"' + _curDevName + '", "mode":' + mode + ',"pubKey":"' + pubKey + '"}';
  3174. if (linuxWin == 2) {
  3175. var retJSON = "";
  3176. try {
  3177. retJSON = AjaxIO(json);
  3178. } catch (e) {
  3179. return -3;
  3180. }
  3181. if (retJSON.length > 3) {
  3182. var obj = eval("(" + retJSON + ")");
  3183. return obj.rtn;
  3184. } else {
  3185. return -2;
  3186. }
  3187. } else {
  3188. try {
  3189. AjaxIO(json);
  3190. } catch (e) {
  3191. return -3;
  3192. }
  3193. var ret = GetHttpResult();
  3194. if (ret) {
  3195. return ret.rtn;
  3196. }
  3197. }
  3198. }
  3199. this.SOF_DigestUpdate = function (inData) {
  3200. var json = '{"function":"SOF_DigestUpdate", "deviceName":"' + _curDevName + '", "inData":"' + inData + '"}';
  3201. if (linuxWin == 2) {
  3202. var retJSON = "";
  3203. try {
  3204. retJSON = AjaxIO(json);
  3205. } catch (e) {
  3206. return -3;
  3207. }
  3208. if (retJSON.length > 3) {
  3209. var obj = eval("(" + retJSON + ")");
  3210. return obj.rtn;
  3211. } else {
  3212. return -2;
  3213. }
  3214. } else {
  3215. try {
  3216. AjaxIO(json);
  3217. } catch (e) {
  3218. return -3;
  3219. }
  3220. var ret = GetHttpResult();
  3221. if (ret) {
  3222. return ret.rtn;
  3223. }
  3224. }
  3225. }
  3226. this.SOF_DigestFinal = function () {
  3227. var json = '{"function":"SOF_DigestFinal", "deviceName":"' + _curDevName + '"}';
  3228. if (linuxWin == 2) {
  3229. var retJSON = "";
  3230. try {
  3231. retJSON = AjaxIO(json);
  3232. } catch (e) {
  3233. return -3;
  3234. }
  3235. if (retJSON.length > 3) {
  3236. var obj = eval("(" + retJSON + ")");
  3237. return obj.digest;
  3238. } else {
  3239. return -2;
  3240. }
  3241. } else {
  3242. try {
  3243. AjaxIO(json);
  3244. } catch (e) {
  3245. return -3;
  3246. }
  3247. var ret = GetHttpResult();
  3248. if (ret) {
  3249. return ret.digest;
  3250. }
  3251. }
  3252. }
  3253. this.SOF_DigestToSignData = function (ContainerName, ulKeySpec, singedType, hashData) {
  3254. var json = '{"function":"SOF_DigestToSignData", "deviceName":"' + _curDevName + '", "containerName":"' + ContainerName + '", "keySpec":' + ulKeySpec + ',"strSignedType":"' + singedType + '", "inData":"' + hashData + '"}';
  3255. if (linuxWin == 2) {
  3256. var retJSON = "";
  3257. try {
  3258. retJSON = AjaxIO(json);
  3259. } catch (e) {
  3260. return -3;
  3261. }
  3262. if (retJSON.length > 3) {
  3263. var obj = eval("(" + retJSON + ")");
  3264. return obj.signed;
  3265. } else {
  3266. return -2;
  3267. }
  3268. } else {
  3269. try {
  3270. AjaxIO(json);
  3271. } catch (e) {
  3272. return -3;
  3273. }
  3274. var ret = GetHttpResult();
  3275. if (ret) {
  3276. return ret.signed;
  3277. }
  3278. return -2;
  3279. }
  3280. }
  3281. this.SOF_IsVerifyPIN = function () {
  3282. var json = '{"function":"SOF_IsVerifyPIN", "deviceName":"' + _curDevName + '"}';
  3283. if (linuxWin == 2) {
  3284. var retJSON = "";
  3285. try {
  3286. retJSON = AjaxIO(json);
  3287. } catch (e) {
  3288. return -3;
  3289. }
  3290. if (retJSON.length > 3) {
  3291. var obj = eval("(" + retJSON + ")");
  3292. return obj.rtn;
  3293. } else {
  3294. return -2;
  3295. }
  3296. } else {
  3297. try {
  3298. AjaxIO(json);
  3299. } catch (e) {
  3300. return -3;
  3301. }
  3302. var ret = GetHttpResult();
  3303. if (ret) {
  3304. return ret.rtn;
  3305. }
  3306. }
  3307. }
  3308. //Socket API
  3309. this.SocketConnect = function (HostName, Port) {
  3310. var json = '{"module":"libSocket","function":"SocketConnect", "HostName":"' + HostName + '", "Port":' + Port + '}';
  3311. if (linuxWin == 2) {
  3312. var retJSON = "";
  3313. try {
  3314. retJSON = AjaxIO(json);
  3315. } catch (e) {
  3316. return -3;
  3317. }
  3318. if (retJSON.length > 3) {
  3319. var obj = eval("(" + retJSON + ")");
  3320. return obj.rtn;
  3321. } else {
  3322. return -2;
  3323. }
  3324. } else {
  3325. try {
  3326. AjaxIO(json);
  3327. }
  3328. catch (e) {
  3329. return -3;
  3330. }
  3331. var ret = GetHttpResult();
  3332. if (ret) {
  3333. return ret.rtn;
  3334. }
  3335. }
  3336. }
  3337. this.SocketDisConnect = function () {
  3338. var json = '{"module":"libSocket","function":"SocketDisConnect"}';
  3339. if (linuxWin == 2) {
  3340. var retJSON = "";
  3341. try {
  3342. retJSON = AjaxIO(json);
  3343. } catch (e) {
  3344. return -3;
  3345. }
  3346. if (retJSON.length > 3) {
  3347. var obj = eval("(" + retJSON + ")");
  3348. return obj.rtn;
  3349. } else {
  3350. return -2;
  3351. }
  3352. } else {
  3353. try {
  3354. AjaxIO(json);
  3355. }
  3356. catch (e) {
  3357. return -3;
  3358. }
  3359. var ret = GetHttpResult();
  3360. if (ret) {
  3361. return ret.rtn;
  3362. }
  3363. }
  3364. }
  3365. this.SocketSendText = function (SendText) {
  3366. var json = '{"module":"libSocket","function":"SocketSendText", "SendText":"' + SendText + '"}';
  3367. if (linuxWin == 2) {
  3368. var retJSON = "";
  3369. try {
  3370. retJSON = AjaxIO(json);
  3371. } catch (e) {
  3372. return -3;
  3373. }
  3374. if (retJSON.length > 3) {
  3375. var obj = eval("(" + retJSON + ")");
  3376. return obj.RecvText;
  3377. } else {
  3378. return -2;
  3379. }
  3380. } else {
  3381. try {
  3382. AjaxIO(json);
  3383. }
  3384. catch (e) {
  3385. return -3;
  3386. }
  3387. var ret = GetHttpResult();
  3388. if (ret) {
  3389. return ret.RecvText;
  3390. }
  3391. }
  3392. }
  3393. this.SOF_SetLabel = function (Label) {
  3394. var json = '{"function":"SOF_SetLabel", "deviceName":"' + _curDevName + '", "Label":"' + Label + '"}';
  3395. if (linuxWin == 2) {
  3396. var retJSON = "";
  3397. try {
  3398. retJSON = AjaxIO(json);
  3399. } catch (e) {
  3400. return -3;
  3401. }
  3402. if (retJSON.length > 3) {
  3403. var obj = eval("(" + retJSON + ")");
  3404. return obj.rtn;
  3405. } else {
  3406. return -2;
  3407. }
  3408. } else {
  3409. try {
  3410. AjaxIO(json);
  3411. } catch (e) {
  3412. return -3;
  3413. }
  3414. var ret = GetHttpResult();
  3415. if (ret) {
  3416. return ret.rtn;
  3417. }
  3418. return -2;
  3419. }
  3420. };
  3421. }