1. import java.math.BigInteger;
  2. import java.security.NoSuchAlgorithmException;
  3. import java.security.SecureRandom;
  4. import java.util.Base64;
  5. import org.bouncycastle.asn1.gm.GMNamedCurves;
  6. import org.bouncycastle.asn1.x9.X9ECParameters;
  7. import org.bouncycastle.crypto.AsymmetricCipherKeyPair;
  8. import org.bouncycastle.crypto.InvalidCipherTextException;
  9. import org.bouncycastle.crypto.engines.SM2Engine;
  10. import org.bouncycastle.crypto.generators.ECKeyPairGenerator;
  11. import org.bouncycastle.crypto.params.ECDomainParameters;
  12. import org.bouncycastle.crypto.params.ECKeyGenerationParameters;
  13. import org.bouncycastle.crypto.params.ECPrivateKeyParameters;
  14. import org.bouncycastle.crypto.params.ECPublicKeyParameters;
  15. import org.bouncycastle.math.ec.ECPoint;
  16. import org.bouncycastle.util.encoders.Hex;
  17.  
  18. /**
  19. * Created by nsw2018 on 2021-07-26.
  20. * Sm2加密、解密算法类
  21. */
  22. public class Sm2Utils {
  23.  
  24. //流程 通过后台代码生产公私钥对,公钥提供给js端用于数据加密,私钥用于js端传来的密文串解密
  25. private static ECDomainParameters domainParameters = null;
  26. private static final String privateKey = "a90be63320c8976b95cd6f96c39211447c4033bab67953f86e0d00c95c6a02a";//生成的私钥 用来解密
  27.  
  28. /**
  29. * 获取椭圆曲线
  30. */
  31. static {
  32. //生成密钥对
  33. X9ECParameters sm2ECParameters = GMNamedCurves.getByName("sm2p256v1");
  34. domainParameters = new ECDomainParameters(sm2ECParameters.getCurve(), sm2ECParameters.getG(), sm2ECParameters.getN());
  35. }
  36.  
  37. public static void main(String args[]) throws NoSuchAlgorithmException {
  38. //私钥:a90be63320c8976b95cd6f96c39211447c4033bab67953f86e0d00c95c6a02a
  39. //公钥:042191f7d0d3467e4ae729ab19a82143e0767ff84d012cf9d7f535f29ff631bbae5fe1a6e40a366db030563a191eab19d6f1f3ce101ac5f757f012e4a0c12a31e6
  40.  
  41. //genPUPRkey();
  42.  
  43. //SM2_PRIVATEKEY
  44. //SM2_PUBLICKEY
  45.  
  46. String text = "04b164aea68b9a00960f8ce52047531460fa66d0057b3987c3c53703923effb32a003936559e9d32ad2bcc4a301b2bf0886f4da28d27032365aa1e7e62bea8174a430d97287728064e5535c2cac6d2c5cb5dccc2078fbd7da9447903db303c71aeb050aea46c10e323ca85af9cf9529b06f92acac8d2cd5f32cdf3db731ad81165a4ad94a6";
  47. verification(text);
  48. }
  49.  
  50. /**
  51. *
  52. * @方法名称 genPUPRkey
  53. * @功能描述 <pre>生成公私钥对 公钥给别人拿去加密传输数据,私钥留个自己用来解密</pre>
  54. * @作者 yw
  55. * @创建时间 2021年4月13日 下午1:57:07
  56. * @throws NoSuchAlgorithmException
  57. */
  58. public static void genPUPRkey() throws NoSuchAlgorithmException {
  59. //生成密钥对
  60. ECKeyPairGenerator keyPairGenerator = new ECKeyPairGenerator();
  61. keyPairGenerator.init(new ECKeyGenerationParameters(domainParameters, SecureRandom.getInstance("SHA1PRNG")));
  62. AsymmetricCipherKeyPair asymmetricCipherKeyPair = keyPairGenerator.generateKeyPair();
  63.  
  64. //私钥,16进制格式,自己保存,格式如80cfeb110007a9a11295b9289c4b889063f35fe66e54d53fdbb5b8aa335d665a
  65. BigInteger privatekey = ((ECPrivateKeyParameters) asymmetricCipherKeyPair.getPrivate()).getD();
  66. String privateKeyHex = privatekey.toString(16);
  67. System.out.println("私钥:" + privateKeyHex);
  68.  
  69. //公钥,16进制格式,发给前端,格式如0467e8c00b1fc2049aa006e75a7216eaf1fb42347b664ea63897917f1281427fa22254d39a3f5fd38e6773edc5eddc074dae27bfbe82d13094bfcbe6b344e89ee9
  70. ECPoint ecPoint = ((ECPublicKeyParameters) asymmetricCipherKeyPair.getPublic()).getQ();
  71. String publicKeyHex = Hex.toHexString(ecPoint.getEncoded(false));
  72. System.out.println("公钥:" + publicKeyHex);
  73. }
  74.  
  75. /**
  76. * 解密
  77. * @方法名称 decrypt
  78. * @功能描述 <pre></pre>
  79. * @作者 yw
  80. * @创建时间 2021年4月13日 下午2:09:59
  81. * @param ciphertext
  82. * @param privatekey
  83. * @throws InvalidCipherTextException
  84. */
  85. public static String decrypt(String ciphertext, String privatekey) throws InvalidCipherTextException {
  86. String cipherData = ciphertext;//JS加密产生的密文
  87. byte[] cipherDataByte = Hex.decode(cipherData);//格式转换
  88.  
  89. BigInteger privateKeyD = new BigInteger(privatekey, 16);//私钥Hex,还原私钥
  90. ECPrivateKeyParameters privateKeyParameters = new ECPrivateKeyParameters(privateKeyD, domainParameters);
  91.  
  92. //用私钥解密
  93. SM2Engine sm2Engine = new SM2Engine();
  94. sm2Engine.init(false, privateKeyParameters);
  95.  
  96. //processBlock得到Base64格式,记得解码
  97. byte[] arrayOfBytes = Base64.getDecoder().decode(sm2Engine.processBlock(cipherDataByte, 0, cipherDataByte.length));
  98.  
  99. //得到明文:SM2 Encryption Test
  100. String mtext = new String(arrayOfBytes);
  101. //System.out.println(mtext);
  102. return mtext;
  103. }
  104.  
  105. /**
  106. *
  107. * @方法名称 verification
  108. * @功能描述 <pre>js的密文校验</pre>
  109. * @作者 yw
  110. * @创建时间 2021年4月13日 下午2:13:07
  111. * @param ciphertext
  112. * @return
  113. */
  114. public static String verification(String ciphertext) {
  115. String mtext = "";//明文
  116. try {
  117. mtext = decrypt(ciphertext, privateKey);
  118. System.out.println("mtext:" + mtext);
  119. } catch (InvalidCipherTextException e) {
  120. e.printStackTrace();
  121. }
  122. return mtext;
  123. }
  124.  
  125. }

前台加密 sm2.js

  1. function SM2Cipher(a) {
  2. this.ct = 1  ;
  3. this.sm3c3 = this.sm3keybase = this.p2 = null;
  4. this.key = Array(32);
  5. this.keyOff = 0;
  6. this.cipherMode = "undefined" != typeof a ? a : SM2CipherMode.C1C3C2
  7. }
  8. (function (global, undefined) {
  9. "use strict";
  10. var SM2CipherMode = {
  11. C1C2C3: "0",
  12. C1C3C2: "1"
  13. };
  14. (function () {
  15. function a(a, c) {
  16. var b = (this._lBlock >>> a ^ this._rBlock) & c;
  17. this._rBlock ^= b;
  18. this._lBlock ^= b << a
  19. }
  20.  
  21. function b(a, c) {
  22. var b = (this._rBlock >>> a ^ this._lBlock) & c;
  23. this._lBlock ^= b;
  24. this._rBlock ^= b << a
  25. }
  26. var c = CryptoJS,
  27. d = c.lib,
  28. e = d.WordArray,
  29. d = d.BlockCipher,
  30. f = c.algo,
  31. g = [57, 49, 41, 33, 25, 17, 9, 1, 58, 50, 42, 34, 26, 18, 10, 2, 59, 51, 43, 35, 27, 19, 11, 3, 60, 52, 44, 36, 63, 55, 47, 39, 31, 23, 15, 7, 62, 54, 46, 38, 30, 22, 14, 6, 61, 53, 45, 37, 29, 21, 13, 5, 28, 20, 12, 4],
  32. h = [14, 17, 11, 24, 1, 5, 3, 28, 15, 6, 21, 10, 23, 19, 12, 4, 26, 8, 16, 7, 27, 20, 13, 2, 41, 52, 31, 37, 47, 55, 30, 40, 51, 45, 33, 48, 44, 49, 39, 56, 34, 53, 46, 42, 50, 36, 29, 32],
  33. k = [1, 2, 4, 6, 8, 10, 12, 14, 15, 17, 19, 21, 23, 25, 27, 28],
  34. l = [{
  35. 0: 8421888,
  36. 268435456: 32768,
  37. 536870912: 8421378,
  38. 805306368: 2,
  39. 1073741824: 512,
  40. 1342177280: 8421890,
  41. 1610612736: 8389122,
  42. 1879048192: 8388608,
  43. 2147483648: 514,
  44. 2415919104: 8389120,
  45. 2684354560: 33280,
  46. 2952790016: 8421376,
  47. 3221225472: 32770,
  48. 3489660928: 8388610,
  49. 3758096384: 0,
  50. 4026531840: 33282,
  51. 134217728: 0,
  52. 402653184: 8421890,
  53. 671088640: 33282,
  54. 939524096: 32768,
  55. 1207959552: 8421888,
  56. 1476395008: 512,
  57. 1744830464: 8421378,
  58. 2013265920: 2,
  59. 2281701376: 8389120,
  60. 2550136832: 33280,
  61. 2818572288: 8421376,
  62. 3087007744: 8389122,
  63. 3355443200: 8388610,
  64. 3623878656: 32770,
  65. 3892314112: 514,
  66. 4160749568: 8388608,
  67. 1: 32768,
  68. 268435457: 2,
  69. 536870913: 8421888,
  70. 805306369: 8388608,
  71. 1073741825: 8421378,
  72. 1342177281: 33280,
  73. 1610612737: 512,
  74. 1879048193: 8389122,
  75. 2147483649: 8421890,
  76. 2415919105: 8421376,
  77. 2684354561: 8388610,
  78. 2952790017: 33282,
  79. 3221225473: 514,
  80. 3489660929: 8389120,
  81. 3758096385: 32770,
  82. 4026531841: 0,
  83. 134217729: 8421890,
  84. 402653185: 8421376,
  85. 671088641: 8388608,
  86. 939524097: 512,
  87. 1207959553: 32768,
  88. 1476395009: 8388610,
  89. 1744830465: 2,
  90. 2013265921: 33282,
  91. 2281701377: 32770,
  92. 2550136833: 8389122,
  93. 2818572289: 514,
  94. 3087007745: 8421888,
  95. 3355443201: 8389120,
  96. 3623878657: 0,
  97. 3892314113: 33280,
  98. 4160749569: 8421378
  99. }, {
  100. 0: 1074282512,
  101. 16777216: 16384,
  102. 33554432: 524288,
  103. 50331648: 1074266128,
  104. 67108864: 1073741840,
  105. 83886080: 1074282496,
  106. 100663296: 1073758208,
  107. 117440512: 16,
  108. 134217728: 540672,
  109. 150994944: 1073758224,
  110. 167772160: 1073741824,
  111. 184549376: 540688,
  112. 201326592: 524304,
  113. 218103808: 0,
  114. 234881024: 16400,
  115. 251658240: 1074266112,
  116. 8388608: 1073758208,
  117. 25165824: 540688,
  118. 41943040: 16,
  119. 58720256: 1073758224,
  120. 75497472: 1074282512,
  121. 92274688: 1073741824,
  122. 109051904: 524288,
  123. 125829120: 1074266128,
  124. 142606336: 524304,
  125. 159383552: 0,
  126. 176160768: 16384,
  127. 192937984: 1074266112,
  128. 209715200: 1073741840,
  129. 226492416: 540672,
  130. 243269632: 1074282496,
  131. 260046848: 16400,
  132. 268435456: 0,
  133. 285212672: 1074266128,
  134. 301989888: 1073758224,
  135. 318767104: 1074282496,
  136. 335544320: 1074266112,
  137. 352321536: 16,
  138. 369098752: 540688,
  139. 385875968: 16384,
  140. 402653184: 16400,
  141. 419430400: 524288,
  142. 436207616: 524304,
  143. 452984832: 1073741840,
  144. 469762048: 540672,
  145. 486539264: 1073758208,
  146. 503316480: 1073741824,
  147. 520093696: 1074282512,
  148. 276824064: 540688,
  149. 293601280: 524288,
  150. 310378496: 1074266112,
  151. 327155712: 16384,
  152. 343932928: 1073758208,
  153. 360710144: 1074282512,
  154. 377487360: 16,
  155. 394264576: 1073741824,
  156. 411041792: 1074282496,
  157. 427819008: 1073741840,
  158. 444596224: 1073758224,
  159. 461373440: 524304,
  160. 478150656: 0,
  161. 494927872: 16400,
  162. 511705088: 1074266128,
  163. 528482304: 540672
  164. }, {
  165. 0: 260,
  166. 1048576: 0,
  167. 2097152: 67109120,
  168. 3145728: 65796,
  169. 4194304: 65540,
  170. 5242880: 67108868,
  171. 6291456: 67174660,
  172. 7340032: 67174400,
  173. 8388608: 67108864,
  174. 9437184: 67174656,
  175. 10485760: 65792,
  176. 11534336: 67174404,
  177. 12582912: 67109124,
  178. 13631488: 65536,
  179. 14680064: 4,
  180. 15728640: 256,
  181. 524288: 67174656,
  182. 1572864: 67174404,
  183. 2621440: 0,
  184. 3670016: 67109120,
  185. 4718592: 67108868,
  186. 5767168: 65536,
  187. 6815744: 65540,
  188. 7864320: 260,
  189. 8912896: 4,
  190. 9961472: 256,
  191. 11010048: 67174400,
  192. 12058624: 65796,
  193. 13107200: 65792,
  194. 14155776: 67109124,
  195. 15204352: 67174660,
  196. 16252928: 67108864,
  197. 16777216: 67174656,
  198. 17825792: 65540,
  199. 18874368: 65536,
  200. 19922944: 67109120,
  201. 20971520: 256,
  202. 22020096: 67174660,
  203. 23068672: 67108868,
  204. 24117248: 0,
  205. 25165824: 67109124,
  206. 26214400: 67108864,
  207. 27262976: 4,
  208. 28311552: 65792,
  209. 29360128: 67174400,
  210. 30408704: 260,
  211. 31457280: 65796,
  212. 32505856: 67174404,
  213. 17301504: 67108864,
  214. 18350080: 260,
  215. 19398656: 67174656,
  216. 20447232: 0,
  217. 21495808: 65540,
  218. 22544384: 67109120,
  219. 23592960: 256,
  220. 24641536: 67174404,
  221. 25690112: 65536,
  222. 26738688: 67174660,
  223. 27787264: 65796,
  224. 28835840: 67108868,
  225. 29884416: 67109124,
  226. 30932992: 67174400,
  227. 31981568: 4,
  228. 33030144: 65792
  229. }, {
  230. 0: 2151682048,
  231. 65536: 2147487808,
  232. 131072: 4198464,
  233. 196608: 2151677952,
  234. 262144: 0,
  235. 327680: 4198400,
  236. 393216: 2147483712,
  237. 458752: 4194368,
  238. 524288: 2147483648,
  239. 589824: 4194304,
  240. 655360: 64,
  241. 720896: 2147487744,
  242. 786432: 2151678016,
  243. 851968: 4160,
  244. 917504: 4096,
  245. 983040: 2151682112,
  246. 32768: 2147487808,
  247. 98304: 64,
  248. 163840: 2151678016,
  249. 229376: 2147487744,
  250. 294912: 4198400,
  251. 360448: 2151682112,
  252. 425984: 0,
  253. 491520: 2151677952,
  254. 557056: 4096,
  255. 622592: 2151682048,
  256. 688128: 4194304,
  257. 753664: 4160,
  258. 819200: 2147483648,
  259. 884736: 4194368,
  260. 950272: 4198464,
  261. 1015808: 2147483712,
  262. 1048576: 4194368,
  263. 1114112: 4198400,
  264. 1179648: 2147483712,
  265. 1245184: 0,
  266. 1310720: 4160,
  267. 1376256: 2151678016,
  268. 1441792: 2151682048,
  269. 1507328: 2147487808,
  270. 1572864: 2151682112,
  271. 1638400: 2147483648,
  272. 1703936: 2151677952,
  273. 1769472: 4198464,
  274. 1835008: 2147487744,
  275. 1900544: 4194304,
  276. 1966080: 64,
  277. 2031616: 4096,
  278. 1081344: 2151677952,
  279. 1146880: 2151682112,
  280. 1212416: 0,
  281. 1277952: 4198400,
  282. 1343488: 4194368,
  283. 1409024: 2147483648,
  284. 1474560: 2147487808,
  285. 1540096: 64,
  286. 1605632: 2147483712,
  287. 1671168: 4096,
  288. 1736704: 2147487744,
  289. 1802240: 2151678016,
  290. 1867776: 4160,
  291. 1933312: 2151682048,
  292. 1998848: 4194304,
  293. 2064384: 4198464
  294. }, {
  295. 0: 128,
  296. 4096: 17039360,
  297. 8192: 262144,
  298. 12288: 536870912,
  299. 16384: 537133184,
  300. 20480: 16777344,
  301. 24576: 553648256,
  302. 28672: 262272,
  303. 32768: 16777216,
  304. 36864: 537133056,
  305. 40960: 536871040,
  306. 45056: 553910400,
  307. 49152: 553910272,
  308. 53248: 0,
  309. 57344: 17039488,
  310. 61440: 553648128,
  311. 2048: 17039488,
  312. 6144: 553648256,
  313. 10240: 128,
  314. 14336: 17039360,
  315. 18432: 262144,
  316. 22528: 537133184,
  317. 26624: 553910272,
  318. 30720: 536870912,
  319. 34816: 537133056,
  320. 38912: 0,
  321. 43008: 553910400,
  322. 47104: 16777344,
  323. 51200: 536871040,
  324. 55296: 553648128,
  325. 59392: 16777216,
  326. 63488: 262272,
  327. 65536: 262144,
  328. 69632: 128,
  329. 73728: 536870912,
  330. 77824: 553648256,
  331. 81920: 16777344,
  332. 86016: 553910272,
  333. 90112: 537133184,
  334. 94208: 16777216,
  335. 98304: 553910400,
  336. 102400: 553648128,
  337. 106496: 17039360,
  338. 110592: 537133056,
  339. 114688: 262272,
  340. 118784: 536871040,
  341. 122880: 0,
  342. 126976: 17039488,
  343. 67584: 553648256,
  344. 71680: 16777216,
  345. 75776: 17039360,
  346. 79872: 537133184,
  347. 83968: 536870912,
  348. 88064: 17039488,
  349. 92160: 128,
  350. 96256: 553910272,
  351. 100352: 262272,
  352. 104448: 553910400,
  353. 108544: 0,
  354. 112640: 553648128,
  355. 116736: 16777344,
  356. 120832: 262144,
  357. 124928: 537133056,
  358. 129024: 536871040
  359. }, {
  360. 0: 268435464,
  361. 256: 8192,
  362. 512: 270532608,
  363. 768: 270540808,
  364. 1024: 268443648,
  365. 1280: 2097152,
  366. 1536: 2097160,
  367. 1792: 268435456,
  368. 2048: 0,
  369. 2304: 268443656,
  370. 2560: 2105344,
  371. 2816: 8,
  372. 3072: 270532616,
  373. 3328: 2105352,
  374. 3584: 8200,
  375. 3840: 270540800,
  376. 128: 270532608,
  377. 384: 270540808,
  378. 640: 8,
  379. 896: 2097152,
  380. 1152: 2105352,
  381. 1408: 268435464,
  382. 1664: 268443648,
  383. 1920: 8200,
  384. 2176: 2097160,
  385. 2432: 8192,
  386. 2688: 268443656,
  387. 2944: 270532616,
  388. 3200: 0,
  389. 3456: 270540800,
  390. 3712: 2105344,
  391. 3968: 268435456,
  392. 4096: 268443648,
  393. 4352: 270532616,
  394. 4608: 270540808,
  395. 4864: 8200,
  396. 5120: 2097152,
  397. 5376: 268435456,
  398. 5632: 268435464,
  399. 5888: 2105344,
  400. 6144: 2105352,
  401. 6400: 0,
  402. 6656: 8,
  403. 6912: 270532608,
  404. 7168: 8192,
  405. 7424: 268443656,
  406. 7680: 270540800,
  407. 7936: 2097160,
  408. 4224: 8,
  409. 4480: 2105344,
  410. 4736: 2097152,
  411. 4992: 268435464,
  412. 5248: 268443648,
  413. 5504: 8200,
  414. 5760: 270540808,
  415. 6016: 270532608,
  416. 6272: 270540800,
  417. 6528: 270532616,
  418. 6784: 8192,
  419. 7040: 2105352,
  420. 7296: 2097160,
  421. 7552: 0,
  422. 7808: 268435456,
  423. 8064: 268443656
  424. }, {
  425. 0: 1048576,
  426. 16: 33555457,
  427. 32: 1024,
  428. 48: 1049601,
  429. 64: 34604033,
  430. 80: 0,
  431. 96: 1,
  432. 112: 34603009,
  433. 128: 33555456,
  434. 144: 1048577,
  435. 160: 33554433,
  436. 176: 34604032,
  437. 192: 34603008,
  438. 208: 1025,
  439. 224: 1049600,
  440. 240: 33554432,
  441. 8: 34603009,
  442. 24: 0,
  443. 40: 33555457,
  444. 56: 34604032,
  445. 72: 1048576,
  446. 88: 33554433,
  447. 104: 33554432,
  448. 120: 1025,
  449. 136: 1049601,
  450. 152: 33555456,
  451. 168: 34603008,
  452. 184: 1048577,
  453. 200: 1024,
  454. 216: 34604033,
  455. 232: 1,
  456. 248: 1049600,
  457. 256: 33554432,
  458. 272: 1048576,
  459. 288: 33555457,
  460. 304: 34603009,
  461. 320: 1048577,
  462. 336: 33555456,
  463. 352: 34604032,
  464. 368: 1049601,
  465. 384: 1025,
  466. 400: 34604033,
  467. 416: 1049600,
  468. 432: 1,
  469. 448: 0,
  470. 464: 34603008,
  471. 480: 33554433,
  472. 496: 1024,
  473. 264: 1049600,
  474. 280: 33555457,
  475. 296: 34603009,
  476. 312: 1,
  477. 328: 33554432,
  478. 344: 1048576,
  479. 360: 1025,
  480. 376: 34604032,
  481. 392: 33554433,
  482. 408: 34603008,
  483. 424: 0,
  484. 440: 34604033,
  485. 456: 1049601,
  486. 472: 1024,
  487. 488: 33555456,
  488. 504: 1048577
  489. }, {
  490. 0: 134219808,
  491. 1: 131072,
  492. 2: 134217728,
  493. 3: 32,
  494. 4: 131104,
  495. 5: 134350880,
  496. 6: 134350848,
  497. 7: 2048,
  498. 8: 134348800,
  499. 9: 134219776,
  500. 10: 133120,
  501. 11: 134348832,
  502. 12: 2080,
  503. 13: 0,
  504. 14: 134217760,
  505. 15: 133152,
  506. 2147483648: 2048,
  507. 2147483649: 134350880,
  508. 2147483650: 134219808,
  509. 2147483651: 134217728,
  510. 2147483652: 134348800,
  511. 2147483653: 133120,
  512. 2147483654: 133152,
  513. 2147483655: 32,
  514. 2147483656: 134217760,
  515. 2147483657: 2080,
  516. 2147483658: 131104,
  517. 2147483659: 134350848,
  518. 2147483660: 0,
  519. 2147483661: 134348832,
  520. 2147483662: 134219776,
  521. 2147483663: 131072,
  522. 16: 133152,
  523. 17: 134350848,
  524. 18: 32,
  525. 19: 2048,
  526. 20: 134219776,
  527. 21: 134217760,
  528. 22: 134348832,
  529. 23: 131072,
  530. 24: 0,
  531. 25: 131104,
  532. 26: 134348800,
  533. 27: 134219808,
  534. 28: 134350880,
  535. 29: 133120,
  536. 30: 2080,
  537. 31: 134217728,
  538. 2147483664: 131072,
  539. 2147483665: 2048,
  540. 2147483666: 134348832,
  541. 2147483667: 133152,
  542. 2147483668: 32,
  543. 2147483669: 134348800,
  544. 2147483670: 134217728,
  545. 2147483671: 134219808,
  546. 2147483672: 134350880,
  547. 2147483673: 134217760,
  548. 2147483674: 134219776,
  549. 2147483675: 0,
  550. 2147483676: 133120,
  551. 2147483677: 2080,
  552. 2147483678: 131104,
  553. 2147483679: 134350848
  554. }],
  555. p = [4160749569, 528482304, 33030144, 2064384, 129024, 8064, 504, 2147483679],
  556. n = f.DES = d.extend({
  557. _doReset: function () {
  558. for (var a = this._key.words, c = [], b = 0; 56 > b; b++) {
  559. var d = g[b] - 1;
  560. c[b] = a[d >>> 5] >>> 31 - d % 32 & 1
  561. }
  562. a = this._subKeys = [];
  563. for (d = 0; 16 > d; d++) {
  564. for (var e = a[d] = [], f = k[d], b = 0; 24 > b; b++)
  565. e[b / 6 | 0] |= c[(h[b] - 1 + f) % 28] << 31 - b % 6,
  566. e[4 + (b / 6 | 0)] |= c[28 + (h[b + 24] - 1 + f) % 28] << 31 - b % 6;
  567. e[0] = e[0] << 1 | e[0] >>> 31;
  568. for (b = 1; 7 > b; b++)
  569. e[b] >>>= 4 * (b - 1) + 3;
  570. e[7] = e[7] << 5 | e[7] >>> 27
  571. }
  572. c = this._invSubKeys = [];
  573. for (b = 0; 16 > b; b++)
  574. c[b] = a[15 - b]
  575. },
  576. encryptBlock: function (a, c) {
  577. this._doCryptBlock(a, c, this._subKeys)
  578. },
  579. decryptBlock: function (a, c) {
  580. this._doCryptBlock(a, c, this._invSubKeys)
  581. },
  582. _doCryptBlock: function (c, d, e) {
  583. this._lBlock = c[d];
  584. this._rBlock = c[d + 1];
  585. a.call(this, 4, 252645135);
  586. a.call(this, 16, 65535);
  587. b.call(this, 2, 858993459);
  588. b.call(this, 8, 16711935);
  589. a.call(this, 1, 1431655765);
  590. for (var f = 0; 16 > f; f++) {
  591. for (var g = e[f], h = this._lBlock, k = this._rBlock, n = 0, u = 0; 8 > u; u++)
  592. n |= l[u][((k ^ g[u]) & p[u]) >>> 0];
  593. this._lBlock = k;
  594. this._rBlock = h ^ n
  595. }
  596. e = this._lBlock;
  597. this._lBlock = this._rBlock;
  598. this._rBlock = e;
  599. a.call(this, 1, 1431655765);
  600. b.call(this, 8, 16711935);
  601. b.call(this, 2, 858993459);
  602. a.call(this, 16, 65535);
  603. a.call(this, 4, 252645135);
  604. c[d] = this._lBlock;
  605. c[d + 1] = this._rBlock
  606. },
  607. keySize: 2,
  608. ivSize: 2,
  609. blockSize: 2
  610. });
  611. c.DES = d._createHelper(n);
  612. f = f.TripleDES = d.extend({
  613. _doReset: function () {
  614. var a = this._key.words;
  615. this._des1 = n.createEncryptor(e.create(a.slice(0, 2)));
  616. this._des2 = n.createEncryptor(e.create(a.slice(2, 4)));
  617. this._des3 = n.createEncryptor(e.create(a.slice(4, 6)))
  618. },
  619. encryptBlock: function (a, c) {
  620. this._des1.encryptBlock(a, c);
  621. this._des2.decryptBlock(a, c);
  622. this._des3.encryptBlock(a, c)
  623. },
  624. decryptBlock: function (a, c) {
  625. this._des3.decryptBlock(a, c);
  626. this._des2.encryptBlock(a, c);
  627. this._des1.decryptBlock(a, c)
  628. },
  629. keySize: 6,
  630. ivSize: 2,
  631. blockSize: 2
  632. });
  633. c.TripleDES = d._createHelper(f)
  634. })();
  635. (function () {
  636. var a = CryptoJS,
  637. b = a.lib.WordArray;
  638. a.enc.Base64 = {
  639. stringify: function (a) {
  640. var b = a.words,
  641. e = a.sigBytes,
  642. f = this._map;
  643. a.clamp();
  644. a = [];
  645. for (var g = 0; g < e; g += 3)
  646. for (var h = (b[g >>> 2] >>> 24 - g % 4 * 8 & 255) << 16 | (b[g + 1 >>> 2] >>> 24 - (g + 1) % 4 * 8 & 255) << 8 | b[g + 2 >>> 2] >>> 24 - (g + 2) % 4 * 8 & 255, k = 0; 4 > k && g + .75 * k < e; k++)
  647. a.push(f.charAt(h >>> 6 * (3 - k) & 63));
  648. if (b = f.charAt(64))
  649. for (; a.length % 4;)
  650. a.push(b);
  651. return a.join("")
  652. },
  653. parse: function (a) {
  654. var d = a.length,
  655. e = this._map,
  656. f = e.charAt(64);
  657. f && (f = a.indexOf(f),
  658. -1 != f && (d = f));
  659. for (var f = [], g = 0, h = 0; h < d; h++)
  660. if (h % 4) {
  661. var k = e.indexOf(a.charAt(h - 1)) << h % 4 * 2,
  662. l = e.indexOf(a.charAt(h)) >>> 6 - h % 4 * 2;
  663. f[g >>> 2] |= (k | l) << 24 - g % 4 * 8;
  664. g++
  665. }
  666. return b.create(f, g)
  667. },
  668. _map: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="
  669. }
  670. })();
  671. var dbits, canary = 0xdeadbeefcafe,
  672. j_lm = 15715070 == (canary & 16777215);
  673.  
  674. function BigInteger(a, b, c) {
  675. null != a && ("number" == typeof a ? this.fromNumber(a, b, c) : null == b && "string" != typeof a ? this.fromString(a, 256) : this.fromString(a, b))
  676. }
  677.  
  678. function nbi() {
  679. return new BigInteger(null)
  680. }
  681.  
  682. function am1(a, b, c, d, e, f) {
  683. for (; 0 <= --f;) {
  684. var g = b * this[a++] + c[d] + e;
  685. e = Math.floor(g / 67108864);
  686. c[d++] = g & 67108863
  687. }
  688. return e
  689. }
  690.  
  691. function am2(a, b, c, d, e, f) {
  692. var g = b & 32767;
  693. for (b >>= 15; 0 <= --f;) {
  694. var h = this[a] & 32767,
  695. k = this[a++] >> 15,
  696. l = b * h + k * g,
  697. h = g * h + ((l & 32767) << 15) + c[d] + (e & 1073741823);
  698. e = (h >>> 30) + (l >>> 15) + b * k + (e >>> 30);
  699. c[d++] = h & 1073741823
  700. }
  701. return e
  702. }
  703.  
  704. function am3(a, b, c, d, e, f) {
  705. var g = b & 16383;
  706. for (b >>= 14; 0 <= --f;) {
  707. var h = this[a] & 16383,
  708. k = this[a++] >> 14,
  709. l = b * h + k * g,
  710. h = g * h + ((l & 16383) << 14) + c[d] + e;
  711. e = (h >> 28) + (l >> 14) + b * k;
  712. c[d++] = h & 268435455
  713. }
  714. return e
  715. }
  716. j_lm && "Microsoft Internet Explorer" == navigator.appName ? (BigInteger.prototype.am = am2,
  717. dbits = 30) : j_lm && "Netscape" != navigator.appName ? (BigInteger.prototype.am = am1,
  718. dbits = 26) : (BigInteger.prototype.am = am3,
  719. dbits = 28);
  720. BigInteger.prototype.DB = dbits;
  721. BigInteger.prototype.DM = (1 << dbits) - 1;
  722. BigInteger.prototype.DV = 1 << dbits;
  723. var BI_FP = 52;
  724. BigInteger.prototype.FV = Math.pow(2, BI_FP);
  725. BigInteger.prototype.F1 = BI_FP - dbits;
  726. BigInteger.prototype.F2 = 2 * dbits - BI_FP;
  727. var BI_RM = "0123456789abcdefghijklmnopqrstuvwxyz",
  728. BI_RC = [],
  729. rr, vv;
  730. rr = 48;
  731. for (vv = 0; 9 >= vv; ++vv)
  732. BI_RC[rr++] = vv;
  733. rr = 97;
  734. for (vv = 10; 36 > vv; ++vv)
  735. BI_RC[rr++] = vv;
  736. rr = 65;
  737. for (vv = 10; 36 > vv; ++vv)
  738. BI_RC[rr++] = vv;
  739.  
  740. function int2char(a) {
  741. return BI_RM.charAt(a)
  742. }
  743.  
  744. function intAt(a, b) {
  745. var c = BI_RC[a.charCodeAt(b)];
  746. return null == c ? -1 : c
  747. }
  748.  
  749. function bnpCopyTo(a) {
  750. for (var b = this.t - 1; 0 <= b; --b)
  751. a[b] = this[b];
  752. a.t = this.t;
  753. a.s = this.s
  754. }
  755.  
  756. function bnpFromInt(a) {
  757. this.t = 1;
  758. this.s = 0 > a ? -1 : 0;
  759. 0 < a ? this[0] = a : -1 > a ? this[0] = a + this.DV : this.t = 0
  760. }
  761.  
  762. function nbv(a) {
  763. var b = nbi();
  764. b.fromInt(a);
  765. return b
  766. }
  767.  
  768. function bnpFromString(a, b) {
  769. var c;
  770. if (16 == b)
  771. c = 4;
  772. else if (8 == b)
  773. c = 3;
  774. else if (256 == b)
  775. c = 8;
  776. else if (2 == b)
  777. c = 1;
  778. else if (32 == b)
  779. c = 5;
  780. else if (4 == b)
  781. c = 2;
  782. else {
  783. this.fromRadix(a, b);
  784. return
  785. }
  786. this.s = this.t = 0;
  787. for (var d = a.length, e = !1, f = 0; 0 <= --d;) {
  788. var g = 8 == c ? a[d] & 255 : intAt(a, d);
  789. 0 > g ? "-" == a.charAt(d) && (e = !0) : (e = !1,
  790. 0 == f ? this[this.t++] = g : f + c > this.DB ? (this[this.t - 1] |= (g & (1 << this.DB - f) - 1) << f,
  791. this[this.t++] = g >> this.DB - f) : this[this.t - 1] |= g << f,
  792. f += c,
  793. f >= this.DB && (f -= this.DB))
  794. }
  795. 8 == c && 0 != (a[0] & 128) && (this.s = -1,
  796. 0 < f && (this[this.t - 1] |= (1 << this.DB - f) - 1 << f));
  797. this.clamp();
  798. e && BigInteger.ZERO.subTo(this, this)
  799. }
  800.  
  801. function bnpClamp() {
  802. for (var a = this.s & this.DM; 0 < this.t && this[this.t - 1] == a;)
  803. --this.t
  804. }
  805.  
  806. function bnToString(a) {
  807. if (0 > this.s)
  808. return "-" + this.negate().toString(a);
  809. if (16 == a)
  810. a = 4;
  811. else if (8 == a)
  812. a = 3;
  813. else if (2 == a)
  814. a = 1;
  815. else if (32 == a)
  816. a = 5;
  817. else if (4 == a)
  818. a = 2;
  819. else
  820. return this.toRadix(a);
  821. var b = (1 << a) - 1,
  822. c, d = !1,
  823. e = "",
  824. f = this.t,
  825. g = this.DB - f * this.DB % a;
  826. if (0 < f--)
  827. for (g < this.DB && 0 < (c = this[f] >> g) && (d = !0,
  828. e = int2char(c)); 0 <= f;)
  829. g < a ? (c = (this[f] & (1 << g) - 1) << a - g,
  830. c |= this[--f] >> (g += this.DB - a)) : (c = this[f] >> (g -= a) & b,
  831. 0 >= g && (g += this.DB,
  832. --f)),
  833. 0 < c && (d = !0),
  834. d && (e += int2char(c));
  835. return d ? e : "0"
  836. }
  837.  
  838. function bnNegate() {
  839. var a = nbi();
  840. BigInteger.ZERO.subTo(this, a);
  841. return a
  842. }
  843.  
  844. function bnAbs() {
  845. return 0 > this.s ? this.negate() : this
  846. }
  847.  
  848. function bnCompareTo(a) {
  849. var b = this.s - a.s;
  850. if (0 != b)
  851. return b;
  852. var c = this.t,
  853. b = c - a.t;
  854. if (0 != b)
  855. return 0 > this.s ? -b : b;
  856. for (; 0 <= --c;)
  857. if (0 != (b = this[c] - a[c]))
  858. return b;
  859. return 0
  860. }
  861.  
  862. function nbits(a) {
  863. var b = 1,
  864. c;
  865. 0 != (c = a >>> 16) && (a = c,
  866. b += 16);
  867. 0 != (c = a >> 8) && (a = c,
  868. b += 8);
  869. 0 != (c = a >> 4) && (a = c,
  870. b += 4);
  871. 0 != (c = a >> 2) && (a = c,
  872. b += 2);
  873. 0 != a >> 1 && (b += 1);
  874. return b
  875. }
  876.  
  877. function bnBitLength() {
  878. return 0 >= this.t ? 0 : this.DB * (this.t - 1) + nbits(this[this.t - 1] ^ this.s & this.DM)
  879. }
  880.  
  881. function bnpDLShiftTo(a, b) {
  882. var c;
  883. for (c = this.t - 1; 0 <= c; --c)
  884. b[c + a] = this[c];
  885. for (c = a - 1; 0 <= c; --c)
  886. b[c] = 0;
  887. b.t = this.t + a;
  888. b.s = this.s
  889. }
  890.  
  891. function bnpDRShiftTo(a, b) {
  892. for (var c = a; c < this.t; ++c)
  893. b[c - a] = this[c];
  894. b.t = Math.max(this.t - a, 0);
  895. b.s = this.s
  896. }
  897.  
  898. function bnpLShiftTo(a, b) {
  899. var c = a % this.DB,
  900. d = this.DB - c,
  901. e = (1 << d) - 1,
  902. f = Math.floor(a / this.DB),
  903. g = this.s << c & this.DM,
  904. h;
  905. for (h = this.t - 1; 0 <= h; --h)
  906. b[h + f + 1] = this[h] >> d | g,
  907. g = (this[h] & e) << c;
  908. for (h = f - 1; 0 <= h; --h)
  909. b[h] = 0;
  910. b[f] = g;
  911. b.t = this.t + f + 1;
  912. b.s = this.s;
  913. b.clamp()
  914. }
  915.  
  916. function bnpRShiftTo(a, b) {
  917. b.s = this.s;
  918. var c = Math.floor(a / this.DB);
  919. if (c >= this.t)
  920. b.t = 0;
  921. else {
  922. var d = a % this.DB,
  923. e = this.DB - d,
  924. f = (1 << d) - 1;
  925. b[0] = this[c] >> d;
  926. for (var g = c + 1; g < this.t; ++g)
  927. b[g - c - 1] |= (this[g] & f) << e,
  928. b[g - c] = this[g] >> d;
  929. 0 < d && (b[this.t - c - 1] |= (this.s & f) << e);
  930. b.t = this.t - c;
  931. b.clamp()
  932. }
  933. }
  934.  
  935. function bnpSubTo(a, b) {
  936. for (var c = 0, d = 0, e = Math.min(a.t, this.t); c < e;)
  937. d += this[c] - a[c],
  938. b[c++] = d & this.DM,
  939. d >>= this.DB;
  940. if (a.t < this.t) {
  941. for (d -= a.s; c < this.t;)
  942. d += this[c],
  943. b[c++] = d & this.DM,
  944. d >>= this.DB;
  945. d += this.s
  946. } else {
  947. for (d += this.s; c < a.t;)
  948. d -= a[c],
  949. b[c++] = d & this.DM,
  950. d >>= this.DB;
  951. d -= a.s
  952. }
  953. b.s = 0 > d ? -1 : 0; -
  954. 1 > d ? b[c++] = this.DV + d : 0 < d && (b[c++] = d);
  955. b.t = c;
  956. b.clamp()
  957. }
  958.  
  959. function bnpMultiplyTo(a, b) {
  960. var c = this.abs(),
  961. d = a.abs(),
  962. e = c.t;
  963. for (b.t = e + d.t; 0 <= --e;)
  964. b[e] = 0;
  965. for (e = 0; e < d.t; ++e)
  966. b[e + c.t] = c.am(0, d[e], b, e, 0, c.t);
  967. b.s = 0;
  968. b.clamp();
  969. this.s != a.s && BigInteger.ZERO.subTo(b, b)
  970. }
  971.  
  972. function bnpSquareTo(a) {
  973. for (var b = this.abs(), c = a.t = 2 * b.t; 0 <= --c;)
  974. a[c] = 0;
  975. for (c = 0; c < b.t - 1; ++c) {
  976. var d = b.am(c, b[c], a, 2 * c, 0, 1);
  977. (a[c + b.t] += b.am(c + 1, 2 * b[c], a, 2 * c + 1, d, b.t - c - 1)) >= b.DV && (a[c + b.t] -= b.DV,
  978. a[c + b.t + 1] = 1)
  979. }
  980. 0 < a.t && (a[a.t - 1] += b.am(c, b[c], a, 2 * c, 0, 1));
  981. a.s = 0;
  982. a.clamp()
  983. }
  984.  
  985. function bnpDivRemTo(a, b, c) {
  986. var d = a.abs();
  987. if (!(0 >= d.t)) {
  988. var e = this.abs();
  989. if (e.t < d.t)
  990. null != b && b.fromInt(0),
  991. null != c && this.copyTo(c);
  992. else {
  993. null == c && (c = nbi());
  994. var f = nbi(),
  995. g = this.s;
  996. a = a.s;
  997. var h = this.DB - nbits(d[d.t - 1]);
  998. 0 < h ? (d.lShiftTo(h, f),
  999. e.lShiftTo(h, c)) : (d.copyTo(f),
  1000. e.copyTo(c));
  1001. d = f.t;
  1002. e = f[d - 1];
  1003. if (0 != e) {
  1004. var k = e * (1 << this.F1) + (1 < d ? f[d - 2] >> this.F2 : 0),
  1005. l = this.FV / k,
  1006. k = (1 << this.F1) / k,
  1007. p = 1 << this.F2,
  1008. n = c.t,
  1009. q = n - d,
  1010. m = null == b ? nbi() : b;
  1011. f.dlShiftTo(q, m);
  1012. 0 <= c.compareTo(m) && (c[c.t++] = 1,
  1013. c.subTo(m, c));
  1014. BigInteger.ONE.dlShiftTo(d, m);
  1015. for (m.subTo(f, f); f.t < d;)
  1016. f[f.t++] = 0;
  1017. for (; 0 <= --q;) {
  1018. var r = c[--n] == e ? this.DM : Math.floor(c[n] * l + (c[n - 1] + p) * k);
  1019. if ((c[n] += f.am(0, r, c, q, 0, d)) < r)
  1020. for (f.dlShiftTo(q, m),
  1021. c.subTo(m, c); c[n] < --r;)
  1022. c.subTo(m, c)
  1023. }
  1024. null != b && (c.drShiftTo(d, b),
  1025. g != a && BigInteger.ZERO.subTo(b, b));
  1026. c.t = d;
  1027. c.clamp();
  1028. 0 < h && c.rShiftTo(h, c);
  1029. 0 > g && BigInteger.ZERO.subTo(c, c)
  1030. }
  1031. }
  1032. }
  1033. }
  1034.  
  1035. function bnMod(a) {
  1036. var b = nbi();
  1037. this.abs().divRemTo(a, null, b);
  1038. 0 > this.s && 0 < b.compareTo(BigInteger.ZERO) && a.subTo(b, b);
  1039. return b
  1040. }
  1041.  
  1042. function Classic(a) {
  1043. this.m = a
  1044. }
  1045.  
  1046. function cConvert(a) {
  1047. return 0 > a.s || 0 <= a.compareTo(this.m) ? a.mod(this.m) : a
  1048. }
  1049.  
  1050. function cRevert(a) {
  1051. return a
  1052. }
  1053.  
  1054. function cReduce(a) {
  1055. a.divRemTo(this.m, null, a)
  1056. }
  1057.  
  1058. function cMulTo(a, b, c) {
  1059. a.multiplyTo(b, c);
  1060. this.reduce(c)
  1061. }
  1062.  
  1063. function cSqrTo(a, b) {
  1064. a.squareTo(b);
  1065. this.reduce(b)
  1066. }
  1067. Classic.prototype.convert = cConvert;
  1068. Classic.prototype.revert = cRevert;
  1069. Classic.prototype.reduce = cReduce;
  1070. Classic.prototype.mulTo = cMulTo;
  1071. Classic.prototype.sqrTo = cSqrTo;
  1072.  
  1073. function bnpInvDigit() {
  1074. if (1 > this.t)
  1075. return 0;
  1076. var a = this[0];
  1077. if (0 == (a & 1))
  1078. return 0;
  1079. var b = a & 3,
  1080. b = b * (2 - (a & 15) * b) & 15,
  1081. b = b * (2 - (a & 255) * b) & 255,
  1082. b = b * (2 - ((a & 65535) * b & 65535)) & 65535,
  1083. b = b * (2 - a * b % this.DV) % this.DV;
  1084. return 0 < b ? this.DV - b : -b
  1085. }
  1086.  
  1087. function Montgomery(a) {
  1088. this.m = a;
  1089. this.mp = a.invDigit();
  1090. this.mpl = this.mp & 32767;
  1091. this.mph = this.mp >> 15;
  1092. this.um = (1 << a.DB - 15) - 1;
  1093. this.mt2 = 2 * a.t
  1094. }
  1095.  
  1096. function montConvert(a) {
  1097. var b = nbi();
  1098. a.abs().dlShiftTo(this.m.t, b);
  1099. b.divRemTo(this.m, null, b);
  1100. 0 > a.s && 0 < b.compareTo(BigInteger.ZERO) && this.m.subTo(b, b);
  1101. return b
  1102. }
  1103.  
  1104. function montRevert(a) {
  1105. var b = nbi();
  1106. a.copyTo(b);
  1107. this.reduce(b);
  1108. return b
  1109. }
  1110.  
  1111. function montReduce(a) {
  1112. for (; a.t <= this.mt2;)
  1113. a[a.t++] = 0;
  1114. for (var b = 0; b < this.m.t; ++b) {
  1115. var c = a[b] & 32767,
  1116. d = c * this.mpl + ((c * this.mph + (a[b] >> 15) * this.mpl & this.um) << 15) & a.DM,
  1117. c = b + this.m.t;
  1118. for (a[c] += this.m.am(0, d, a, b, 0, this.m.t); a[c] >= a.DV;)
  1119. a[c] -= a.DV,
  1120. a[++c]++
  1121. }
  1122. a.clamp();
  1123. a.drShiftTo(this.m.t, a);
  1124. 0 <= a.compareTo(this.m) && a.subTo(this.m, a)
  1125. }
  1126.  
  1127. function montSqrTo(a, b) {
  1128. a.squareTo(b);
  1129. this.reduce(b)
  1130. }
  1131.  
  1132. function montMulTo(a, b, c) {
  1133. a.multiplyTo(b, c);
  1134. this.reduce(c)
  1135. }
  1136. Montgomery.prototype.convert = montConvert;
  1137. Montgomery.prototype.revert = montRevert;
  1138. Montgomery.prototype.reduce = montReduce;
  1139. Montgomery.prototype.mulTo = montMulTo;
  1140. Montgomery.prototype.sqrTo = montSqrTo;
  1141.  
  1142. function bnpIsEven() {
  1143. return 0 == (0 < this.t ? this[0] & 1 : this.s)
  1144. }
  1145.  
  1146. function bnpExp(a, b) {
  1147. if (4294967295 < a || 1 > a)
  1148. return BigInteger.ONE;
  1149. var c = nbi(),
  1150. d = nbi(),
  1151. e = b.convert(this),
  1152. f = nbits(a) - 1;
  1153. for (e.copyTo(c); 0 <= --f;)
  1154. if (b.sqrTo(c, d),
  1155. 0 < (a & 1 << f))
  1156. b.mulTo(d, e, c);
  1157. else
  1158. var g = c,
  1159. c = d,
  1160. d = g;
  1161. return b.revert(c)
  1162. }
  1163.  
  1164. function bnModPowInt(a, b) {
  1165. var c;
  1166. c = 256 > a || b.isEven() ? new Classic(b) : new Montgomery(b);
  1167. return this.exp(a, c)
  1168. }
  1169. BigInteger.prototype.copyTo = bnpCopyTo;
  1170. BigInteger.prototype.fromInt = bnpFromInt;
  1171. BigInteger.prototype.fromString = bnpFromString;
  1172. BigInteger.prototype.clamp = bnpClamp;
  1173. BigInteger.prototype.dlShiftTo = bnpDLShiftTo;
  1174. BigInteger.prototype.drShiftTo = bnpDRShiftTo;
  1175. BigInteger.prototype.lShiftTo = bnpLShiftTo;
  1176. BigInteger.prototype.rShiftTo = bnpRShiftTo;
  1177. BigInteger.prototype.subTo = bnpSubTo;
  1178. BigInteger.prototype.multiplyTo = bnpMultiplyTo;
  1179. BigInteger.prototype.squareTo = bnpSquareTo;
  1180. BigInteger.prototype.divRemTo = bnpDivRemTo;
  1181. BigInteger.prototype.invDigit = bnpInvDigit;
  1182. BigInteger.prototype.isEven = bnpIsEven;
  1183. BigInteger.prototype.exp = bnpExp;
  1184. BigInteger.prototype.toString = bnToString;
  1185. BigInteger.prototype.negate = bnNegate;
  1186. BigInteger.prototype.abs = bnAbs;
  1187. BigInteger.prototype.compareTo = bnCompareTo;
  1188. BigInteger.prototype.bitLength = bnBitLength;
  1189. BigInteger.prototype.mod = bnMod;
  1190. BigInteger.prototype.modPowInt = bnModPowInt;
  1191. BigInteger.ZERO = nbv(0);
  1192. BigInteger.ONE = nbv(1);
  1193.  
  1194. function bnClone() {
  1195. var a = nbi();
  1196. this.copyTo(a);
  1197. return a
  1198. }
  1199.  
  1200. function bnIntValue() {
  1201. if (0 > this.s) {
  1202. if (1 == this.t)
  1203. return this[0] - this.DV;
  1204. if (0 == this.t)
  1205. return -1
  1206. } else {
  1207. if (1 == this.t)
  1208. return this[0];
  1209. if (0 == this.t)
  1210. return 0
  1211. }
  1212. return (this[1] & (1 << 32 - this.DB) - 1) << this.DB | this[0]
  1213. }
  1214.  
  1215. function bnByteValue() {
  1216. return 0 == this.t ? this.s : this[0] << 24 >> 24
  1217. }
  1218.  
  1219. function bnShortValue() {
  1220. return 0 == this.t ? this.s : this[0] << 16 >> 16
  1221. }
  1222.  
  1223. function bnpChunkSize(a) {
  1224. return Math.floor(Math.LN2 * this.DB / Math.log(a))
  1225. }
  1226.  
  1227. function bnSigNum() {
  1228. return 0 > this.s ? -1 : 0 >= this.t || 1 == this.t && 0 >= this[0] ? 0 : 1
  1229. }
  1230.  
  1231. function bnpToRadix(a) {
  1232. null == a && (a = 10);
  1233. if (0 == this.signum() || 2 > a || 36 < a)
  1234. return "0";
  1235. var b = this.chunkSize(a),
  1236. b = Math.pow(a, b),
  1237. c = nbv(b),
  1238. d = nbi(),
  1239. e = nbi(),
  1240. f = "";
  1241. for (this.divRemTo(c, d, e); 0 < d.signum();)
  1242. f = (b + e.intValue()).toString(a).substr(1) + f,
  1243. d.divRemTo(c, d, e);
  1244. return e.intValue().toString(a) + f
  1245. }
  1246.  
  1247. function bnpFromRadix(a, b) {
  1248. this.fromInt(0);
  1249. null == b && (b = 10);
  1250. for (var c = this.chunkSize(b), d = Math.pow(b, c), e = !1, f = 0, g = 0, h = 0; h < a.length; ++h) {
  1251. var k = intAt(a, h);
  1252. 0 > k ? "-" == a.charAt(h) && 0 == this.signum() && (e = !0) : (g = b * g + k,
  1253. ++f >= c && (this.dMultiply(d),
  1254. this.dAddOffset(g, 0),
  1255. g = f = 0))
  1256. }
  1257. 0 < f && (this.dMultiply(Math.pow(b, f)),
  1258. this.dAddOffset(g, 0));
  1259. e && BigInteger.ZERO.subTo(this, this)
  1260. }
  1261.  
  1262. function bnpFromNumber(a, b, c) {
  1263. if ("number" == typeof b)
  1264. if (2 > a)
  1265. this.fromInt(1);
  1266. else
  1267. for (this.fromNumber(a, c),
  1268. this.testBit(a - 1) || this.bitwiseTo(BigInteger.ONE.shiftLeft(a - 1), op_or, this),
  1269. this.isEven() && this.dAddOffset(1, 0); !this.isProbablePrime(b);)
  1270. this.dAddOffset(2, 0),
  1271. this.bitLength() > a && this.subTo(BigInteger.ONE.shiftLeft(a - 1), this);
  1272. else {
  1273. c = [];
  1274. var d = a & 7;
  1275. c.length = (a >> 3) + 1;
  1276. b.nextBytes(c);
  1277. c[0] = 0 < d ? c[0] & (1 << d) - 1 : 0;
  1278. this.fromString(c, 256)
  1279. }
  1280. }
  1281.  
  1282. function bnToByteArray() {
  1283. var a = this.t,
  1284. b = [];
  1285. b[0] = this.s;
  1286. var c = this.DB - a * this.DB % 8,
  1287. d, e = 0;
  1288. if (0 < a--)
  1289. for (c < this.DB && (d = this[a] >> c) != (this.s & this.DM) >> c && (b[e++] = d | this.s << this.DB - c); 0 <= a;)
  1290. if (8 > c ? (d = (this[a] & (1 << c) - 1) << 8 - c,
  1291. d |= this[--a] >> (c += this.DB - 8)) : (d = this[a] >> (c -= 8) & 255,
  1292. 0 >= c && (c += this.DB,
  1293. --a)),
  1294. 0 != (d & 128) && (d |= -256),
  1295. 0 == e && (this.s & 128) != (d & 128) && ++e,
  1296. 0 < e || d != this.s)
  1297. b[e++] = d;
  1298. return b
  1299. }
  1300.  
  1301. function bnEquals(a) {
  1302. return 0 == this.compareTo(a)
  1303. }
  1304.  
  1305. function bnMin(a) {
  1306. return 0 > this.compareTo(a) ? this : a
  1307. }
  1308.  
  1309. function bnMax(a) {
  1310. return 0 < this.compareTo(a) ? this : a
  1311. }
  1312.  
  1313. function bnpBitwiseTo(a, b, c) {
  1314. var d, e, f = Math.min(a.t, this.t);
  1315. for (d = 0; d < f; ++d)
  1316. c[d] = b(this[d], a[d]);
  1317. if (a.t < this.t) {
  1318. e = a.s & this.DM;
  1319. for (d = f; d < this.t; ++d)
  1320. c[d] = b(this[d], e);
  1321. c.t = this.t
  1322. } else {
  1323. e = this.s & this.DM;
  1324. for (d = f; d < a.t; ++d)
  1325. c[d] = b(e, a[d]);
  1326. c.t = a.t
  1327. }
  1328. c.s = b(this.s, a.s);
  1329. c.clamp()
  1330. }
  1331.  
  1332. function op_and(a, b) {
  1333. return a & b
  1334. }
  1335.  
  1336. function bnAnd(a) {
  1337. var b = nbi();
  1338. this.bitwiseTo(a, op_and, b);
  1339. return b
  1340. }
  1341.  
  1342. function op_or(a, b) {
  1343. return a | b
  1344. }
  1345.  
  1346. function bnOr(a) {
  1347. var b = nbi();
  1348. this.bitwiseTo(a, op_or, b);
  1349. return b
  1350. }
  1351.  
  1352. function op_xor(a, b) {
  1353. return a ^ b
  1354. }
  1355.  
  1356. function bnXor(a) {
  1357. var b = nbi();
  1358. this.bitwiseTo(a, op_xor, b);
  1359. return b
  1360. }
  1361.  
  1362. function op_andnot(a, b) {
  1363. return a & ~b
  1364. }
  1365.  
  1366. function bnAndNot(a) {
  1367. var b = nbi();
  1368. this.bitwiseTo(a, op_andnot, b);
  1369. return b
  1370. }
  1371.  
  1372. function bnNot() {
  1373. for (var a = nbi(), b = 0; b < this.t; ++b)
  1374. a[b] = this.DM & ~this[b];
  1375. a.t = this.t;
  1376. a.s = ~this.s;
  1377. return a
  1378. }
  1379.  
  1380. function bnShiftLeft(a) {
  1381. var b = nbi();
  1382. 0 > a ? this.rShiftTo(-a, b) : this.lShiftTo(a, b);
  1383. return b
  1384. }
  1385.  
  1386. function bnShiftRight(a) {
  1387. var b = nbi();
  1388. 0 > a ? this.lShiftTo(-a, b) : this.rShiftTo(a, b);
  1389. return b
  1390. }
  1391.  
  1392. function lbit(a) {
  1393. if (0 == a)
  1394. return -1;
  1395. var b = 0;
  1396. 0 == (a & 65535) && (a >>= 16,
  1397. b += 16);
  1398. 0 == (a & 255) && (a >>= 8,
  1399. b += 8);
  1400. 0 == (a & 15) && (a >>= 4,
  1401. b += 4);
  1402. 0 == (a & 3) && (a >>= 2,
  1403. b += 2);
  1404. 0 == (a & 1) && ++b;
  1405. return b
  1406. }
  1407.  
  1408. function bnGetLowestSetBit() {
  1409. for (var a = 0; a < this.t; ++a)
  1410. if (0 != this[a])
  1411. return a * this.DB + lbit(this[a]);
  1412. return 0 > this.s ? this.t * this.DB : -1
  1413. }
  1414.  
  1415. function cbit(a) {
  1416. for (var b = 0; 0 != a;)
  1417. a &= a - 1,
  1418. ++b;
  1419. return b
  1420. }
  1421.  
  1422. function bnBitCount() {
  1423. for (var a = 0, b = this.s & this.DM, c = 0; c < this.t; ++c)
  1424. a += cbit(this[c] ^ b);
  1425. return a
  1426. }
  1427.  
  1428. function bnTestBit(a) {
  1429. var b = Math.floor(a / this.DB);
  1430. return b >= this.t ? 0 != this.s : 0 != (this[b] & 1 << a % this.DB)
  1431. }
  1432.  
  1433. function bnpChangeBit(a, b) {
  1434. var c = BigInteger.ONE.shiftLeft(a);
  1435. this.bitwiseTo(c, b, c);
  1436. return c
  1437. }
  1438.  
  1439. function bnSetBit(a) {
  1440. return this.changeBit(a, op_or)
  1441. }
  1442.  
  1443. function bnClearBit(a) {
  1444. return this.changeBit(a, op_andnot)
  1445. }
  1446.  
  1447. function bnFlipBit(a) {
  1448. return this.changeBit(a, op_xor)
  1449. }
  1450.  
  1451. function bnpAddTo(a, b) {
  1452. for (var c = 0, d = 0, e = Math.min(a.t, this.t); c < e;)
  1453. d += this[c] + a[c],
  1454. b[c++] = d & this.DM,
  1455. d >>= this.DB;
  1456. if (a.t < this.t) {
  1457. for (d += a.s; c < this.t;)
  1458. d += this[c],
  1459. b[c++] = d & this.DM,
  1460. d >>= this.DB;
  1461. d += this.s
  1462. } else {
  1463. for (d += this.s; c < a.t;)
  1464. d += a[c],
  1465. b[c++] = d & this.DM,
  1466. d >>= this.DB;
  1467. d += a.s
  1468. }
  1469. b.s = 0 > d ? -1 : 0;
  1470. 0 < d ? b[c++] = d : -1 > d && (b[c++] = this.DV + d);
  1471. b.t = c;
  1472. b.clamp()
  1473. }
  1474.  
  1475. function bnAdd(a) {
  1476. var b = nbi();
  1477. this.addTo(a, b);
  1478. return b
  1479. }
  1480.  
  1481. function bnSubtract(a) {
  1482. var b = nbi();
  1483. this.subTo(a, b);
  1484. return b
  1485. }
  1486.  
  1487. function bnMultiply(a) {
  1488. var b = nbi();
  1489. this.multiplyTo(a, b);
  1490. return b
  1491. }
  1492.  
  1493. function bnSquare() {
  1494. var a = nbi();
  1495. this.squareTo(a);
  1496. return a
  1497. }
  1498.  
  1499. function bnDivide(a) {
  1500. var b = nbi();
  1501. this.divRemTo(a, b, null);
  1502. return b
  1503. }
  1504.  
  1505. function bnRemainder(a) {
  1506. var b = nbi();
  1507. this.divRemTo(a, null, b);
  1508. return b
  1509. }
  1510.  
  1511. function bnDivideAndRemainder(a) {
  1512. var b = nbi(),
  1513. c = nbi();
  1514. this.divRemTo(a, b, c);
  1515. return [b, c]
  1516. }
  1517.  
  1518. function bnpDMultiply(a) {
  1519. this[this.t] = this.am(0, a - 1, this, 0, 0, this.t);
  1520. ++this.t;
  1521. this.clamp()
  1522. }
  1523.  
  1524. function bnpDAddOffset(a, b) {
  1525. if (0 != a) {
  1526. for (; this.t <= b;)
  1527. this[this.t++] = 0;
  1528. for (this[b] += a; this[b] >= this.DV;)
  1529. this[b] -= this.DV,
  1530. ++b >= this.t && (this[this.t++] = 0),
  1531. ++this[b]
  1532. }
  1533. }
  1534.  
  1535. function NullExp() {}
  1536.  
  1537. function nNop(a) {
  1538. return a
  1539. }
  1540.  
  1541. function nMulTo(a, b, c) {
  1542. a.multiplyTo(b, c)
  1543. }
  1544.  
  1545. function nSqrTo(a, b) {
  1546. a.squareTo(b)
  1547. }
  1548. NullExp.prototype.convert = nNop;
  1549. NullExp.prototype.revert = nNop;
  1550. NullExp.prototype.mulTo = nMulTo;
  1551. NullExp.prototype.sqrTo = nSqrTo;
  1552.  
  1553. function bnPow(a) {
  1554. return this.exp(a, new NullExp)
  1555. }
  1556.  
  1557. function bnpMultiplyLowerTo(a, b, c) {
  1558. var d = Math.min(this.t + a.t, b);
  1559. c.s = 0;
  1560. for (c.t = d; 0 < d;)
  1561. c[--d] = 0;
  1562. var e;
  1563. for (e = c.t - this.t; d < e; ++d)
  1564. c[d + this.t] = this.am(0, a[d], c, d, 0, this.t);
  1565. for (e = Math.min(a.t, b); d < e; ++d)
  1566. this.am(0, a[d], c, d, 0, b - d);
  1567. c.clamp()
  1568. }
  1569.  
  1570. function bnpMultiplyUpperTo(a, b, c) {
  1571. --b;
  1572. var d = c.t = this.t + a.t - b;
  1573. for (c.s = 0; 0 <= --d;)
  1574. c[d] = 0;
  1575. for (d = Math.max(b - this.t, 0); d < a.t; ++d)
  1576. c[this.t + d - b] = this.am(b - d, a[d], c, 0, 0, this.t + d - b);
  1577. c.clamp();
  1578. c.drShiftTo(1, c)
  1579. }
  1580.  
  1581. function Barrett(a) {
  1582. this.r2 = nbi();
  1583. this.q3 = nbi();
  1584. BigInteger.ONE.dlShiftTo(2 * a.t, this.r2);
  1585. this.mu = this.r2.divide(a);
  1586. this.m = a
  1587. }
  1588.  
  1589. function barrettConvert(a) {
  1590. if (0 > a.s || a.t > 2 * this.m.t)
  1591. return a.mod(this.m);
  1592. if (0 > a.compareTo(this.m))
  1593. return a;
  1594. var b = nbi();
  1595. a.copyTo(b);
  1596. this.reduce(b);
  1597. return b
  1598. }
  1599.  
  1600. function barrettRevert(a) {
  1601. return a
  1602. }
  1603.  
  1604. function barrettReduce(a) {
  1605. a.drShiftTo(this.m.t - 1, this.r2);
  1606. a.t > this.m.t + 1 && (a.t = this.m.t + 1,
  1607. a.clamp());
  1608. this.mu.multiplyUpperTo(this.r2, this.m.t + 1, this.q3);
  1609. for (this.m.multiplyLowerTo(this.q3, this.m.t + 1, this.r2); 0 > a.compareTo(this.r2);)
  1610. a.dAddOffset(1, this.m.t + 1);
  1611. for (a.subTo(this.r2, a); 0 <= a.compareTo(this.m);)
  1612. a.subTo(this.m, a)
  1613. }
  1614.  
  1615. function barrettSqrTo(a, b) {
  1616. a.squareTo(b);
  1617. this.reduce(b)
  1618. }
  1619.  
  1620. function barrettMulTo(a, b, c) {
  1621. a.multiplyTo(b, c);
  1622. this.reduce(c)
  1623. }
  1624. Barrett.prototype.convert = barrettConvert;
  1625. Barrett.prototype.revert = barrettRevert;
  1626. Barrett.prototype.reduce = barrettReduce;
  1627. Barrett.prototype.mulTo = barrettMulTo;
  1628. Barrett.prototype.sqrTo = barrettSqrTo;
  1629.  
  1630. function bnModPow(a, b) {
  1631. var c = a.bitLength(),
  1632. d, e = nbv(1),
  1633. f;
  1634. if (0 >= c)
  1635. return e;
  1636. d = 18 > c ? 1 : 48 > c ? 3 : 144 > c ? 4 : 768 > c ? 5 : 6;
  1637. f = 8 > c ? new Classic(b) : b.isEven() ? new Barrett(b) : new Montgomery(b);
  1638. var g = [],
  1639. h = 3,
  1640. k = d - 1,
  1641. l = (1 << d) - 1;
  1642. g[1] = f.convert(this);
  1643. if (1 < d)
  1644. for (c = nbi(),
  1645. f.sqrTo(g[1], c); h <= l;)
  1646. g[h] = nbi(),
  1647. f.mulTo(c, g[h - 2], g[h]),
  1648. h += 2;
  1649. for (var p = a.t - 1, n, q = !0, m = nbi(), c = nbits(a[p]) - 1; 0 <= p;) {
  1650. c >= k ? n = a[p] >> c - k & l : (n = (a[p] & (1 << c + 1) - 1) << k - c,
  1651. 0 < p && (n |= a[p - 1] >> this.DB + c - k));
  1652. for (h = d; 0 == (n & 1);)
  1653. n >>= 1,
  1654. --h;
  1655. 0 > (c -= h) && (c += this.DB,
  1656. --p);
  1657. if (q)
  1658. g[n].copyTo(e),
  1659. q = !1;
  1660. else {
  1661. for (; 1 < h;)
  1662. f.sqrTo(e, m),
  1663. f.sqrTo(m, e),
  1664. h -= 2;
  1665. 0 < h ? f.sqrTo(e, m) : (h = e,
  1666. e = m,
  1667. m = h);
  1668. f.mulTo(m, g[n], e)
  1669. }
  1670. for (; 0 <= p && 0 == (a[p] & 1 << c);)
  1671. f.sqrTo(e, m),
  1672. h = e,
  1673. e = m,
  1674. m = h,
  1675. 0 > --c && (c = this.DB - 1,
  1676. --p)
  1677. }
  1678. return f.revert(e)
  1679. }
  1680.  
  1681. function bnGCD(a) {
  1682. var b = 0 > this.s ? this.negate() : this.clone();
  1683. a = 0 > a.s ? a.negate() : a.clone();
  1684. if (0 > b.compareTo(a)) {
  1685. var c = b,
  1686. b = a;
  1687. a = c
  1688. }
  1689. var c = b.getLowestSetBit(),
  1690. d = a.getLowestSetBit();
  1691. if (0 > d)
  1692. return b;
  1693. c < d && (d = c);
  1694. 0 < d && (b.rShiftTo(d, b),
  1695. a.rShiftTo(d, a));
  1696. for (; 0 < b.signum();)
  1697. 0 < (c = b.getLowestSetBit()) && b.rShiftTo(c, b),
  1698. 0 < (c = a.getLowestSetBit()) && a.rShiftTo(c, a),
  1699. 0 <= b.compareTo(a) ? (b.subTo(a, b),
  1700. b.rShiftTo(1, b)) : (a.subTo(b, a),
  1701. a.rShiftTo(1, a));
  1702. 0 < d && a.lShiftTo(d, a);
  1703. return a
  1704. }
  1705.  
  1706. function bnpModInt(a) {
  1707. if (0 >= a)
  1708. return 0;
  1709. var b = this.DV % a,
  1710. c = 0 > this.s ? a - 1 : 0;
  1711. if (0 < this.t)
  1712. if (0 == b)
  1713. c = this[0] % a;
  1714. else
  1715. for (var d = this.t - 1; 0 <= d; --d)
  1716. c = (b * c + this[d]) % a;
  1717. return c
  1718. }
  1719.  
  1720. function bnModInverse(a) {
  1721. var b = a.isEven();
  1722. if (this.isEven() && b || 0 == a.signum())
  1723. return BigInteger.ZERO;
  1724. for (var c = a.clone(), d = this.clone(), e = nbv(1), f = nbv(0), g = nbv(0), h = nbv(1); 0 != c.signum();) {
  1725. for (; c.isEven();)
  1726. c.rShiftTo(1, c),
  1727. b ? (e.isEven() && f.isEven() || (e.addTo(this, e),
  1728. f.subTo(a, f)),
  1729. e.rShiftTo(1, e)) : f.isEven() || f.subTo(a, f),
  1730. f.rShiftTo(1, f);
  1731. for (; d.isEven();)
  1732. d.rShiftTo(1, d),
  1733. b ? (g.isEven() && h.isEven() || (g.addTo(this, g),
  1734. h.subTo(a, h)),
  1735. g.rShiftTo(1, g)) : h.isEven() || h.subTo(a, h),
  1736. h.rShiftTo(1, h);
  1737. 0 <= c.compareTo(d) ? (c.subTo(d, c),
  1738. b && e.subTo(g, e),
  1739. f.subTo(h, f)) : (d.subTo(c, d),
  1740. b && g.subTo(e, g),
  1741. h.subTo(f, h))
  1742. }
  1743. if (0 != d.compareTo(BigInteger.ONE))
  1744. return BigInteger.ZERO;
  1745. if (0 <= h.compareTo(a))
  1746. return h.subtract(a);
  1747. if (0 > h.signum())
  1748. h.addTo(a, h);
  1749. else
  1750. return h;
  1751. return 0 > h.signum() ? h.add(a) : h
  1752. }
  1753. var lowprimes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997],
  1754. lplim = 67108864 / lowprimes[lowprimes.length - 1];
  1755.  
  1756. function bnIsProbablePrime(a) {
  1757. var b, c = this.abs();
  1758. if (1 == c.t && c[0] <= lowprimes[lowprimes.length - 1]) {
  1759. for (b = 0; b < lowprimes.length; ++b)
  1760. if (c[0] == lowprimes[b])
  1761. return !0;
  1762. return !1
  1763. }
  1764. if (c.isEven())
  1765. return !1;
  1766. for (b = 1; b < lowprimes.length;) {
  1767. for (var d = lowprimes[b], e = b + 1; e < lowprimes.length && d < lplim;)
  1768. d *= lowprimes[e++];
  1769. for (d = c.modInt(d); b < e;)
  1770. if (0 == d % lowprimes[b++])
  1771. return !1
  1772. }
  1773. return c.millerRabin(a)
  1774. }
  1775.  
  1776. function bnpMillerRabin(a) {
  1777. var b = this.subtract(BigInteger.ONE),
  1778. c = b.getLowestSetBit();
  1779. if (0 >= c)
  1780. return !1;
  1781. var d = b.shiftRight(c);
  1782. a = a + 1 >> 1;
  1783. a > lowprimes.length && (a = lowprimes.length);
  1784. for (var e = nbi(), f = 0; f < a; ++f) {
  1785. e.fromInt(lowprimes[Math.floor(Math.random() * lowprimes.length)]);
  1786. var g = e.modPow(d, this);
  1787. if (0 != g.compareTo(BigInteger.ONE) && 0 != g.compareTo(b)) {
  1788. for (var h = 1; h++ < c && 0 != g.compareTo(b);)
  1789. if (g = g.modPowInt(2, this),
  1790. 0 == g.compareTo(BigInteger.ONE))
  1791. return !1;
  1792. if (0 != g.compareTo(b))
  1793. return !1
  1794. }
  1795. }
  1796. return !0
  1797. }
  1798. BigInteger.prototype.chunkSize = bnpChunkSize;
  1799. BigInteger.prototype.toRadix = bnpToRadix;
  1800. BigInteger.prototype.fromRadix = bnpFromRadix;
  1801. BigInteger.prototype.fromNumber = bnpFromNumber;
  1802. BigInteger.prototype.bitwiseTo = bnpBitwiseTo;
  1803. BigInteger.prototype.changeBit = bnpChangeBit;
  1804. BigInteger.prototype.addTo = bnpAddTo;
  1805. BigInteger.prototype.dMultiply = bnpDMultiply;
  1806. BigInteger.prototype.dAddOffset = bnpDAddOffset;
  1807. BigInteger.prototype.multiplyLowerTo = bnpMultiplyLowerTo;
  1808. BigInteger.prototype.multiplyUpperTo = bnpMultiplyUpperTo;
  1809. BigInteger.prototype.modInt = bnpModInt;
  1810. BigInteger.prototype.millerRabin = bnpMillerRabin;
  1811. BigInteger.prototype.clone = bnClone;
  1812. BigInteger.prototype.intValue = bnIntValue;
  1813. BigInteger.prototype.byteValue = bnByteValue;
  1814. BigInteger.prototype.shortValue = bnShortValue;
  1815. BigInteger.prototype.signum = bnSigNum;
  1816. BigInteger.prototype.toByteArray = bnToByteArray;
  1817. BigInteger.prototype.equals = bnEquals;
  1818. BigInteger.prototype.min = bnMin;
  1819. BigInteger.prototype.max = bnMax;
  1820. BigInteger.prototype.and = bnAnd;
  1821. BigInteger.prototype.or = bnOr;
  1822. BigInteger.prototype.xor = bnXor;
  1823. BigInteger.prototype.andNot = bnAndNot;
  1824. BigInteger.prototype.not = bnNot;
  1825. BigInteger.prototype.shiftLeft = bnShiftLeft;
  1826. BigInteger.prototype.shiftRight = bnShiftRight;
  1827. BigInteger.prototype.getLowestSetBit = bnGetLowestSetBit;
  1828. BigInteger.prototype.bitCount = bnBitCount;
  1829. BigInteger.prototype.testBit = bnTestBit;
  1830. BigInteger.prototype.setBit = bnSetBit;
  1831. BigInteger.prototype.clearBit = bnClearBit;
  1832. BigInteger.prototype.flipBit = bnFlipBit;
  1833. BigInteger.prototype.add = bnAdd;
  1834. BigInteger.prototype.subtract = bnSubtract;
  1835. BigInteger.prototype.multiply = bnMultiply;
  1836. BigInteger.prototype.divide = bnDivide;
  1837. BigInteger.prototype.remainder = bnRemainder;
  1838. BigInteger.prototype.divideAndRemainder = bnDivideAndRemainder;
  1839. BigInteger.prototype.modPow = bnModPow;
  1840. BigInteger.prototype.modInverse = bnModInverse;
  1841. BigInteger.prototype.pow = bnPow;
  1842. BigInteger.prototype.gcd = bnGCD;
  1843. BigInteger.prototype.isProbablePrime = bnIsProbablePrime;
  1844. BigInteger.prototype.square = bnSquare;
  1845.  
  1846. function Arcfour() {
  1847. this.j = this.i = 0;
  1848. this.S = []
  1849. }
  1850.  
  1851. function ARC4init(a) {
  1852. var b, c, d;
  1853. for (b = 0; 256 > b; ++b)
  1854. this.S[b] = b;
  1855. for (b = c = 0; 256 > b; ++b)
  1856. c = c + this.S[b] + a[b % a.length] & 255,
  1857. d = this.S[b],
  1858. this.S[b] = this.S[c],
  1859. this.S[c] = d;
  1860. this.j = this.i = 0
  1861. }
  1862.  
  1863. function ARC4next() {
  1864. var a;
  1865. this.i = this.i + 1 & 255;
  1866. this.j = this.j + this.S[this.i] & 255;
  1867. a = this.S[this.i];
  1868. this.S[this.i] = this.S[this.j];
  1869. this.S[this.j] = a;
  1870. return this.S[a + this.S[this.i] & 255]
  1871. }
  1872. Arcfour.prototype.init = ARC4init;
  1873. Arcfour.prototype.next = ARC4next;
  1874.  
  1875. function prng_newstate() {
  1876. return new Arcfour
  1877. }
  1878. var rng_psize = 256,
  1879. rng_state, rng_pool, rng_pptr;
  1880.  
  1881. function rng_seed_int(a) {
  1882. rng_pool[rng_pptr++] ^= a & 255;
  1883. rng_pool[rng_pptr++] ^= a >> 8 & 255;
  1884. rng_pool[rng_pptr++] ^= a >> 16 & 255;
  1885. rng_pool[rng_pptr++] ^= a >> 24 & 255;
  1886. rng_pptr >= rng_psize && (rng_pptr -= rng_psize)
  1887. }
  1888.  
  1889. function rng_seed_time() {
  1890. rng_seed_int((new Date).getTime())
  1891. }
  1892. if (null == rng_pool) {
  1893. rng_pool = [];
  1894. rng_pptr = 0;
  1895. var t;
  1896. if ("Netscape" == navigator.appName && "5" > navigator.appVersion && window.crypto) {
  1897. var z = window.crypto.random(32);
  1898. for (t = 0; t < z.length; ++t)
  1899. rng_pool[rng_pptr++] = z.charCodeAt(t) & 255
  1900. }
  1901. for (; rng_pptr < rng_psize;)
  1902. t = Math.floor(65536 * Math.random()),
  1903. rng_pool[rng_pptr++] = t >>> 8,
  1904. rng_pool[rng_pptr++] = t & 255;
  1905. rng_pptr = 0;
  1906. rng_seed_time()
  1907. }
  1908.  
  1909. function rng_get_byte() {
  1910. if (null == rng_state) {
  1911. rng_seed_time();
  1912. rng_state = prng_newstate();
  1913. rng_state.init(rng_pool);
  1914. for (rng_pptr = 0; rng_pptr < rng_pool.length; ++rng_pptr)
  1915. rng_pool[rng_pptr] = 0;
  1916. rng_pptr = 0
  1917. }
  1918. return rng_state.next()
  1919. }
  1920.  
  1921. function rng_get_bytes(a) {
  1922. var b;
  1923. for (b = 0; b < a.length; ++b)
  1924. a[b] = rng_get_byte()
  1925. }
  1926.  
  1927. function SecureRandom() {}
  1928. SecureRandom.prototype.nextBytes = rng_get_bytes;
  1929. var KJUR = {};
  1930. //"undefined" != typeof KJUR && KJUR || (KJUR = {});
  1931. "undefined" != typeof KJUR.crypto && KJUR.crypto || (KJUR.crypto = {});
  1932. KJUR.crypto.Util = new function () {
  1933. this.DIGESTINFOHEAD = {
  1934. sha1: "3021300906052b0e03021a05000414",
  1935. sha224: "302d300d06096086480165030402040500041c",
  1936. sha256: "3031300d060960864801650304020105000420",
  1937. sha384: "3041300d060960864801650304020205000430",
  1938. sha512: "3051300d060960864801650304020305000440",
  1939. md2: "3020300c06082a864886f70d020205000410",
  1940. md5: "3020300c06082a864886f70d020505000410",
  1941. ripemd160: "3021300906052b2403020105000414"
  1942. };
  1943. this.DEFAULTPROVIDER = {
  1944. md5: "cryptojs",
  1945. sha1: "cryptojs",
  1946. sha224: "cryptojs",
  1947. sha256: "cryptojs",
  1948. sha384: "cryptojs",
  1949. sha512: "cryptojs",
  1950. ripemd160: "cryptojs",
  1951. hmacmd5: "cryptojs",
  1952. hmacsha1: "cryptojs",
  1953. hmacsha224: "cryptojs",
  1954. hmacsha256: "cryptojs",
  1955. hmacsha384: "cryptojs",
  1956. hmacsha512: "cryptojs",
  1957. hmacripemd160: "cryptojs",
  1958. sm3: "cryptojs",
  1959. MD5withRSA: "cryptojs/jsrsa",
  1960. SHA1withRSA: "cryptojs/jsrsa",
  1961. SHA224withRSA: "cryptojs/jsrsa",
  1962. SHA256withRSA: "cryptojs/jsrsa",
  1963. SHA384withRSA: "cryptojs/jsrsa",
  1964. SHA512withRSA: "cryptojs/jsrsa",
  1965. RIPEMD160withRSA: "cryptojs/jsrsa",
  1966. MD5withECDSA: "cryptojs/jsrsa",
  1967. SHA1withECDSA: "cryptojs/jsrsa",
  1968. SHA224withECDSA: "cryptojs/jsrsa",
  1969. SHA256withECDSA: "cryptojs/jsrsa",
  1970. SHA384withECDSA: "cryptojs/jsrsa",
  1971. SHA512withECDSA: "cryptojs/jsrsa",
  1972. RIPEMD160withECDSA: "cryptojs/jsrsa",
  1973. SHA1withDSA: "cryptojs/jsrsa",
  1974. SHA224withDSA: "cryptojs/jsrsa",
  1975. SHA256withDSA: "cryptojs/jsrsa",
  1976. MD5withRSAandMGF1: "cryptojs/jsrsa",
  1977. SHA1withRSAandMGF1: "cryptojs/jsrsa",
  1978. SHA224withRSAandMGF1: "cryptojs/jsrsa",
  1979. SHA256withRSAandMGF1: "cryptojs/jsrsa",
  1980. SHA384withRSAandMGF1: "cryptojs/jsrsa",
  1981. SHA512withRSAandMGF1: "cryptojs/jsrsa",
  1982. RIPEMD160withRSAandMGF1: "cryptojs/jsrsa"
  1983. };
  1984. this.CRYPTOJSMESSAGEDIGESTNAME = {
  1985. md5: "CryptoJS.algo.MD5",
  1986. sha1: "CryptoJS.algo.SHA1",
  1987. sha224: "CryptoJS.algo.SHA224",
  1988. sha256: "CryptoJS.algo.SHA256",
  1989. sha384: "CryptoJS.algo.SHA384",
  1990. sha512: "CryptoJS.algo.SHA512",
  1991. ripemd160: "CryptoJS.algo.RIPEMD160",
  1992. sm3: "CryptoJS.algo.SM3"
  1993. };
  1994. this.getDigestInfoHex = function (a, b) {
  1995. if ("undefined" == typeof this.DIGESTINFOHEAD[b])
  1996. throw "alg not supported in Util.DIGESTINFOHEAD: " + b;
  1997. return this.DIGESTINFOHEAD[b] + a
  1998. };
  1999. this.getPaddedDigestInfoHex = function (a, b, c) {
  2000. var d = this.getDigestInfoHex(a, b);
  2001. a = c / 4;
  2002. if (d.length + 22 > a)
  2003. throw "key is too short for SigAlg: keylen=" + c + "," + b;
  2004. b = "00" + d;
  2005. c = "";
  2006. a = a - 4 - b.length;
  2007. for (d = 0; d < a; d += 2)
  2008. c += "ff";
  2009. return "0001" + c + b
  2010. };
  2011. this.hashString = function (a, b) {
  2012. return (new KJUR.crypto.MessageDigest({
  2013. alg: b
  2014. })).digestString(a)
  2015. };
  2016. this.hashHex = function (a, b) {
  2017. return (new KJUR.crypto.MessageDigest({
  2018. alg: b
  2019. })).digestHex(a)
  2020. };
  2021. this.sha1 = function (a) {
  2022. return (new KJUR.crypto.MessageDigest({
  2023. alg: "sha1",
  2024. prov: "cryptojs"
  2025. })).digestString(a)
  2026. };
  2027. this.sha256 = function (a) {
  2028. return (new KJUR.crypto.MessageDigest({
  2029. alg: "sha256",
  2030. prov: "cryptojs"
  2031. })).digestString(a)
  2032. };
  2033. this.sha256Hex = function (a) {
  2034. return (new KJUR.crypto.MessageDigest({
  2035. alg: "sha256",
  2036. prov: "cryptojs"
  2037. })).digestHex(a)
  2038. };
  2039. this.sha512 = function (a) {
  2040. return (new KJUR.crypto.MessageDigest({
  2041. alg: "sha512",
  2042. prov: "cryptojs"
  2043. })).digestString(a)
  2044. };
  2045. this.sha512Hex = function (a) {
  2046. return (new KJUR.crypto.MessageDigest({
  2047. alg: "sha512",
  2048. prov: "cryptojs"
  2049. })).digestHex(a)
  2050. };
  2051. this.md5 = function (a) {
  2052. return (new KJUR.crypto.MessageDigest({
  2053. alg: "md5",
  2054. prov: "cryptojs"
  2055. })).digestString(a)
  2056. };
  2057. this.ripemd160 = function (a) {
  2058. return (new KJUR.crypto.MessageDigest({
  2059. alg: "ripemd160",
  2060. prov: "cryptojs"
  2061. })).digestString(a)
  2062. };
  2063. this.getCryptoJSMDByName = function (a) {}
  2064. };
  2065. KJUR.crypto.MessageDigest = function (a) {
  2066. this.setAlgAndProvider = function (a, c) {
  2067. null != a && void 0 === c && (c = KJUR.crypto.Util.DEFAULTPROVIDER[a]);
  2068. if (-1 != ":md5:sha1:sha224:sha256:sha384:sha512:ripemd160:sm3:".indexOf(a) && "cryptojs" == c) {
  2069. try {
  2070. this.md = eval(KJUR.crypto.Util.CRYPTOJSMESSAGEDIGESTNAME[a]).create()
  2071. } catch (d) {
  2072. throw "setAlgAndProvider hash alg set fail alg=" + a + "/" + d;
  2073. }
  2074. this.updateString = function (a) {
  2075. this.md.update(a)
  2076. };
  2077. this.updateHex = function (a) {
  2078. a = CryptoJS.enc.Hex.parse(a);
  2079. this.md.update(a)
  2080. };
  2081. this.digest = function () {
  2082. return this.md.finalize().toString(CryptoJS.enc.Hex)
  2083. };
  2084. this.digestString = function (a) {
  2085. this.updateString(a);
  2086. return this.digest()
  2087. };
  2088. this.digestHex = function (a) {
  2089. this.updateHex(a);
  2090. return this.digest()
  2091. }
  2092. }
  2093. if (-1 != ":sha256:".indexOf(a) && "sjcl" == c) {
  2094. try {
  2095. this.md = new sjcl.hash.sha256
  2096. } catch (d) {
  2097. throw "setAlgAndProvider hash alg set fail alg=" + a + "/" + d;
  2098. }
  2099. this.updateString = function (a) {
  2100. this.md.update(a)
  2101. };
  2102. this.updateHex = function (a) {
  2103. a = sjcl.codec.hex.toBits(a);
  2104. this.md.update(a)
  2105. };
  2106. this.digest = function () {
  2107. var a = this.md.finalize();
  2108. return sjcl.codec.hex.fromBits(a)
  2109. };
  2110. this.digestString = function (a) {
  2111. this.updateString(a);
  2112. return this.digest()
  2113. };
  2114. this.digestHex = function (a) {
  2115. this.updateHex(a);
  2116. return this.digest()
  2117. }
  2118. }
  2119. };
  2120. this.updateString = function (a) {
  2121. throw "updateString(str) not supported for this alg/prov: " + this.algName + "/" + this.provName;
  2122. };
  2123. this.updateHex = function (a) {
  2124. throw "updateHex(hex) not supported for this alg/prov: " + this.algName + "/" + this.provName;
  2125. };
  2126. this.digest = function () {
  2127. throw "digest() not supported for this alg/prov: " + this.algName + "/" + this.provName;
  2128. };
  2129. this.digestString = function (a) {
  2130. throw "digestString(str) not supported for this alg/prov: " + this.algName + "/" + this.provName;
  2131. };
  2132. this.digestHex = function (a) {
  2133. throw "digestHex(hex) not supported for this alg/prov: " + this.algName + "/" + this.provName;
  2134. };
  2135. void 0 !== a && void 0 !== a.alg && (this.algName = a.alg,
  2136. void 0 === a.prov && (this.provName = KJUR.crypto.Util.DEFAULTPROVIDER[this.algName]),
  2137. this.setAlgAndProvider(this.algName, this.provName))
  2138. };
  2139. KJUR.crypto.Mac = function (a) {
  2140. this.setAlgAndProvider = function (a, c) {
  2141. null == a && (a = "hmacsha1");
  2142. a = a.toLowerCase();
  2143. if ("hmac" != a.substr(0, 4))
  2144. throw "setAlgAndProvider unsupported HMAC alg: " + a;
  2145. void 0 === c && (c = KJUR.crypto.Util.DEFAULTPROVIDER[a]);
  2146. this.algProv = a + "/" + c;
  2147. var d = a.substr(4);
  2148. if (-1 != ":md5:sha1:sha224:sha256:sha384:sha512:ripemd160:".indexOf(d) && "cryptojs" == c) {
  2149. try {
  2150. var e = eval(KJUR.crypto.Util.CRYPTOJSMESSAGEDIGESTNAME[d]);
  2151. this.mac = CryptoJS.algo.HMAC.create(e, this.pass)
  2152. } catch (f) {
  2153. throw "setAlgAndProvider hash alg set fail hashAlg=" + d + "/" + f;
  2154. }
  2155. this.updateString = function (a) {
  2156. this.mac.update(a)
  2157. };
  2158. this.updateHex = function (a) {
  2159. a = CryptoJS.enc.Hex.parse(a);
  2160. this.mac.update(a)
  2161. };
  2162. this.doFinal = function () {
  2163. return this.mac.finalize().toString(CryptoJS.enc.Hex)
  2164. };
  2165. this.doFinalString = function (a) {
  2166. this.updateString(a);
  2167. return this.doFinal()
  2168. };
  2169. this.doFinalHex = function (a) {
  2170. this.updateHex(a);
  2171. return this.doFinal()
  2172. }
  2173. }
  2174. };
  2175. this.updateString = function (a) {
  2176. throw "updateString(str) not supported for this alg/prov: " + this.algProv;
  2177. };
  2178. this.updateHex = function (a) {
  2179. throw "updateHex(hex) not supported for this alg/prov: " + this.algProv;
  2180. };
  2181. this.doFinal = function () {
  2182. throw "digest() not supported for this alg/prov: " + this.algProv;
  2183. };
  2184. this.doFinalString = function (a) {
  2185. throw "digestString(str) not supported for this alg/prov: " + this.algProv;
  2186. };
  2187. this.doFinalHex = function (a) {
  2188. throw "digestHex(hex) not supported for this alg/prov: " + this.algProv;
  2189. };
  2190. void 0 !== a && (void 0 !== a.pass && (this.pass = a.pass),
  2191. void 0 !== a.alg && (this.algName = a.alg,
  2192. void 0 === a.prov && (this.provName = KJUR.crypto.Util.DEFAULTPROVIDER[this.algName]),
  2193. this.setAlgAndProvider(this.algName, this.provName)))
  2194. };
  2195. KJUR.crypto.Signature = function (a) {
  2196. var b = null;
  2197. this._setAlgNames = function () {
  2198. this.algName.match(/^(.+)with(.+)$/) && (this.mdAlgName = RegExp.$1.toLowerCase(),
  2199. this.pubkeyAlgName = RegExp.$2.toLowerCase())
  2200. };
  2201. this._zeroPaddingOfSignature = function (a, b) {
  2202. for (var e = "", f = b / 4 - a.length, g = 0; g < f; g++)
  2203. e += "0";
  2204. return e + a
  2205. };
  2206. this.setAlgAndProvider = function (a, b) {
  2207. this._setAlgNames();
  2208. if ("cryptojs/jsrsa" != b)
  2209. throw "provider not supported: " + b;
  2210. if (-1 != ":md5:sha1:sha224:sha256:sha384:sha512:ripemd160:sm3:".indexOf(this.mdAlgName)) {
  2211. try {
  2212. this.md = new KJUR.crypto.MessageDigest({
  2213. alg: this.mdAlgName
  2214. })
  2215. } catch (e) {
  2216. throw "setAlgAndProvider hash alg set fail alg=" + this.mdAlgName + "/" + e;
  2217. }
  2218. this.init = function (a, c) {
  2219. var b = null;
  2220. try {
  2221. b = void 0 === c ? KEYUTIL.getKey(a) : KEYUTIL.getKey(a, c)
  2222. } catch (d) {
  2223. throw "init failed:" + d;
  2224. }
  2225. if (!0 === b.isPrivate)
  2226. this.prvKey = b,
  2227. this.state = "SIGN";
  2228. else if (!0 === b.isPublic)
  2229. this.pubKey = b,
  2230. this.state = "VERIFY";
  2231. else
  2232. throw "init failed.:" + b;
  2233. };
  2234. this.initSign = function (a) {
  2235. "string" == typeof a.ecprvhex && "string" == typeof a.eccurvename ? (this.ecprvhex = a.ecprvhex,
  2236. this.eccurvename = a.eccurvename) : this.prvKey = a;
  2237. this.state = "SIGN"
  2238. };
  2239. this.initVerifyByPublicKey = function (a) {
  2240. "string" == typeof a.ecpubhex && "string" == typeof a.eccurvename ? (this.ecpubhex = a.ecpubhex,
  2241. this.eccurvename = a.eccurvename) : a instanceof KJUR.crypto.ECDSA ? this.pubKey = a : a instanceof RSAKey && (this.pubKey = a);
  2242. this.state = "VERIFY"
  2243. };
  2244. this.initVerifyByCertificatePEM = function (a) {
  2245. var c = new X509;
  2246. c.readCertPEM(a);
  2247. this.pubKey = c.subjectPublicKeyRSA;
  2248. this.state = "VERIFY"
  2249. };
  2250. this.updateString = function (a) {
  2251. this.md.updateString(a)
  2252. };
  2253. this.updateHex = function (a) {
  2254. this.md.updateHex(a)
  2255. };
  2256. this.sign = function () {
  2257. "sm2" != this.eccurvename && (this.sHashHex = this.md.digest());
  2258. if ("undefined" != typeof this.ecprvhex && "undefined" != typeof this.eccurvename) {
  2259. if ("sm2" == this.eccurvename) {
  2260. var a = new KJUR.crypto.SM3withSM2({
  2261. curve: this.eccurvename
  2262. }),
  2263. c = a.ecparams.G,
  2264. b = c.multiply(new BigInteger(this.ecprvhex, 16)),
  2265. d = b.getX().toBigInteger().toRadix(16) + b.getY().toBigInteger().toRadix(16),
  2266. b = new SM3Digest,
  2267. c = (new SM3Digest).GetZ(c, d),
  2268. c = b.GetWords(b.GetHex(c).toString()),
  2269. d = CryptoJS.enc.Utf8.stringify(this.md.md._data),
  2270. d = CryptoJS.enc.Utf8.parse(d).toString(),
  2271. d = b.GetWords(d),
  2272. k = Array(b.GetDigestSize());
  2273. b.BlockUpdate(c, 0, c.length);
  2274. b.BlockUpdate(d, 0, d.length);
  2275. b.DoFinal(k, 0);
  2276. this.sHashHex = b.GetHex(k).toString()
  2277. } else
  2278. a = new KJUR.crypto.ECDSA({
  2279. curve: this.eccurvename
  2280. });
  2281. this.hSign = a.signHex(this.sHashHex, this.ecprvhex)
  2282. } else if ("rsaandmgf1" == this.pubkeyAlgName)
  2283. this.hSign = this.prvKey.signWithMessageHashPSS(this.sHashHex, this.mdAlgName, this.pssSaltLen);
  2284. else if ("rsa" == this.pubkeyAlgName)
  2285. this.hSign = this.prvKey.signWithMessageHash(this.sHashHex, this.mdAlgName);
  2286. else if (this.prvKey instanceof KJUR.crypto.ECDSA)
  2287. this.hSign = this.prvKey.signWithMessageHash(this.sHashHex);
  2288. else if (this.prvKey instanceof KJUR.crypto.DSA)
  2289. this.hSign = this.prvKey.signWithMessageHash(this.sHashHex);
  2290. else
  2291. throw "Signature: unsupported public key alg: " + this.pubkeyAlgName;
  2292. return this.hSign
  2293. };
  2294. this.signString = function (a) {
  2295. this.updateString(a);
  2296. this.sign()
  2297. };
  2298. this.signHex = function (a) {
  2299. this.updateHex(a);
  2300. this.sign()
  2301. };
  2302. this.verify = function (a) {
  2303. "sm2" != this.eccurvename && (this.sHashHex = this.md.digest());
  2304. if ("undefined" != typeof this.ecpubhex && "undefined" != typeof this.eccurvename) {
  2305. if ("sm2" == this.eccurvename) {
  2306. var c = new KJUR.crypto.SM3withSM2({
  2307. curve: this.eccurvename
  2308. }),
  2309. b = c.ecparams.G,
  2310. d = this.ecpubhex.substr(2, 128),
  2311. k = new SM3Digest,
  2312. b = (new SM3Digest).GetZ(b, d),
  2313. b = k.GetWords(k.GetHex(b).toString()),
  2314. d = CryptoJS.enc.Utf8.stringify(this.md.md._data),
  2315. d = CryptoJS.enc.Utf8.parse(d).toString(),
  2316. d = k.GetWords(d),
  2317. l = Array(k.GetDigestSize());
  2318. k.BlockUpdate(b, 0, b.length);
  2319. k.BlockUpdate(d, 0, d.length);
  2320. k.DoFinal(l, 0);
  2321. this.sHashHex = k.GetHex(l).toString()
  2322. } else
  2323. c = new KJUR.crypto.ECDSA({
  2324. curve: this.eccurvename
  2325. });
  2326. return c.verifyHex(this.sHashHex, a, this.ecpubhex)
  2327. }
  2328. if ("rsaandmgf1" == this.pubkeyAlgName)
  2329. return this.pubKey.verifyWithMessageHashPSS(this.sHashHex, a, this.mdAlgName, this.pssSaltLen);
  2330. if ("rsa" == this.pubkeyAlgName || this.pubKey instanceof KJUR.crypto.ECDSA || this.pubKey instanceof KJUR.crypto.DSA)
  2331. return this.pubKey.verifyWithMessageHash(this.sHashHex, a);
  2332. throw "Signature: unsupported public key alg: " + this.pubkeyAlgName;
  2333. }
  2334. }
  2335. };
  2336. this.init = function (a, b) {
  2337. throw "init(key, pass) not supported for this alg:prov=" + this.algProvName;
  2338. };
  2339. this.initVerifyByPublicKey = function (a) {
  2340. throw "initVerifyByPublicKey(rsaPubKeyy) not supported for this alg:prov=" + this.algProvName;
  2341. };
  2342. this.initVerifyByCertificatePEM = function (a) {
  2343. throw "initVerifyByCertificatePEM(certPEM) not supported for this alg:prov=" + this.algProvName;
  2344. };
  2345. this.initSign = function (a) {
  2346. throw "initSign(prvKey) not supported for this alg:prov=" + this.algProvName;
  2347. };
  2348. this.updateString = function (a) {
  2349. throw "updateString(str) not supported for this alg:prov=" + this.algProvName;
  2350. };
  2351. this.updateHex = function (a) {
  2352. throw "updateHex(hex) not supported for this alg:prov=" + this.algProvName;
  2353. };
  2354. this.sign = function () {
  2355. throw "sign() not supported for this alg:prov=" + this.algProvName;
  2356. };
  2357. this.signString = function (a) {
  2358. throw "digestString(str) not supported for this alg:prov=" + this.algProvName;
  2359. };
  2360. this.signHex = function (a) {
  2361. throw "digestHex(hex) not supported for this alg:prov=" + this.algProvName;
  2362. };
  2363. this.verify = function (a) {
  2364. throw "verify(hSigVal) not supported for this alg:prov=" + this.algProvName;
  2365. };
  2366. this.initParams = a;
  2367. if (void 0 !== a && (void 0 !== a.alg && (this.algName = a.alg,
  2368. this.provName = void 0 === a.prov ? KJUR.crypto.Util.DEFAULTPROVIDER[this.algName] : a.prov,
  2369. this.algProvName = this.algName + ":" + this.provName,
  2370. this.setAlgAndProvider(this.algName, this.provName),
  2371. this._setAlgNames()),
  2372. void 0 !== a.psssaltlen && (this.pssSaltLen = a.psssaltlen),
  2373. void 0 !== a.prvkeypem)) {
  2374. if (void 0 !== a.prvkeypas)
  2375. throw "both prvkeypem and prvkeypas parameters not supported";
  2376. try {
  2377. b = new RSAKey,
  2378. b.readPrivateKeyFromPEMString(a.prvkeypem),
  2379. this.initSign(b)
  2380. } catch (c) {
  2381. throw "fatal error to load pem private key: " + c;
  2382. }
  2383. }
  2384. };
  2385. KJUR.crypto.OID = new function () {
  2386. this.oidhex2name = {
  2387. "2a864886f70d010101": "rsaEncryption",
  2388. "2a8648ce3d0201": "ecPublicKey",
  2389. "2a8648ce380401": "dsa",
  2390. "2a8648ce3d030107": "secp256r1",
  2391. "2b8104001f": "secp192k1",
  2392. "2b81040021": "secp224r1",
  2393. "2b8104000a": "secp256k1",
  2394. "2b81040023": "secp521r1",
  2395. "2b81040022": "secp384r1",
  2396. "2a8648ce380403": "SHA1withDSA",
  2397. "608648016503040301": "SHA224withDSA",
  2398. "608648016503040302": "SHA256withDSA"
  2399. }
  2400. };
  2401.  
  2402. function ECFieldElementFp(a, b) {
  2403. this.x = b;
  2404. this.q = a
  2405. }
  2406.  
  2407. function feFpEquals(a) {
  2408. return a == this ? !0 : this.q.equals(a.q) && this.x.equals(a.x)
  2409. }
  2410.  
  2411. function feFpToBigInteger() {
  2412. return this.x
  2413. }
  2414.  
  2415. function feFpNegate() {
  2416. return new ECFieldElementFp(this.q, this.x.negate().mod(this.q))
  2417. }
  2418.  
  2419. function feFpAdd(a) {
  2420. return new ECFieldElementFp(this.q, this.x.add(a.toBigInteger()).mod(this.q))
  2421. }
  2422.  
  2423. function feFpSubtract(a) {
  2424. return new ECFieldElementFp(this.q, this.x.subtract(a.toBigInteger()).mod(this.q))
  2425. }
  2426.  
  2427. function feFpMultiply(a) {
  2428. return new ECFieldElementFp(this.q, this.x.multiply(a.toBigInteger()).mod(this.q))
  2429. }
  2430.  
  2431. function feFpSquare() {
  2432. return new ECFieldElementFp(this.q, this.x.square().mod(this.q))
  2433. }
  2434.  
  2435. function feFpDivide(a) {
  2436. return new ECFieldElementFp(this.q, this.x.multiply(a.toBigInteger().modInverse(this.q)).mod(this.q))
  2437. }
  2438. ECFieldElementFp.prototype.equals = feFpEquals;
  2439. ECFieldElementFp.prototype.toBigInteger = feFpToBigInteger;
  2440. ECFieldElementFp.prototype.negate = feFpNegate;
  2441. ECFieldElementFp.prototype.add = feFpAdd;
  2442. ECFieldElementFp.prototype.subtract = feFpSubtract;
  2443. ECFieldElementFp.prototype.multiply = feFpMultiply;
  2444. ECFieldElementFp.prototype.square = feFpSquare;
  2445. ECFieldElementFp.prototype.divide = feFpDivide;
  2446.  
  2447. function ECPointFp(a, b, c, d) {
  2448. this.curve = a;
  2449. this.x = b;
  2450. this.y = c;
  2451. this.z = null == d ? BigInteger.ONE : d;
  2452. this.zinv = null
  2453. }
  2454.  
  2455. function pointFpGetX() {
  2456. null == this.zinv && (this.zinv = this.z.modInverse(this.curve.q));
  2457. return this.curve.fromBigInteger(this.x.toBigInteger().multiply(this.zinv).mod(this.curve.q))
  2458. }
  2459.  
  2460. function pointFpGetY() {
  2461. null == this.zinv && (this.zinv = this.z.modInverse(this.curve.q));
  2462. return this.curve.fromBigInteger(this.y.toBigInteger().multiply(this.zinv).mod(this.curve.q))
  2463. }
  2464.  
  2465. function pointFpEquals(a) {
  2466. return a == this ? !0 : this.isInfinity() ? a.isInfinity() : a.isInfinity() ? this.isInfinity() : a.y.toBigInteger().multiply(this.z).subtract(this.y.toBigInteger().multiply(a.z)).mod(this.curve.q).equals(BigInteger.ZERO) ? a.x.toBigInteger().multiply(this.z).subtract(this.x.toBigInteger().multiply(a.z)).mod(this.curve.q).equals(BigInteger.ZERO) : !1
  2467. }
  2468.  
  2469. function pointFpIsInfinity() {
  2470. return null == this.x && null == this.y ? !0 : this.z.equals(BigInteger.ZERO) && !this.y.toBigInteger().equals(BigInteger.ZERO)
  2471. }
  2472.  
  2473. function pointFpNegate() {
  2474. return new ECPointFp(this.curve, this.x, this.y.negate(), this.z)
  2475. }
  2476.  
  2477. function pointFpAdd(a) {
  2478. if (this.isInfinity())
  2479. return a;
  2480. if (a.isInfinity())
  2481. return this;
  2482. var b = a.y.toBigInteger().multiply(this.z).subtract(this.y.toBigInteger().multiply(a.z)).mod(this.curve.q),
  2483. c = a.x.toBigInteger().multiply(this.z).subtract(this.x.toBigInteger().multiply(a.z)).mod(this.curve.q);
  2484. if (BigInteger.ZERO.equals(c))
  2485. return BigInteger.ZERO.equals(b) ? this.twice() : this.curve.getInfinity();
  2486. var d = new BigInteger("3"),
  2487. e = this.x.toBigInteger(),
  2488. f = this.y.toBigInteger();
  2489. a.x.toBigInteger();
  2490. a.y.toBigInteger();
  2491. var g = c.square(),
  2492. h = g.multiply(c),
  2493. e = e.multiply(g),
  2494. g = b.square().multiply(this.z),
  2495. c = g.subtract(e.shiftLeft(1)).multiply(a.z).subtract(h).multiply(c).mod(this.curve.q),
  2496. b = e.multiply(d).multiply(b).subtract(f.multiply(h)).subtract(g.multiply(b)).multiply(a.z).add(b.multiply(h)).mod(this.curve.q);
  2497. a = h.multiply(this.z).multiply(a.z).mod(this.curve.q);
  2498. return new ECPointFp(this.curve, this.curve.fromBigInteger(c), this.curve.fromBigInteger(b), a)
  2499. }
  2500.  
  2501. function pointFpTwice() {
  2502. if (this.isInfinity())
  2503. return this;
  2504. if (0 == this.y.toBigInteger().signum())
  2505. return this.curve.getInfinity();
  2506. var a = new BigInteger("3"),
  2507. b = this.x.toBigInteger(),
  2508. c = this.y.toBigInteger(),
  2509. d = c.multiply(this.z),
  2510. e = d.multiply(c).mod(this.curve.q),
  2511. c = this.curve.a.toBigInteger(),
  2512. f = b.square().multiply(a);
  2513. BigInteger.ZERO.equals(c) || (f = f.add(this.z.square().multiply(c)));
  2514. f = f.mod(this.curve.q);
  2515. c = f.square().subtract(b.shiftLeft(3).multiply(e)).shiftLeft(1).multiply(d).mod(this.curve.q);
  2516. a = f.multiply(a).multiply(b).subtract(e.shiftLeft(1)).shiftLeft(2).multiply(e).subtract(f.square().multiply(f)).mod(this.curve.q);
  2517. d = d.square().multiply(d).shiftLeft(3).mod(this.curve.q);
  2518. return new ECPointFp(this.curve, this.curve.fromBigInteger(c), this.curve.fromBigInteger(a), d)
  2519. }
  2520.  
  2521. function pointFpMultiply(a) {
  2522. if (this.isInfinity())
  2523. return this;
  2524. if (0 == a.signum())
  2525. return this.curve.getInfinity();
  2526. var b = a.multiply(new BigInteger("3")),
  2527. c = this.negate(),
  2528. d = this,
  2529. e;
  2530. for (e = b.bitLength() - 2; 0 < e; --e) {
  2531. var d = d.twice(),
  2532. f = b.testBit(e),
  2533. g = a.testBit(e);
  2534. f != g && (d = d.add(f ? this : c))
  2535. }
  2536. return d
  2537. }
  2538.  
  2539. function pointFpMultiplyTwo(a, b, c) {
  2540. var d;
  2541. d = a.bitLength() > c.bitLength() ? a.bitLength() - 1 : c.bitLength() - 1;
  2542. for (var e = this.curve.getInfinity(), f = this.add(b); 0 <= d;)
  2543. e = e.twice(),
  2544. a.testBit(d) ? e = c.testBit(d) ? e.add(f) : e.add(this) : c.testBit(d) && (e = e.add(b)),
  2545. --d;
  2546. return e
  2547. }
  2548. ECPointFp.prototype.getX = pointFpGetX;
  2549. ECPointFp.prototype.getY = pointFpGetY;
  2550. ECPointFp.prototype.equals = pointFpEquals;
  2551. ECPointFp.prototype.isInfinity = pointFpIsInfinity;
  2552. ECPointFp.prototype.negate = pointFpNegate;
  2553. ECPointFp.prototype.add = pointFpAdd;
  2554. ECPointFp.prototype.twice = pointFpTwice;
  2555. ECPointFp.prototype.multiply = pointFpMultiply;
  2556. ECPointFp.prototype.multiplyTwo = pointFpMultiplyTwo;
  2557.  
  2558. function ECCurveFp(a, b, c) {
  2559. this.q = a;
  2560. this.a = this.fromBigInteger(b);
  2561. this.b = this.fromBigInteger(c);
  2562. this.infinity = new ECPointFp(this, null, null)
  2563. }
  2564.  
  2565. function curveFpGetQ() {
  2566. return this.q
  2567. }
  2568.  
  2569. function curveFpGetA() {
  2570. return this.a
  2571. }
  2572.  
  2573. function curveFpGetB() {
  2574. return this.b
  2575. }
  2576.  
  2577. function curveFpEquals(a) {
  2578. return a == this ? !0 : this.q.equals(a.q) && this.a.equals(a.a) && this.b.equals(a.b)
  2579. }
  2580.  
  2581. function curveFpGetInfinity() {
  2582. return this.infinity
  2583. }
  2584.  
  2585. function curveFpFromBigInteger(a) {
  2586. return new ECFieldElementFp(this.q, a)
  2587. }
  2588.  
  2589. function curveFpDecodePointHex(a) {
  2590. switch (parseInt(a.substr(0, 2), 16)) {
  2591. case 0:
  2592. return this.infinity;
  2593. case 2:
  2594. case 3:
  2595. return null;
  2596. case 4:
  2597. case 6:
  2598. case 7:
  2599. var b = (a.length - 2) / 2,
  2600. c = a.substr(2, b);
  2601. a = a.substr(b + 2, b);
  2602. return new ECPointFp(this, this.fromBigInteger(new BigInteger(c, 16)), this.fromBigInteger(new BigInteger(a, 16)));
  2603. default:
  2604. return null
  2605. }
  2606. }
  2607. ECCurveFp.prototype.getQ = curveFpGetQ;
  2608. ECCurveFp.prototype.getA = curveFpGetA;
  2609. ECCurveFp.prototype.getB = curveFpGetB;
  2610. ECCurveFp.prototype.equals = curveFpEquals;
  2611. ECCurveFp.prototype.getInfinity = curveFpGetInfinity;
  2612. ECCurveFp.prototype.fromBigInteger = curveFpFromBigInteger;
  2613. ECCurveFp.prototype.decodePointHex = curveFpDecodePointHex;
  2614. ECFieldElementFp.prototype.getByteLength = function () {
  2615. return Math.floor((this.toBigInteger().bitLength() + 7) / 8)
  2616. };
  2617. ECPointFp.prototype.getEncoded = function (a) {
  2618. var b = function (a, c) {
  2619. var b = a.toByteArrayUnsigned();
  2620. if (c < b.length)
  2621. b = b.slice(b.length - c);
  2622. else
  2623. for (; c > b.length;)
  2624. b.unshift(0);
  2625. return b
  2626. },
  2627. c = this.getX().toBigInteger(),
  2628. d = this.getY().toBigInteger(),
  2629. c = b(c, 32);
  2630. a ? d.isEven() ? c.unshift(2) : c.unshift(3) : (c.unshift(4),
  2631. c = c.concat(b(d, 32)));
  2632. return c
  2633. };
  2634. ECPointFp.decodeFrom = function (a, b) {
  2635. var c = b.length - 1,
  2636. d = b.slice(1, 1 + c / 2),
  2637. c = b.slice(1 + c / 2, 1 + c);
  2638. d.unshift(0);
  2639. c.unshift(0);
  2640. d = new BigInteger(d);
  2641. c = new BigInteger(c);
  2642. return new ECPointFp(a, a.fromBigInteger(d), a.fromBigInteger(c))
  2643. };
  2644. ECPointFp.decodeFromHex = function (a, b) {
  2645. b.substr(0, 2);
  2646. var c = b.length - 2,
  2647. d = b.substr(2, c / 2),
  2648. c = b.substr(2 + c / 2, c / 2),
  2649. d = new BigInteger(d, 16),
  2650. c = new BigInteger(c, 16);
  2651. return new ECPointFp(a, a.fromBigInteger(d), a.fromBigInteger(c))
  2652. };
  2653. ECPointFp.prototype.add2D = function (a) {
  2654. if (this.isInfinity())
  2655. return a;
  2656. if (a.isInfinity())
  2657. return this;
  2658. if (this.x.equals(a.x))
  2659. return this.y.equals(a.y) ? this.twice() : this.curve.getInfinity();
  2660. var b = a.x.subtract(this.x),
  2661. b = a.y.subtract(this.y).divide(b);
  2662. a = b.square().subtract(this.x).subtract(a.x);
  2663. b = b.multiply(this.x.subtract(a)).subtract(this.y);
  2664. return new ECPointFp(this.curve, a, b)
  2665. };
  2666. ECPointFp.prototype.twice2D = function () {
  2667. if (this.isInfinity())
  2668. return this;
  2669. if (0 == this.y.toBigInteger().signum())
  2670. return this.curve.getInfinity();
  2671. var a = this.curve.fromBigInteger(BigInteger.valueOf(2)),
  2672. b = this.curve.fromBigInteger(BigInteger.valueOf(3)),
  2673. b = this.x.square().multiply(b).add(this.curve.a).divide(this.y.multiply(a)),
  2674. a = b.square().subtract(this.x.multiply(a)),
  2675. b = b.multiply(this.x.subtract(a)).subtract(this.y);
  2676. return new ECPointFp(this.curve, a, b)
  2677. };
  2678. ECPointFp.prototype.multiply2D = function (a) {
  2679. if (this.isInfinity())
  2680. return this;
  2681. if (0 == a.signum())
  2682. return this.curve.getInfinity();
  2683. var b = a.multiply(new BigInteger("3")),
  2684. c = this.negate(),
  2685. d = this,
  2686. e;
  2687. for (e = b.bitLength() - 2; 0 < e; --e) {
  2688. var d = d.twice(),
  2689. f = b.testBit(e),
  2690. g = a.testBit(e);
  2691. f != g && (d = d.add2D(f ? this : c))
  2692. }
  2693. return d
  2694. };
  2695. ECPointFp.prototype.isOnCurve = function () {
  2696. var a = this.getX().toBigInteger(),
  2697. b = this.getY().toBigInteger(),
  2698. c = this.curve.getA().toBigInteger(),
  2699. d = this.curve.getB().toBigInteger(),
  2700. e = this.curve.getQ(),
  2701. b = b.multiply(b).mod(e),
  2702. a = a.multiply(a).multiply(a).add(c.multiply(a)).add(d).mod(e);
  2703. return b.equals(a)
  2704. };
  2705. ECPointFp.prototype.toString = function () {
  2706. return "(" + this.getX().toBigInteger().toString() + "," + this.getY().toBigInteger().toString() + ")"
  2707. };
  2708. ECPointFp.prototype.validate = function () {
  2709. var a = this.curve.getQ();
  2710. if (this.isInfinity())
  2711. throw Error("Point is at infinity.");
  2712. var b = this.getX().toBigInteger(),
  2713. c = this.getY().toBigInteger();
  2714. if (0 > b.compareTo(BigInteger.ONE) || 0 < b.compareTo(a.subtract(BigInteger.ONE)))
  2715. throw Error("x coordinate out of bounds");
  2716. if (0 > c.compareTo(BigInteger.ONE) || 0 < c.compareTo(a.subtract(BigInteger.ONE)))
  2717. throw Error("y coordinate out of bounds");
  2718. if (!this.isOnCurve())
  2719. throw Error("Point is not on the curve.");
  2720. if (this.multiply(a).isInfinity())
  2721. throw Error("Point is not a scalar multiple of G.");
  2722. return !0
  2723. };
  2724. "undefined" != typeof KJUR && KJUR || (KJUR = {});
  2725. "undefined" != typeof KJUR.crypto && KJUR.crypto || (KJUR.crypto = {});
  2726. KJUR.crypto.ECDSA = function (a) {
  2727. var b = new SecureRandom;
  2728. this.type = "EC";
  2729. this.getBigRandom = function (a) {
  2730. return (new BigInteger(a.bitLength(), b)).mod(a.subtract(BigInteger.ONE)).add(BigInteger.ONE)
  2731. };
  2732. this.setNamedCurve = function (a) {
  2733. this.ecparams = KJUR.crypto.ECParameterDB.getByName(a);
  2734. this.pubKeyHex = this.prvKeyHex = null;
  2735. this.curveName = a
  2736. };
  2737. this.setPrivateKeyHex = function (a) {
  2738. this.isPrivate = !0;
  2739. this.prvKeyHex = a
  2740. };
  2741. this.setPublicKeyHex = function (a) {
  2742. this.isPublic = !0;
  2743. this.pubKeyHex = a
  2744. };
  2745. this.generateKeyPairHex = function () {
  2746. var a = this.getBigRandom(this.ecparams.n),
  2747. b = this.ecparams.G.multiply(a),
  2748. e = b.getX().toBigInteger(),
  2749. b = b.getY().toBigInteger(),
  2750. f = this.ecparams.keylen / 4,
  2751. a = ("0000000000" + a.toString(16)).slice(-f),
  2752. e = ("0000000000" + e.toString(16)).slice(-f),
  2753. b = ("0000000000" + b.toString(16)).slice(-f),
  2754. e = "04" + e + b;
  2755. this.setPrivateKeyHex(a);
  2756. this.setPublicKeyHex(e);
  2757. return {
  2758. ecprvhex: a,
  2759. ecpubhex: e
  2760. }
  2761. };
  2762. this.signWithMessageHash = function (a) {
  2763. return this.signHex(a, this.prvKeyHex)
  2764. };
  2765. this.signHex = function (a, b) {
  2766. var e = new BigInteger(b, 16),
  2767. f = this.ecparams.n,
  2768. g = new BigInteger(a, 16);
  2769. do
  2770. var h = this.getBigRandom(f),
  2771. k = this.ecparams.G.multiply(h).getX().toBigInteger().mod(f);
  2772. while (0 >= k.compareTo(BigInteger.ZERO));
  2773. e = h.modInverse(f).multiply(g.add(e.multiply(k))).mod(f);
  2774. return KJUR.crypto.ECDSA.biRSSigToASN1Sig(k, e)
  2775. };
  2776. this.sign = function (a, b) {
  2777. var e = this.ecparams.n,
  2778. f = BigInteger.fromByteArrayUnsigned(a);
  2779. do
  2780. var g = this.getBigRandom(e),
  2781. h = this.ecparams.G.multiply(g).getX().toBigInteger().mod(e);
  2782. while (0 >= h.compareTo(BigInteger.ZERO));
  2783. e = g.modInverse(e).multiply(f.add(b.multiply(h))).mod(e);
  2784. return this.serializeSig(h, e)
  2785. };
  2786. this.verifyWithMessageHash = function (a, b) {
  2787. return this.verifyHex(a, b, this.pubKeyHex)
  2788. };
  2789. this.verifyHex = function (a, b, e) {
  2790. var f;
  2791. f = KJUR.crypto.ECDSA.parseSigHex(b);
  2792. b = f.r;
  2793. f = f.s;
  2794. e = ECPointFp.decodeFromHex(this.ecparams.curve, e);
  2795. a = new BigInteger(a, 16);
  2796. return this.verifyRaw(a, b, f, e)
  2797. };
  2798. this.verify = function (a, b, e) {
  2799. var f;
  2800. if (Bitcoin.Util.isArray(b))
  2801. b = this.parseSig(b),
  2802. f = b.r,
  2803. b = b.s;
  2804. else if ("object" === typeof b && b.r && b.s)
  2805. f = b.r,
  2806. b = b.s;
  2807. else
  2808. throw "Invalid value for signature";
  2809. if (!(e instanceof ECPointFp))
  2810. if (Bitcoin.Util.isArray(e))
  2811. e = ECPointFp.decodeFrom(this.ecparams.curve, e);
  2812. else
  2813. throw "Invalid format for pubkey value, must be byte array or ECPointFp";
  2814. a = BigInteger.fromByteArrayUnsigned(a);
  2815. return this.verifyRaw(a, f, b, e)
  2816. };
  2817. this.verifyRaw = function (a, b, e, f) {
  2818. var g = this.ecparams.n,
  2819. h = this.ecparams.G;
  2820. if (0 > b.compareTo(BigInteger.ONE) || 0 <= b.compareTo(g) || 0 > e.compareTo(BigInteger.ONE) || 0 <= e.compareTo(g))
  2821. return !1;
  2822. e = e.modInverse(g);
  2823. a = a.multiply(e).mod(g);
  2824. e = b.multiply(e).mod(g);
  2825. return h.multiply(a).add(f.multiply(e)).getX().toBigInteger().mod(g).equals(b)
  2826. };
  2827. this.serializeSig = function (a, b) {
  2828. var e = a.toByteArraySigned(),
  2829. f = b.toByteArraySigned(),
  2830. g = [];
  2831. g.push(2);
  2832. g.push(e.length);
  2833. g = g.concat(e);
  2834. g.push(2);
  2835. g.push(f.length);
  2836. g = g.concat(f);
  2837. g.unshift(g.length);
  2838. g.unshift(48);
  2839. return g
  2840. };
  2841. this.parseSig = function (a) {
  2842. var b;
  2843. if (48 != a[0])
  2844. throw Error("Signature not a valid DERSequence");
  2845. b = 2;
  2846. if (2 != a[b])
  2847. throw Error("First element in signature must be a DERInteger");
  2848. var e = a.slice(b + 2, b + 2 + a[b + 1]);
  2849. b += 2 + a[b + 1];
  2850. if (2 != a[b])
  2851. throw Error("Second element in signature must be a DERInteger");
  2852. a = a.slice(b + 2, b + 2 + a[b + 1]);
  2853. e = BigInteger.fromByteArrayUnsigned(e);
  2854. a = BigInteger.fromByteArrayUnsigned(a);
  2855. return {
  2856. r: e,
  2857. s: a
  2858. }
  2859. };
  2860. this.parseSigCompact = function (a) {
  2861. if (65 !== a.length)
  2862. throw "Signature has the wrong length";
  2863. var b = a[0] - 27;
  2864. if (0 > b || 7 < b)
  2865. throw "Invalid signature type";
  2866. var e = this.ecparams.n,
  2867. f = BigInteger.fromByteArrayUnsigned(a.slice(1, 33)).mod(e);
  2868. a = BigInteger.fromByteArrayUnsigned(a.slice(33, 65)).mod(e);
  2869. return {
  2870. r: f,
  2871. s: a,
  2872. i: b
  2873. }
  2874. };
  2875. void 0 !== a && void 0 !== a.curve && (this.curveName = a.curve);
  2876. void 0 === this.curveName && (this.curveName = "secp256r1");
  2877. this.setNamedCurve(this.curveName);
  2878. void 0 !== a && (void 0 !== a.prv && this.setPrivateKeyHex(a.prv),
  2879. void 0 !== a.pub && this.setPublicKeyHex(a.pub))
  2880. };
  2881. KJUR.crypto.ECDSA.parseSigHex = function (a) {
  2882. var b = KJUR.crypto.ECDSA.parseSigHexInHexRS(a);
  2883. a = new BigInteger(b.r, 16);
  2884. b = new BigInteger(b.s, 16);
  2885. return {
  2886. r: a,
  2887. s: b
  2888. }
  2889. };
  2890. KJUR.crypto.ECDSA.parseSigHexInHexRS = function (a) {
  2891. if ("30" != a.substr(0, 2))
  2892. throw "signature is not a ASN.1 sequence";
  2893. var b = ASN1HEX.getPosArrayOfChildren_AtObj(a, 0);
  2894. if (2 != b.length)
  2895. throw "number of signature ASN.1 sequence elements seem wrong";
  2896. var c = b[0],
  2897. b = b[1];
  2898. if ("02" != a.substr(c, 2))
  2899. throw "1st item of sequene of signature is not ASN.1 integer";
  2900. if ("02" != a.substr(b, 2))
  2901. throw "2nd item of sequene of signature is not ASN.1 integer";
  2902. c = ASN1HEX.getHexOfV_AtObj(a, c);
  2903. a = ASN1HEX.getHexOfV_AtObj(a, b);
  2904. return {
  2905. r: c,
  2906. s: a
  2907. }
  2908. };
  2909. KJUR.crypto.ECDSA.asn1SigToConcatSig = function (a) {
  2910. var b = KJUR.crypto.ECDSA.parseSigHexInHexRS(a);
  2911. a = b.r;
  2912. b = b.s;
  2913. "00" == a.substr(0, 2) && 8 == a.length / 2 * 8 % 128 && (a = a.substr(2));
  2914. "00" == b.substr(0, 2) && 8 == b.length / 2 * 8 % 128 && (b = b.substr(2));
  2915. if (0 != a.length / 2 * 8 % 128)
  2916. throw "unknown ECDSA sig r length error";
  2917. if (0 != b.length / 2 * 8 % 128)
  2918. throw "unknown ECDSA sig s length error";
  2919. return a + b
  2920. };
  2921. KJUR.crypto.ECDSA.concatSigToASN1Sig = function (a) {
  2922. if (0 != a.length / 2 * 8 % 128)
  2923. throw "unknown ECDSA concatinated r-s sig length error";
  2924. var b = a.substr(0, a.length / 2);
  2925. a = a.substr(a.length / 2);
  2926. return KJUR.crypto.ECDSA.hexRSSigToASN1Sig(b, a)
  2927. };
  2928. KJUR.crypto.ECDSA.hexRSSigToASN1Sig = function (a, b) {
  2929. var c = new BigInteger(a, 16),
  2930. d = new BigInteger(b, 16);
  2931. return KJUR.crypto.ECDSA.biRSSigToASN1Sig(c, d)
  2932. };
  2933. KJUR.crypto.ECDSA.biRSSigToASN1Sig = function (a, b) {
  2934. var c = new KJUR.asn1.DERInteger({
  2935. bigint: a
  2936. }),
  2937. d = new KJUR.asn1.DERInteger({
  2938. bigint: b
  2939. });
  2940. return (new KJUR.asn1.DERSequence({
  2941. array: [c, d]
  2942. })).getEncodedHex()
  2943. };
  2944. (function () {
  2945. var a = CryptoJS,
  2946. b = a.lib,
  2947. c = b.WordArray,
  2948. d = b.Hasher,
  2949. e = [],
  2950. b = a.algo.SM3 = d.extend({
  2951. _doReset: function () {
  2952. this._hash = new c.init([1937774191, 1226093241, 388252375, 3666478592, 2842636476, 372324522, 3817729613, 2969243214])
  2953. },
  2954. _doProcessBlock: function (a, b) {
  2955. for (var c = this._hash.words, d = c[0], l = c[1], p = c[2], n = c[3], q = c[4], m = 0; 80 > m; m++) {
  2956. if (16 > m)
  2957. e[m] = a[b + m] | 0;
  2958. else {
  2959. var r = e[m - 3] ^ e[m - 8] ^ e[m - 14] ^ e[m - 16];
  2960. e[m] = r << 1 | r >>> 31
  2961. }
  2962. r = (d << 5 | d >>> 27) + q + e[m];
  2963. r = 20 > m ? r + ((l & p | ~l & n) + 1518500249) : 40 > m ? r + ((l ^ p ^ n) + 1859775393) : 60 > m ? r + ((l & p | l & n | p & n) - 1894007588) : r + ((l ^ p ^ n) - 899497514);
  2964. q = n;
  2965. n = p;
  2966. p = l << 30 | l >>> 2;
  2967. l = d;
  2968. d = r
  2969. }
  2970. c[0] = c[0] + d | 0;
  2971. c[1] = c[1] + l | 0;
  2972. c[2] = c[2] + p | 0;
  2973. c[3] = c[3] + n | 0;
  2974. c[4] = c[4] + q | 0
  2975. },
  2976. _doFinalize: function () {
  2977. var a = this._data,
  2978. b = a.words,
  2979. c = 8 * this._nDataBytes,
  2980. d = 8 * a.sigBytes;
  2981. b[d >>> 5] |= 128 << 24 - d % 32;
  2982. b[(d + 64 >>> 9 << 4) + 14] = Math.floor(c / 4294967296);
  2983. b[(d + 64 >>> 9 << 4) + 15] = c;
  2984. a.sigBytes = 4 * b.length;
  2985. this._process();
  2986. return this._hash
  2987. },
  2988. clone: function () {
  2989. var a = d.clone.call(this);
  2990. a._hash = this._hash.clone();
  2991. return a
  2992. }
  2993. });
  2994. a.SM3 = d._createHelper(b);
  2995. a.HmacSM3 = d._createHmacHelper(b)
  2996. })();
  2997.  
  2998. function SM3Digest() {
  2999. this.BYTE_LENGTH = 64;
  3000. this.xBuf = [];
  3001. this.byteCount = this.xBufOff = 0;
  3002. this.DIGEST_LENGTH = 32;
  3003. this.v0 = [1937774191, 1226093241, 388252375, 3666478592, 2842636476, 372324522, 3817729613, 2969243214];
  3004. this.v0 = [1937774191, 1226093241, 388252375, -628488704, -1452330820, 372324522, -477237683, -1325724082];
  3005. this.v = Array(8);
  3006. this.v_ = Array(8);
  3007. this.X0 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
  3008. this.X = Array(68);
  3009. this.xOff = 0;
  3010. this.T_00_15 = 2043430169;
  3011. this.T_16_63 = 2055708042;
  3012. 0 < arguments.length ? this.InitDigest(arguments[0]) : this.Init()
  3013. }
  3014. SM3Digest.prototype = {
  3015. Init: function () {
  3016. this.xBuf = Array(4);
  3017. this.Reset()
  3018. },
  3019. InitDigest: function (a) {
  3020. this.xBuf = Array(a.xBuf.length);
  3021. Array.Copy(a.xBuf, 0, this.xBuf, 0, a.xBuf.length);
  3022. this.xBufOff = a.xBufOff;
  3023. this.byteCount = a.byteCount;
  3024. Array.Copy(a.X, 0, this.X, 0, a.X.length);
  3025. this.xOff = a.xOff;
  3026. Array.Copy(a.v, 0, this.v, 0, a.v.length)
  3027. },
  3028. GetDigestSize: function () {
  3029. return this.DIGEST_LENGTH
  3030. },
  3031. Reset: function () {
  3032. this.xBufOff = this.byteCount = 0;
  3033. Array.Clear(this.xBuf, 0, this.xBuf.length);
  3034. Array.Copy(this.v0, 0, this.v, 0, this.v0.length);
  3035. this.xOff = 0;
  3036. Array.Copy(this.X0, 0, this.X, 0, this.X0.length)
  3037. },
  3038. GetByteLength: function () {
  3039. return this.BYTE_LENGTH
  3040. },
  3041. ProcessBlock: function () {
  3042. var a, b = this.X,
  3043. c = Array(64);
  3044. for (a = 16; 68 > a; a++)
  3045. b[a] = this.P1(b[a - 16] ^ b[a - 9] ^ this.ROTATE(b[a - 3], 15)) ^ this.ROTATE(b[a - 13], 7) ^ b[a - 6];
  3046. for (a = 0; 64 > a; a++)
  3047. c[a] = b[a] ^ b[a + 4];
  3048. var d = this.v,
  3049. e = this.v_;
  3050. Array.Copy(d, 0, e, 0, this.v0.length);
  3051. var f, g;
  3052. for (a = 0; 16 > a; a++)
  3053. g = this.ROTATE(e[0], 12),
  3054. f = Int32.parse(Int32.parse(g + e[4]) + this.ROTATE(this.T_00_15, a)),
  3055. f = this.ROTATE(f, 7),
  3056. g ^= f,
  3057. g = Int32.parse(Int32.parse(this.FF_00_15(e[0], e[1], e[2]) + e[3]) + g) + c[a],
  3058. f = Int32.parse(Int32.parse(this.GG_00_15(e[4], e[5], e[6]) + e[7]) + f) + b[a],
  3059. e[3] = e[2],
  3060. e[2] = this.ROTATE(e[1], 9),
  3061. e[1] = e[0],
  3062. e[0] = g,
  3063. e[7] = e[6],
  3064. e[6] = this.ROTATE(e[5], 19),
  3065. e[5] = e[4],
  3066. e[4] = this.P0(f);
  3067. for (a = 16; 64 > a; a++)
  3068. g = this.ROTATE(e[0], 12),
  3069. f = Int32.parse(Int32.parse(g + e[4]) + this.ROTATE(this.T_16_63, a)),
  3070. f = this.ROTATE(f, 7),
  3071. g ^= f,
  3072. g = Int32.parse(Int32.parse(this.FF_16_63(e[0], e[1], e[2]) + e[3]) + g) + c[a],
  3073. f = Int32.parse(Int32.parse(this.GG_16_63(e[4], e[5], e[6]) + e[7]) + f) + b[a],
  3074. e[3] = e[2],
  3075. e[2] = this.ROTATE(e[1], 9),
  3076. e[1] = e[0],
  3077. e[0] = g,
  3078. e[7] = e[6],
  3079. e[6] = this.ROTATE(e[5], 19),
  3080. e[5] = e[4],
  3081. e[4] = this.P0(f);
  3082. for (a = 0; 8 > a; a++)
  3083. d[a] ^= Int32.parse(e[a]);
  3084. this.xOff = 0;
  3085. Array.Copy(this.X0, 0, this.X, 0, this.X0.length)
  3086. },
  3087. ProcessWord: function (a, b) {
  3088. var c = a[b] << 24,
  3089. c = c | (a[++b] & 255) << 16,
  3090. c = c | (a[++b] & 255) << 8,
  3091. c = c | a[++b] & 255;
  3092. this.X[this.xOff] = c;
  3093. 16 == ++this.xOff && this.ProcessBlock()
  3094. },
  3095. ProcessLength: function (a) {
  3096. 14 < this.xOff && this.ProcessBlock();
  3097. this.X[14] = this.URShiftLong(a, 32);
  3098. this.X[15] = a & 4294967295
  3099. },
  3100. IntToBigEndian: function (a, b, c) {
  3101. b[c] = Int32.parseByte(this.URShift(a, 24));
  3102. b[++c] = Int32.parseByte(this.URShift(a, 16));
  3103. b[++c] = Int32.parseByte(this.URShift(a, 8));
  3104. b[++c] = Int32.parseByte(a)
  3105. },
  3106. DoFinal: function (a, b) {
  3107. this.Finish();
  3108. for (var c = 0; 8 > c; c++)
  3109. this.IntToBigEndian(this.v[c], a, b + 4 * c);
  3110. this.Reset();
  3111. for (var d = a.length, c = 0; c < d; c++)
  3112. a[c] &= 255;
  3113. return this.DIGEST_LENGTH
  3114. },
  3115. Update: function (a) {
  3116. this.xBuf[this.xBufOff++] = a;
  3117. this.xBufOff == this.xBuf.length && (this.ProcessWord(this.xBuf, 0),
  3118. this.xBufOff = 0);
  3119. this.byteCount++
  3120. },
  3121. BlockUpdate: function (a, b, c) {
  3122. for (; 0 != this.xBufOff && 0 < c;)
  3123. this.Update(a[b]),
  3124. b++,
  3125. c--;
  3126. for (; c > this.xBuf.length;)
  3127. this.ProcessWord(a, b),
  3128. b += this.xBuf.length,
  3129. c -= this.xBuf.length,
  3130. this.byteCount += this.xBuf.length;
  3131. for (; 0 < c;)
  3132. this.Update(a[b]),
  3133. b++,
  3134. c--
  3135. },
  3136. Finish: function () {
  3137. var a = this.byteCount << 3;
  3138. for (this.Update(128); 0 != this.xBufOff;)
  3139. this.Update(0);
  3140. this.ProcessLength(a);
  3141. this.ProcessBlock()
  3142. },
  3143. ROTATE: function (a, b) {
  3144. return a << b | this.URShift(a, 32 - b)
  3145. },
  3146. P0: function (a) {
  3147. return a ^ this.ROTATE(a, 9) ^ this.ROTATE(a, 17)
  3148. },
  3149. P1: function (a) {
  3150. return a ^ this.ROTATE(a, 15) ^ this.ROTATE(a, 23)
  3151. },
  3152. FF_00_15: function (a, b, c) {
  3153. return a ^ b ^ c
  3154. },
  3155. FF_16_63: function (a, b, c) {
  3156. return a & b | a & c | b & c
  3157. },
  3158. GG_00_15: function (a, b, c) {
  3159. return a ^ b ^ c
  3160. },
  3161. GG_16_63: function (a, b, c) {
  3162. return a & b | ~a & c
  3163. },
  3164. URShift: function (a, b) {
  3165. if (a > Int32.maxValue || a < Int32.minValue)
  3166. a = Int32.parse(a);
  3167. return 0 <= a ? a >> b : (a >> b) + (2 << ~b)
  3168. },
  3169. URShiftLong: function (a, b) {
  3170. var c;
  3171. c = new BigInteger;
  3172. c.fromInt(a);
  3173. if (0 <= c.signum())
  3174. c = c.shiftRight(b).intValue();
  3175. else {
  3176. var d = new BigInteger;
  3177. d.fromInt(2);
  3178. var e = ~b;
  3179. c = "";
  3180. if (0 > e) {
  3181. d = 64 + e;
  3182. for (e = 0; e < d; e++)
  3183. c += "0";
  3184. d = new BigInteger;
  3185. d.fromInt(a >> b);
  3186. c = new BigInteger("10" + c, 2);
  3187. c.toRadix(10);
  3188. c = c.add(d).toRadix(10)
  3189. } else
  3190. c = d.shiftLeft(~b).intValue(),
  3191. c = (a >> b) + c
  3192. }
  3193. return c
  3194. },
  3195. GetZ: function (a, b) {
  3196. var c = CryptoJS.enc.Utf8.parse("1234567812345678"),
  3197. d = 32 * c.words.length;
  3198. this.Update(d >> 8 & 255);
  3199. this.Update(d & 255);
  3200. c = this.GetWords(c.toString());
  3201. this.BlockUpdate(c, 0, c.length);
  3202. var c = this.GetWords(a.curve.a.toBigInteger().toRadix(16)),
  3203. d = this.GetWords(a.curve.b.toBigInteger().toRadix(16)),
  3204. e = this.GetWords(a.getX().toBigInteger().toRadix(16)),
  3205. f = this.GetWords(a.getY().toBigInteger().toRadix(16)),
  3206. g = this.GetWords(b.substr(0, 64)),
  3207. h = this.GetWords(b.substr(64, 64));
  3208. this.BlockUpdate(c, 0, c.length);
  3209. this.BlockUpdate(d, 0, d.length);
  3210. this.BlockUpdate(e, 0, e.length);
  3211. this.BlockUpdate(f, 0, f.length);
  3212. this.BlockUpdate(g, 0, g.length);
  3213. this.BlockUpdate(h, 0, h.length);
  3214. c = Array(this.GetDigestSize());
  3215. this.DoFinal(c, 0);
  3216. return c
  3217. },
  3218. GetWords: function (a) {
  3219. for (var b = [], c = a.length, d = 0; d < c; d += 2)
  3220. b[b.length] = parseInt(a.substr(d, 2), 16);
  3221. return b
  3222. },
  3223. GetHex: function (a) {
  3224. for (var b = [], c = 0, d = 0; d < 2 * a.length; d += 2)
  3225. b[d >>> 3] |= parseInt(a[c]) << 24 - d % 8 * 4,
  3226. c++;
  3227. return new CryptoJS.lib.WordArray.init(b, a.length)
  3228. }
  3229. };
  3230. Array.Clear = function (a, b, c) {
  3231. for (var elm in a)
  3232. a[elm] = null
  3233. };
  3234. Array.Copy = function (a, b, c, d, e) {
  3235. a = a.slice(b, b + e);
  3236. for (b = 0; b < a.length; b++)
  3237. c[d] = a[b],
  3238. d++
  3239. };
  3240. var Int32 = { //zdk
  3241. minValue: -parseInt("10000000000000000000000000000000", 2),
  3242. maxValue: 2147483647,
  3243. parse: function (a) {
  3244. if (a < this.minValue) {
  3245. a = new Number(-a);
  3246. a = a.toString(2);
  3247. a = a.substr(a.length - 31, 31);
  3248. for (var b = "", c = 0; c < a.length; c++)
  3249. var d = a.substr(c, 1),
  3250. b = b + ("0" == d ? "1" : "0");
  3251. a = parseInt(b, 2);
  3252. return a + 1
  3253. }
  3254. if (a > this.maxValue) {
  3255. a = Number(a);
  3256. a = a.toString(2);
  3257. a = a.substr(a.length - 31, 31);
  3258. b = "";
  3259. for (c = 0; c < a.length; c++)
  3260. d = a.substr(c, 1),
  3261. b += "0" == d ? "1" : "0";
  3262. a = parseInt(b, 2);
  3263. return -(a + 1)
  3264. }
  3265. return a
  3266. },
  3267. parseByte: function (a) {
  3268. if (0 > a) {
  3269. a = new Number(-a);
  3270. a = a.toString(2);
  3271. a = a.substr(a.length - 8, 8);
  3272. for (var b = "", c = 0; c < a.length; c++)
  3273. var d = a.substr(c, 1),
  3274. b = b + ("0" == d ? "1" : "0");
  3275. return parseInt(b, 2) + 1
  3276. }
  3277. return 255 < a ? (a = Number(a),
  3278. a = a.toString(2),
  3279. parseInt(a.substr(a.length - 8, 8), 2)) : a
  3280. }
  3281. };
  3282. "undefined" != typeof KJUR && KJUR || (KJUR = {});
  3283. "undefined" != typeof KJUR.crypto && KJUR.crypto || (KJUR.crypto = {});
  3284. KJUR.crypto.SM3withSM2 = function (a) {
  3285. var b = new SecureRandom;
  3286. this.type = "SM2";
  3287. this.getBigRandom = function (a) {
  3288. return (new BigInteger(a.bitLength(), b)).mod(a.subtract(BigInteger.ONE)).add(BigInteger.ONE)
  3289. };
  3290. this.setNamedCurve = function (a) {
  3291. this.ecparams = KJUR.crypto.ECParameterDB.getByName(a);
  3292. this.pubKeyHex = this.prvKeyHex = null;
  3293. this.curveName = a
  3294. };
  3295. this.setPrivateKeyHex = function (a) {
  3296. this.isPrivate = !0;
  3297. this.prvKeyHex = a
  3298. };
  3299. this.setPublicKeyHex = function (a) {
  3300. this.isPublic = !0;
  3301. this.pubKeyHex = a
  3302. };
  3303. this.generateKeyPairHex = function () {
  3304. var a = this.getBigRandom(this.ecparams.n),
  3305. b = this.ecparams.G.multiply(a),
  3306. e = b.getX().toBigInteger(),
  3307. b = b.getY().toBigInteger(),
  3308. f = this.ecparams.keylen / 4,
  3309. a = ("0000000000" + a.toString(16)).slice(-f),
  3310. e = ("0000000000" + e.toString(16)).slice(-f),
  3311. b = ("0000000000" + b.toString(16)).slice(-f),
  3312. e = "04" + e + b;
  3313. this.setPrivateKeyHex(a);
  3314. this.setPublicKeyHex(e);
  3315. return {
  3316. ecprvhex: a,
  3317. ecpubhex: e
  3318. }
  3319. };
  3320. this.signWithMessageHash = function (a) {
  3321. return this.signHex(a, this.prvKeyHex)
  3322. };
  3323. this.signHex = function (a, b) {
  3324. var e = new BigInteger(b, 16),
  3325. f = this.ecparams.n,
  3326. g = new BigInteger(a, 16),
  3327. h = null,
  3328. k = null,
  3329. l = k = null;
  3330. do {
  3331. do
  3332. k = this.generateKeyPairHex(),
  3333. h = new BigInteger(k.ecprvhex, 16),
  3334. k = ECPointFp.decodeFromHex(this.ecparams.curve, k.ecpubhex),
  3335. k = g.add(k.getX().toBigInteger()),
  3336. k = k.mod(f);
  3337. while (k.equals(BigInteger.ZERO) || k.add(h).equals(f));
  3338. var p = e.add(BigInteger.ONE),
  3339. p = p.modInverse(f),
  3340. l = k.multiply(e),
  3341. l = h.subtract(l).mod(f),
  3342. l = p.multiply(l).mod(f)
  3343. } while (l.equals(BigInteger.ZERO));
  3344. return KJUR.crypto.ECDSA.biRSSigToASN1Sig(k, l)
  3345. };
  3346. this.sign = function (a, b) {
  3347. var e = this.ecparams.n,
  3348. f = BigInteger.fromByteArrayUnsigned(a);
  3349. do
  3350. var g = this.getBigRandom(e),
  3351. h = this.ecparams.G.multiply(g).getX().toBigInteger().mod(e);
  3352. while (0 >= h.compareTo(BigInteger.ZERO));
  3353. e = g.modInverse(e).multiply(f.add(b.multiply(h))).mod(e);
  3354. return this.serializeSig(h, e)
  3355. };
  3356. this.verifyWithMessageHash = function (a, b) {
  3357. return this.verifyHex(a, b, this.pubKeyHex)
  3358. };
  3359. this.verifyHex = function (a, b, e) {
  3360. var f;
  3361. f = KJUR.crypto.ECDSA.parseSigHex(b);
  3362. b = f.r;
  3363. f = f.s;
  3364. e = ECPointFp.decodeFromHex(this.ecparams.curve, e);
  3365. a = new BigInteger(a, 16);
  3366. return this.verifyRaw(a, b, f, e)
  3367. };
  3368. this.verify = function (a, b, e) {
  3369. var f;
  3370. if (Bitcoin.Util.isArray(b))
  3371. b = this.parseSig(b),
  3372. f = b.r,
  3373. b = b.s;
  3374. else if ("object" === typeof b && b.r && b.s)
  3375. f = b.r,
  3376. b = b.s;
  3377. else
  3378. throw "Invalid value for signature";
  3379. if (!(e instanceof ECPointFp))
  3380. if (Bitcoin.Util.isArray(e))
  3381. e = ECPointFp.decodeFrom(this.ecparams.curve, e);
  3382. else
  3383. throw "Invalid format for pubkey value, must be byte array or ECPointFp";
  3384. a = BigInteger.fromByteArrayUnsigned(a);
  3385. return this.verifyRaw(a, f, b, e)
  3386. };
  3387. this.verifyRaw = function (a, b, e, f) {
  3388. var g = this.ecparams.n,
  3389. h = this.ecparams.G,
  3390. k = b.add(e).mod(g);
  3391. if (k.equals(BigInteger.ZERO))
  3392. return !1;
  3393. e = h.multiply(e);
  3394. e = e.add(f.multiply(k));
  3395. a = a.add(e.getX().toBigInteger()).mod(g);
  3396. return b.equals(a)
  3397. };
  3398. this.serializeSig = function (a, b) {
  3399. var e = a.toByteArraySigned(),
  3400. f = b.toByteArraySigned(),
  3401. g = [];
  3402. g.push(2);
  3403. g.push(e.length);
  3404. g = g.concat(e);
  3405. g.push(2);
  3406. g.push(f.length);
  3407. g = g.concat(f);
  3408. g.unshift(g.length);
  3409. g.unshift(48);
  3410. return g
  3411. };
  3412. this.parseSig = function (a) {
  3413. var b;
  3414. if (48 != a[0])
  3415. throw Error("Signature not a valid DERSequence");
  3416. b = 2;
  3417. if (2 != a[b])
  3418. throw Error("First element in signature must be a DERInteger");
  3419. var e = a.slice(b + 2, b + 2 + a[b + 1]);
  3420. b += 2 + a[b + 1];
  3421. if (2 != a[b])
  3422. throw Error("Second element in signature must be a DERInteger");
  3423. a = a.slice(b + 2, b + 2 + a[b + 1]);
  3424. e = BigInteger.fromByteArrayUnsigned(e);
  3425. a = BigInteger.fromByteArrayUnsigned(a);
  3426. return {
  3427. r: e,
  3428. s: a
  3429. }
  3430. };
  3431. this.parseSigCompact = function (a) {
  3432. if (65 !== a.length)
  3433. throw "Signature has the wrong length";
  3434. var b = a[0] - 27;
  3435. if (0 > b || 7 < b)
  3436. throw "Invalid signature type";
  3437. var e = this.ecparams.n,
  3438. f = BigInteger.fromByteArrayUnsigned(a.slice(1, 33)).mod(e);
  3439. a = BigInteger.fromByteArrayUnsigned(a.slice(33, 65)).mod(e);
  3440. return {
  3441. r: f,
  3442. s: a,
  3443. i: b
  3444. }
  3445. };
  3446. void 0 !== a && void 0 !== a.curve && (this.curveName = a.curve);
  3447. void 0 === this.curveName && (this.curveName = "sm2");
  3448. this.setNamedCurve(this.curveName);
  3449. void 0 !== a && (void 0 !== a.prv && this.setPrivateKeyHex(a.prv),
  3450. void 0 !== a.pub && this.setPublicKeyHex(a.pub))
  3451. };
  3452. "undefined" != typeof KJUR && KJUR || (KJUR = {});
  3453. "undefined" != typeof KJUR.crypto && KJUR.crypto || (KJUR.crypto = {});
  3454. KJUR.crypto.ECParameterDB = new function () {
  3455. var a = {},
  3456. b = {};
  3457. this.getByName = function (c) {
  3458. var d = c;
  3459. "undefined" != typeof b[d] && (d = b[c]);
  3460. if ("undefined" != typeof a[d])
  3461. return a[d];
  3462. throw "unregistered EC curve name: " + d;
  3463. };
  3464. this.regist = function (c, d, e, f, g, h, k, l, p, n, q, m) {
  3465. a[c] = {};
  3466. e = new BigInteger(e, 16);
  3467. f = new BigInteger(f, 16);
  3468. g = new BigInteger(g, 16);
  3469. h = new BigInteger(h, 16);
  3470. k = new BigInteger(k, 16);
  3471. e = new ECCurveFp(e, f, g);
  3472. l = e.decodePointHex("04" + l + p);
  3473. a[c].name = c;
  3474. a[c].keylen = d;
  3475. a[c].curve = e;
  3476. a[c].G = l;
  3477. a[c].n = h;
  3478. a[c].h = k;
  3479. a[c].oid = q;
  3480. a[c].info = m;
  3481. for (d = 0; d < n.length; d++)
  3482. b[n[d]] = c
  3483. }
  3484. };
  3485. KJUR.crypto.ECParameterDB.regist("secp128r1", 128, "FFFFFFFDFFFFFFFFFFFFFFFFFFFFFFFF", "FFFFFFFDFFFFFFFFFFFFFFFFFFFFFFFC", "E87579C11079F43DD824993C2CEE5ED3", "FFFFFFFE0000000075A30D1B9038A115", "1", "161FF7528B899B2D0C28607CA52C5B86", "CF5AC8395BAFEB13C02DA292DDED7A83", [], "", "secp128r1 : SECG curve over a 128 bit prime field");
  3486. KJUR.crypto.ECParameterDB.regist("secp160k1", 160, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFAC73", "0", "7", "0100000000000000000001B8FA16DFAB9ACA16B6B3", "1", "3B4C382CE37AA192A4019E763036F4F5DD4D7EBB", "938CF935318FDCED6BC28286531733C3F03C4FEE", [], "", "secp160k1 : SECG curve over a 160 bit prime field");
  3487. KJUR.crypto.ECParameterDB.regist("secp160r1", 160, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFF", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFC", "1C97BEFC54BD7A8B65ACF89F81D4D4ADC565FA45", "0100000000000000000001F4C8F927AED3CA752257", "1", "4A96B5688EF573284664698968C38BB913CBFC82", "23A628553168947D59DCC912042351377AC5FB32", [], "", "secp160r1 : SECG curve over a 160 bit prime field");
  3488. KJUR.crypto.ECParameterDB.regist("secp192k1", 192, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFEE37", "0", "3", "FFFFFFFFFFFFFFFFFFFFFFFE26F2FC170F69466A74DEFD8D", "1", "DB4FF10EC057E9AE26B07D0280B7F4341DA5D1B1EAE06C7D", "9B2F2F6D9C5628A7844163D015BE86344082AA88D95E2F9D", []);
  3489. KJUR.crypto.ECParameterDB.regist("secp192r1", 192, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFF", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFC", "64210519E59C80E70FA7E9AB72243049FEB8DEECC146B9B1", "FFFFFFFFFFFFFFFFFFFFFFFF99DEF836146BC9B1B4D22831", "1", "188DA80EB03090F67CBF20EB43A18800F4FF0AFD82FF1012", "07192B95FFC8DA78631011ED6B24CDD573F977A11E794811", []);
  3490. KJUR.crypto.ECParameterDB.regist("secp224r1", 224, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000000000000000001", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFE", "B4050A850C04B3ABF54132565044B0B7D7BFD8BA270B39432355FFB4", "FFFFFFFFFFFFFFFFFFFFFFFFFFFF16A2E0B8F03E13DD29455C5C2A3D", "1", "B70E0CBD6BB4BF7F321390B94A03C1D356C21122343280D6115C1D21", "BD376388B5F723FB4C22DFE6CD4375A05A07476444D5819985007E34", []);
  3491. KJUR.crypto.ECParameterDB.regist("secp256k1", 256, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F", "0", "7", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141", "1", "79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798", "483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8", []);
  3492. KJUR.crypto.ECParameterDB.regist("secp256r1", 256, "FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF", "FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFC", "5AC635D8AA3A93E7B3EBBD55769886BC651D06B0CC53B0F63BCE3C3E27D2604B", "FFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632551", "1", "6B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C296", "4FE342E2FE1A7F9B8EE7EB4A7C0F9E162BCE33576B315ECECBB6406837BF51F5", ["NIST P-256", "P-256", "prime256v1"]);
  3493. KJUR.crypto.ECParameterDB.regist("secp384r1", 384, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFF0000000000000000FFFFFFFF", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFF0000000000000000FFFFFFFC", "B3312FA7E23EE7E4988E056BE3F82D19181D9C6EFE8141120314088F5013875AC656398D8A2ED19D2A85C8EDD3EC2AEF", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC7634D81F4372DDF581A0DB248B0A77AECEC196ACCC52973", "1", "AA87CA22BE8B05378EB1C71EF320AD746E1D3B628BA79B9859F741E082542A385502F25DBF55296C3A545E3872760AB7", "3617de4a96262c6f5d9e98bf9292dc29f8f41dbd289a147ce9da3113b5f0b8c00a60b1ce1d7e819d7a431d7c90ea0e5f", ["NIST P-384", "P-384"]);
  3494. KJUR.crypto.ECParameterDB.regist("secp521r1", 521, "1FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", "1FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC", "051953EB9618E1C9A1F929A21A0B68540EEA2DA725B99B315F3B8B489918EF109E156193951EC7E937B1652C0BD3BB1BF073573DF883D2C34F1EF451FD46B503F00", "1FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA51868783BF2F966B7FCC0148F709A5D03BB5C9B8899C47AEBB6FB71E91386409", "1", "C6858E06B70404E9CD9E3ECB662395B4429C648139053FB521F828AF606B4D3DBAA14B5E77EFE75928FE1DC127A2FFA8DE3348B3C1856A429BF97E7E31C2E5BD66", "011839296a789a3bc0045c8a5fb42c7d1bd998f54449579b446817afbd17273e662c97ee72995ef42640c550b9013fad0761353c7086a272c24088be94769fd16650", ["NIST P-521", "P-521"]);
  3495. KJUR.crypto.ECParameterDB.regist("sm2", 256, "FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFF", "FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFC", "28E9FA9E9D9F5E344D5A9E4BCF6509A7F39789F515AB8F92DDBCBD414D940E93", "FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFF7203DF6B21C6052B53BBF40939D54123", "1", "32C4AE2C1F1981195F9904466A39C9948FE30BBFF2660BE1715A4589334C74C7", "BC3736A2F4F6779C59BDCEE36B692153D0A9877CC62A474002DF32E52139F0A0", ["sm2", "SM2"]);
  3496.  
  3497. SM2Cipher.prototype = {
  3498. Reset: function () {
  3499. this.sm3keybase = new SM3Digest;
  3500. this.sm3c3 = new SM3Digest;
  3501. for (var a = this.p2.getX().toBigInteger().toRadix(16); 64 > a.length;)
  3502. a = "0" + a;
  3503. for (var a = this.GetWords(a), b = this.p2.getY().toBigInteger().toRadix(16); 64 > b.length;)
  3504. b = "0" + b;
  3505. b = this.GetWords(b);
  3506. this.sm3keybase.BlockUpdate(a, 0, a.length);
  3507. this.sm3c3.BlockUpdate(a, 0, a.length);
  3508. this.sm3keybase.BlockUpdate(b, 0, b.length);
  3509. this.ct = 1;
  3510. this.NextKey()
  3511. },
  3512. NextKey: function () {
  3513. var a = new SM3Digest(this.sm3keybase);
  3514. a.Update(this.ct >> 24 & 255);
  3515. a.Update(this.ct >> 16 & 255);
  3516. a.Update(this.ct >> 8 & 255);
  3517. a.Update(this.ct & 255);
  3518. a.DoFinal(this.key, 0);
  3519. this.keyOff = 0;
  3520. this.ct++
  3521. },
  3522. KDF: function (a) {
  3523. var b = Array(a),
  3524. c = new SM3Digest,
  3525. d = Array(32),
  3526. e = 1,
  3527. f = a / 32;
  3528. a %= 32;
  3529. for (var g = this.p2.getX().toBigInteger().toRadix(16); 64 > g.length;)
  3530. g = "0" + g;
  3531. for (var g = this.GetWords(g), h = this.p2.getY().toBigInteger().toRadix(16); 64 > h.length;)
  3532. h = "0" + h;
  3533. for (var h = this.GetWords(h), k = 0, l = 0; l < f; l++)
  3534. c.BlockUpdate(g, 0, g.length),
  3535. c.BlockUpdate(h, 0, h.length),
  3536. c.Update(e >> 24 & 255),
  3537. c.Update(e >> 16 & 255),
  3538. c.Update(e >> 8 & 255),
  3539. c.Update(e & 255),
  3540. c.DoFinal(b, k),
  3541. k += 32,
  3542. e++;
  3543. 0 != a && (c.BlockUpdate(g, 0, g.length),
  3544. c.BlockUpdate(h, 0, h.length),
  3545. c.Update(e >> 24 & 255),
  3546. c.Update(e >> 16 & 255),
  3547. c.Update(e >> 8 & 255),
  3548. c.Update(e & 255),
  3549. c.DoFinal(d, 0));
  3550. Array.Copy(d, 0, b, k, a);
  3551. for (l = 0; l < b.length; l++)
  3552. b[l] &= 255;
  3553. return b
  3554. },
  3555. InitEncipher: function (a) {
  3556. var b = null,
  3557. c = null,
  3558. c = new KJUR.crypto.ECDSA({
  3559. curve: "sm2"
  3560. }),
  3561. d = c.generateKeyPairHex(),
  3562. b = new BigInteger(d.ecprvhex, 16),
  3563. c = ECPointFp.decodeFromHex(c.ecparams.curve, d.ecpubhex);
  3564. this.p2 = a.multiply(b);
  3565. this.Reset();
  3566. return c
  3567. },
  3568. EncryptBlock: function (a) {
  3569. this.sm3c3.BlockUpdate(a, 0, a.length);
  3570. for (var b = this.KDF(a.length), c = 0; c < a.length; c++)
  3571. a[c] ^= b[c]
  3572. },
  3573. InitDecipher: function (a, b) {
  3574. this.p2 = b.multiply(a);
  3575. this.p2.getX().toBigInteger().toRadix(16);
  3576. this.p2.getY().toBigInteger().toRadix(16);
  3577. this.Reset()
  3578. },
  3579. DecryptBlock: function (a) {
  3580. for (var b = this.KDF(a.length), c = 0, d = "", c = 0; c < b.length; c++)
  3581. d += b[c].toString(16);
  3582. for (c = 0; c < a.length; c++)
  3583. a[c] ^= b[c];
  3584. this.sm3c3.BlockUpdate(a, 0, a.length)
  3585. },
  3586. Dofinal: function (a) {
  3587. for (var b = this.p2.getY().toBigInteger().toRadix(16); 64 > b.length;)
  3588. b = "0" + b;
  3589. b = this.GetWords(b);
  3590. this.sm3c3.BlockUpdate(b, 0, b.length);
  3591. this.sm3c3.DoFinal(a, 0);
  3592. this.Reset()
  3593. },
  3594. Encrypt: function (a, b) {
  3595. var c = Array(b.length);
  3596. Array.Copy(b, 0, c, 0, b.length);
  3597. var d = this.InitEncipher(a);
  3598. this.EncryptBlock(c);
  3599. var e = Array(32);
  3600. this.Dofinal(e);
  3601. for (var f = d.getX().toBigInteger().toRadix(16), d = d.getY().toBigInteger().toRadix(16); 64 > f.length;)
  3602. f = "0" + f;
  3603. for (; 64 > d.length;)
  3604. d = "0" + d;
  3605. f += d;
  3606. c = this.GetHex(c).toString();
  3607. 0 != c.length % 2 && (c = "0" + c);
  3608. e = this.GetHex(e).toString();
  3609. d = f + c + e;
  3610. this.cipherMode == SM2CipherMode.C1C3C2 && (d = f + e + c);
  3611. return d
  3612. },
  3613. GetWords: function (a) {
  3614. for (var b = [], c = a.length, d = 0; d < c; d += 2)
  3615. b[b.length] = parseInt(a.substr(d, 2), 16);
  3616. return b
  3617. },
  3618. GetHex: function (a) {
  3619. for (var b = [], c = 0, d = 0; d < 2 * a.length; d += 2)
  3620. b[d >>> 3] |= parseInt(a[c]) << 24 - d % 8 * 4,
  3621. c++;
  3622. return new CryptoJS.lib.WordArray.init(b, a.length)
  3623. },
  3624. Decrypt: function (a, b) {
  3625. var c = b.substr(0, 64),
  3626. d = b.substr(0 + c.length, 64),
  3627. e = b.substr(c.length + d.length, b.length - c.length - d.length - 64),
  3628. f = b.substr(b.length - 64);
  3629. this.cipherMode == SM2CipherMode.C1C3C2 && (f = b.substr(c.length + d.length, 64),
  3630. e = b.substr(c.length + d.length + 64));
  3631. e = this.GetWords(e);
  3632. c = this.CreatePoint(c, d);
  3633. this.InitDecipher(a, c);
  3634. this.DecryptBlock(e);
  3635. c = Array(32);
  3636. this.Dofinal(c);
  3637. return this.GetHex(c).toString() == f ? (f = this.GetHex(e),
  3638. CryptoJS.enc.Utf8.stringify(f)) : ""
  3639. },
  3640. CreatePoint: function (a, b) {
  3641. var c = new KJUR.crypto.ECDSA({
  3642. curve: "sm2"
  3643. });
  3644. return ECPointFp.decodeFromHex(c.ecparams.curve, "04" + a + b)
  3645. }
  3646. };
  3647.  
  3648. /*-------------下面修改----------*/
  3649.  
  3650. var SM2Key = function (key) {
  3651. this.setKey(key);
  3652. };
  3653.  
  3654. function SM2SetKey(key) {
  3655. if (key && typeof key === 'object') {
  3656. this.eccX = key.eccX;
  3657. this.eccY = key.eccY;
  3658. } else {
  3659. this.eccX = "F1342ADB38855E1F8C37D1181378DE446E52788389F7DB3DEA022A1FC4D4D856";
  3660. this.eccY = "66FC6DE253C822F1E52914D9E0B80C5D825759CE696CF039A8449F98017510B7";
  3661. }
  3662. }
  3663.  
  3664. /*
  3665. *加密数据
  3666. */
  3667. function SM2Encrypt(text) {
  3668. var cipherMode = SM2CipherMode.C1C3C2,
  3669. cipher = new SM2Cipher(cipherMode),
  3670. textData = CryptoJS.enc.Utf8.parse(text);
  3671. var cipher = new SM2Cipher(cipherMode);
  3672. var userKey = cipher.CreatePoint(this.eccX, this.eccY);
  3673. var msgData = cipher.GetWords(textData.toString());
  3674.  
  3675. return cipher.Encrypt(userKey, msgData);
  3676. }
  3677.  
  3678. SM2Key.prototype.setKey = SM2SetKey;
  3679. SM2Key.prototype.encrypt = SM2Encrypt;
  3680.  
  3681. //export default SM2Key;
  3682. global.SM2 = {
  3683. SM2CipherMode: SM2CipherMode,
  3684. SM2Cipher: SM2Cipher,
  3685. CryptoJS: CryptoJS
  3686. }
  3687. }(window));
  3688.  
  3689. window.SM2Utils = {};
  3690.  
  3691. function sm2Encrypt(data, publickey, cipherMode) {
  3692. cipherMode = cipherMode == 0 ? cipherMode : 1;
  3693. // msg = SM2.utf8tob64(msg);
  3694. var msgData = CryptoJS.enc.Utf8.parse(data);
  3695.  
  3696. msgData = CryptoJS.enc.Base64.stringify(msgData);
  3697. //在转utf-8
  3698. msgData = CryptoJS.enc.Utf8.parse(msgData);
  3699.  
  3700. var pubkeyHex = publickey;
  3701. if (pubkeyHex.length > 64 * 2) {
  3702. pubkeyHex = pubkeyHex.substr(pubkeyHex.length - 64 * 2);
  3703. }
  3704. var xHex = pubkeyHex.substr(0, 64);
  3705. var yHex = pubkeyHex.substr(64);
  3706. var cipher = new SM2Cipher(cipherMode);
  3707. var userKey = cipher.CreatePoint(xHex, yHex);
  3708. msgData = cipher.GetWords(msgData.toString());
  3709. var encryptData = cipher.Encrypt(userKey, msgData);
  3710.  
  3711. return '04' + encryptData;
  3712. }
  3713.  
  3714. /**
  3715. * 根据公钥进行加密
  3716. */
  3717. SM2Utils.encs = function (key, s, cipherMode) {
  3718. if (s == null || s.length == 0) {
  3719. return "";
  3720. }
  3721. return sm2Encrypt(s, key, cipherMode);
  3722. }

crypto-js.js

  1. !function(t,r){"object"==typeof exports?module.exports=exports=r():"function"==typeof define&&define.amd?define([],r):t.CryptoJS=r()}(this,function(){var t=t||function(t,r){var e=Object.create||function(){function t(){}return function(r){var e;return t.prototype=r,e=new t,t.prototype=null,e}}(),i={},n=i.lib={},o=n.Base=function(){return{extend:function(t){var r=e(this);return t&&r.mixIn(t),r.hasOwnProperty("init")&&this.init!==r.init||(r.init=function(){r.$super.init.apply(this,arguments)}),r.init.prototype=r,r.$super=this,r},create:function(){var t=this.extend();return t.init.apply(t,arguments),t},init:function(){},mixIn:function(t){for(var r in t)t.hasOwnProperty(r)&&(this[r]=t[r]);t.hasOwnProperty("toString")&&(this.toString=t.toString)},clone:function(){return this.init.prototype.extend(this)}}}(),s=n.WordArray=o.extend({init:function(t,e){t=this.words=t||[],e!=r?this.sigBytes=e:this.sigBytes=4*t.length},toString:function(t){return(t||c).stringify(this)},concat:function(t){var r=this.words,e=t.words,i=this.sigBytes,n=t.sigBytes;if(this.clamp(),i%4)for(var o=0;o<n;o++){var s=e[o>>>2]>>>24-o%4*8&255;r[i+o>>>2]|=s<<24-(i+o)%4*8}else for(var o=0;o<n;o+=4)r[i+o>>>2]=e[o>>>2];return this.sigBytes+=n,this},clamp:function(){var r=this.words,e=this.sigBytes;r[e>>>2]&=4294967295<<32-e%4*8,r.length=t.ceil(e/4)},clone:function(){var t=o.clone.call(this);return t.words=this.words.slice(0),t},random:function(r){for(var e,i=[],n=function(r){var r=r,e=987654321,i=4294967295;return function(){e=36969*(65535&e)+(e>>16)&i,r=18e3*(65535&r)+(r>>16)&i;var n=(e<<16)+r&i;return n/=4294967296,n+=.5,n*(t.random()>.5?1:-1)}},o=0;o<r;o+=4){var a=n(4294967296*(e||t.random()));e=987654071*a(),i.push(4294967296*a()|0)}return new s.init(i,r)}}),a=i.enc={},c=a.Hex={stringify:function(t){for(var r=t.words,e=t.sigBytes,i=[],n=0;n<e;n++){var o=r[n>>>2]>>>24-n%4*8&255;i.push((o>>>4).toString(16)),i.push((15&o).toString(16))}return i.join("")},parse:function(t){for(var r=t.length,e=[],i=0;i<r;i+=2)e[i>>>3]|=parseInt(t.substr(i,2),16)<<24-i%8*4;return new s.init(e,r/2)}},h=a.Latin1={stringify:function(t){for(var r=t.words,e=t.sigBytes,i=[],n=0;n<e;n++){var o=r[n>>>2]>>>24-n%4*8&255;i.push(String.fromCharCode(o))}return i.join("")},parse:function(t){for(var r=t.length,e=[],i=0;i<r;i++)e[i>>>2]|=(255&t.charCodeAt(i))<<24-i%4*8;return new s.init(e,r)}},l=a.Utf8={stringify:function(t){try{return decodeURIComponent(escape(h.stringify(t)))}catch(t){throw new Error("Malformed UTF-8 data")}},parse:function(t){return h.parse(unescape(encodeURIComponent(t)))}},f=n.BufferedBlockAlgorithm=o.extend({reset:function(){this._data=new s.init,this._nDataBytes=0},_append:function(t){"string"==typeof t&&(t=l.parse(t)),this._data.concat(t),this._nDataBytes+=t.sigBytes},_process:function(r){var e=this._data,i=e.words,n=e.sigBytes,o=this.blockSize,a=4*o,c=n/a;c=r?t.ceil(c):t.max((0|c)-this._minBufferSize,0);var h=c*o,l=t.min(4*h,n);if(h){for(var f=0;f<h;f+=o)this._doProcessBlock(i,f);var u=i.splice(0,h);e.sigBytes-=l}return new s.init(u,l)},clone:function(){var t=o.clone.call(this);return t._data=this._data.clone(),t},_minBufferSize:0}),u=(n.Hasher=f.extend({cfg:o.extend(),init:function(t){this.cfg=this.cfg.extend(t),this.reset()},reset:function(){f.reset.call(this),this._doReset()},update:function(t){return this._append(t),this._process(),this},finalize:function(t){t&&this._append(t);var r=this._doFinalize();return r},blockSize:16,_createHelper:function(t){return function(r,e){return new t.init(e).finalize(r)}},_createHmacHelper:function(t){return function(r,e){return new u.HMAC.init(t,e).finalize(r)}}}),i.algo={});return i}(Math);return function(){function r(t,r,e){for(var i=[],o=0,s=0;s<r;s++)if(s%4){var a=e[t.charCodeAt(s-1)]<<s%4*2,c=e[t.charCodeAt(s)]>>>6-s%4*2;i[o>>>2]|=(a|c)<<24-o%4*8,o++}return n.create(i,o)}var e=t,i=e.lib,n=i.WordArray,o=e.enc;o.Base64={stringify:function(t){var r=t.words,e=t.sigBytes,i=this._map;t.clamp();for(var n=[],o=0;o<e;o+=3)for(var s=r[o>>>2]>>>24-o%4*8&255,a=r[o+1>>>2]>>>24-(o+1)%4*8&255,c=r[o+2>>>2]>>>24-(o+2)%4*8&255,h=s<<16|a<<8|c,l=0;l<4&&o+.75*l<e;l++)n.push(i.charAt(h>>>6*(3-l)&63));var f=i.charAt(64);if(f)for(;n.length%4;)n.push(f);return n.join("")},parse:function(t){var e=t.length,i=this._map,n=this._reverseMap;if(!n){n=this._reverseMap=[];for(var o=0;o<i.length;o++)n[i.charCodeAt(o)]=o}var s=i.charAt(64);if(s){var a=t.indexOf(s);a!==-1&&(e=a)}return r(t,e,n)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="}}(),function(r){function e(t,r,e,i,n,o,s){var a=t+(r&e|~r&i)+n+s;return(a<<o|a>>>32-o)+r}function i(t,r,e,i,n,o,s){var a=t+(r&i|e&~i)+n+s;return(a<<o|a>>>32-o)+r}function n(t,r,e,i,n,o,s){var a=t+(r^e^i)+n+s;return(a<<o|a>>>32-o)+r}function o(t,r,e,i,n,o,s){var a=t+(e^(r|~i))+n+s;return(a<<o|a>>>32-o)+r}var s=t,a=s.lib,c=a.WordArray,h=a.Hasher,l=s.algo,f=[];!function(){for(var t=0;t<64;t++)f[t]=4294967296*r.abs(r.sin(t+1))|0}();var u=l.MD5=h.extend({_doReset:function(){this._hash=new c.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(t,r){for(var s=0;s<16;s++){var a=r+s,c=t[a];t[a]=16711935&(c<<8|c>>>24)|4278255360&(c<<24|c>>>8)}var h=this._hash.words,l=t[r+0],u=t[r+1],d=t[r+2],v=t[r+3],p=t[r+4],_=t[r+5],y=t[r+6],g=t[r+7],B=t[r+8],w=t[r+9],k=t[r+10],S=t[r+11],m=t[r+12],x=t[r+13],b=t[r+14],H=t[r+15],z=h[0],A=h[1],C=h[2],D=h[3];z=e(z,A,C,D,l,7,f[0]),D=e(D,z,A,C,u,12,f[1]),C=e(C,D,z,A,d,17,f[2]),A=e(A,C,D,z,v,22,f[3]),z=e(z,A,C,D,p,7,f[4]),D=e(D,z,A,C,_,12,f[5]),C=e(C,D,z,A,y,17,f[6]),A=e(A,C,D,z,g,22,f[7]),z=e(z,A,C,D,B,7,f[8]),D=e(D,z,A,C,w,12,f[9]),C=e(C,D,z,A,k,17,f[10]),A=e(A,C,D,z,S,22,f[11]),z=e(z,A,C,D,m,7,f[12]),D=e(D,z,A,C,x,12,f[13]),C=e(C,D,z,A,b,17,f[14]),A=e(A,C,D,z,H,22,f[15]),z=i(z,A,C,D,u,5,f[16]),D=i(D,z,A,C,y,9,f[17]),C=i(C,D,z,A,S,14,f[18]),A=i(A,C,D,z,l,20,f[19]),z=i(z,A,C,D,_,5,f[20]),D=i(D,z,A,C,k,9,f[21]),C=i(C,D,z,A,H,14,f[22]),A=i(A,C,D,z,p,20,f[23]),z=i(z,A,C,D,w,5,f[24]),D=i(D,z,A,C,b,9,f[25]),C=i(C,D,z,A,v,14,f[26]),A=i(A,C,D,z,B,20,f[27]),z=i(z,A,C,D,x,5,f[28]),D=i(D,z,A,C,d,9,f[29]),C=i(C,D,z,A,g,14,f[30]),A=i(A,C,D,z,m,20,f[31]),z=n(z,A,C,D,_,4,f[32]),D=n(D,z,A,C,B,11,f[33]),C=n(C,D,z,A,S,16,f[34]),A=n(A,C,D,z,b,23,f[35]),z=n(z,A,C,D,u,4,f[36]),D=n(D,z,A,C,p,11,f[37]),C=n(C,D,z,A,g,16,f[38]),A=n(A,C,D,z,k,23,f[39]),z=n(z,A,C,D,x,4,f[40]),D=n(D,z,A,C,l,11,f[41]),C=n(C,D,z,A,v,16,f[42]),A=n(A,C,D,z,y,23,f[43]),z=n(z,A,C,D,w,4,f[44]),D=n(D,z,A,C,m,11,f[45]),C=n(C,D,z,A,H,16,f[46]),A=n(A,C,D,z,d,23,f[47]),z=o(z,A,C,D,l,6,f[48]),D=o(D,z,A,C,g,10,f[49]),C=o(C,D,z,A,b,15,f[50]),A=o(A,C,D,z,_,21,f[51]),z=o(z,A,C,D,m,6,f[52]),D=o(D,z,A,C,v,10,f[53]),C=o(C,D,z,A,k,15,f[54]),A=o(A,C,D,z,u,21,f[55]),z=o(z,A,C,D,B,6,f[56]),D=o(D,z,A,C,H,10,f[57]),C=o(C,D,z,A,y,15,f[58]),A=o(A,C,D,z,x,21,f[59]),z=o(z,A,C,D,p,6,f[60]),D=o(D,z,A,C,S,10,f[61]),C=o(C,D,z,A,d,15,f[62]),A=o(A,C,D,z,w,21,f[63]),h[0]=h[0]+z|0,h[1]=h[1]+A|0,h[2]=h[2]+C|0,h[3]=h[3]+D|0},_doFinalize:function(){var t=this._data,e=t.words,i=8*this._nDataBytes,n=8*t.sigBytes;e[n>>>5]|=128<<24-n%32;var o=r.floor(i/4294967296),s=i;e[(n+64>>>9<<4)+15]=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8),e[(n+64>>>9<<4)+14]=16711935&(s<<8|s>>>24)|4278255360&(s<<24|s>>>8),t.sigBytes=4*(e.length+1),this._process();for(var a=this._hash,c=a.words,h=0;h<4;h++){var l=c[h];c[h]=16711935&(l<<8|l>>>24)|4278255360&(l<<24|l>>>8)}return a},clone:function(){var t=h.clone.call(this);return t._hash=this._hash.clone(),t}});s.MD5=h._createHelper(u),s.HmacMD5=h._createHmacHelper(u)}(Math),function(){var r=t,e=r.lib,i=e.WordArray,n=e.Hasher,o=r.algo,s=[],a=o.SHA1=n.extend({_doReset:function(){this._hash=new i.init([1732584193,4023233417,2562383102,271733878,3285377520])},_doProcessBlock:function(t,r){for(var e=this._hash.words,i=e[0],n=e[1],o=e[2],a=e[3],c=e[4],h=0;h<80;h++){if(h<16)s[h]=0|t[r+h];else{var l=s[h-3]^s[h-8]^s[h-14]^s[h-16];s[h]=l<<1|l>>>31}var f=(i<<5|i>>>27)+c+s[h];f+=h<20?(n&o|~n&a)+1518500249:h<40?(n^o^a)+1859775393:h<60?(n&o|n&a|o&a)-1894007588:(n^o^a)-899497514,c=a,a=o,o=n<<30|n>>>2,n=i,i=f}e[0]=e[0]+i|0,e[1]=e[1]+n|0,e[2]=e[2]+o|0,e[3]=e[3]+a|0,e[4]=e[4]+c|0},_doFinalize:function(){var t=this._data,r=t.words,e=8*this._nDataBytes,i=8*t.sigBytes;return r[i>>>5]|=128<<24-i%32,r[(i+64>>>9<<4)+14]=Math.floor(e/4294967296),r[(i+64>>>9<<4)+15]=e,t.sigBytes=4*r.length,this._process(),this._hash},clone:function(){var t=n.clone.call(this);return t._hash=this._hash.clone(),t}});r.SHA1=n._createHelper(a),r.HmacSHA1=n._createHmacHelper(a)}(),function(r){var e=t,i=e.lib,n=i.WordArray,o=i.Hasher,s=e.algo,a=[],c=[];!function(){function t(t){for(var e=r.sqrt(t),i=2;i<=e;i++)if(!(t%i))return!1;return!0}function e(t){return 4294967296*(t-(0|t))|0}for(var i=2,n=0;n<64;)t(i)&&(n<8&&(a[n]=e(r.pow(i,.5))),c[n]=e(r.pow(i,1/3)),n++),i++}();var h=[],l=s.SHA256=o.extend({_doReset:function(){this._hash=new n.init(a.slice(0))},_doProcessBlock:function(t,r){for(var e=this._hash.words,i=e[0],n=e[1],o=e[2],s=e[3],a=e[4],l=e[5],f=e[6],u=e[7],d=0;d<64;d++){if(d<16)h[d]=0|t[r+d];else{var v=h[d-15],p=(v<<25|v>>>7)^(v<<14|v>>>18)^v>>>3,_=h[d-2],y=(_<<15|_>>>17)^(_<<13|_>>>19)^_>>>10;h[d]=p+h[d-7]+y+h[d-16]}var g=a&l^~a&f,B=i&n^i&o^n&o,w=(i<<30|i>>>2)^(i<<19|i>>>13)^(i<<10|i>>>22),k=(a<<26|a>>>6)^(a<<21|a>>>11)^(a<<7|a>>>25),S=u+k+g+c[d]+h[d],m=w+B;u=f,f=l,l=a,a=s+S|0,s=o,o=n,n=i,i=S+m|0}e[0]=e[0]+i|0,e[1]=e[1]+n|0,e[2]=e[2]+o|0,e[3]=e[3]+s|0,e[4]=e[4]+a|0,e[5]=e[5]+l|0,e[6]=e[6]+f|0,e[7]=e[7]+u|0},_doFinalize:function(){var t=this._data,e=t.words,i=8*this._nDataBytes,n=8*t.sigBytes;return e[n>>>5]|=128<<24-n%32,e[(n+64>>>9<<4)+14]=r.floor(i/4294967296),e[(n+64>>>9<<4)+15]=i,t.sigBytes=4*e.length,this._process(),this._hash},clone:function(){var t=o.clone.call(this);return t._hash=this._hash.clone(),t}});e.SHA256=o._createHelper(l),e.HmacSHA256=o._createHmacHelper(l)}(Math),function(){function r(t){return t<<8&4278255360|t>>>8&16711935}var e=t,i=e.lib,n=i.WordArray,o=e.enc;o.Utf16=o.Utf16BE={stringify:function(t){for(var r=t.words,e=t.sigBytes,i=[],n=0;n<e;n+=2){var o=r[n>>>2]>>>16-n%4*8&65535;i.push(String.fromCharCode(o))}return i.join("")},parse:function(t){for(var r=t.length,e=[],i=0;i<r;i++)e[i>>>1]|=t.charCodeAt(i)<<16-i%2*16;return n.create(e,2*r)}};o.Utf16LE={stringify:function(t){for(var e=t.words,i=t.sigBytes,n=[],o=0;o<i;o+=2){var s=r(e[o>>>2]>>>16-o%4*8&65535);n.push(String.fromCharCode(s))}return n.join("")},parse:function(t){for(var e=t.length,i=[],o=0;o<e;o++)i[o>>>1]|=r(t.charCodeAt(o)<<16-o%2*16);return n.create(i,2*e)}}}(),function(){if("function"==typeof ArrayBuffer){var r=t,e=r.lib,i=e.WordArray,n=i.init,o=i.init=function(t){if(t instanceof ArrayBuffer&&(t=new Uint8Array(t)),(t instanceof Int8Array||"undefined"!=typeof Uint8ClampedArray&&t instanceof Uint8ClampedArray||t instanceof Int16Array||t instanceof Uint16Array||t instanceof Int32Array||t instanceof Uint32Array||t instanceof Float32Array||t instanceof Float64Array)&&(t=new Uint8Array(t.buffer,t.byteOffset,t.byteLength)),t instanceof Uint8Array){for(var r=t.byteLength,e=[],i=0;i<r;i++)e[i>>>2]|=t[i]<<24-i%4*8;n.call(this,e,r)}else n.apply(this,arguments)};o.prototype=i}}(),function(r){function e(t,r,e){return t^r^e}function i(t,r,e){return t&r|~t&e}function n(t,r,e){return(t|~r)^e}function o(t,r,e){return t&e|r&~e}function s(t,r,e){return t^(r|~e)}function a(t,r){return t<<r|t>>>32-r}var c=t,h=c.lib,l=h.WordArray,f=h.Hasher,u=c.algo,d=l.create([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8,3,10,14,4,9,15,8,1,2,7,0,6,13,11,5,12,1,9,11,10,0,8,12,4,13,3,7,15,14,5,6,2,4,0,5,9,7,12,2,10,14,1,3,8,11,6,15,13]),v=l.create([5,14,7,0,9,2,11,4,13,6,15,8,1,10,3,12,6,11,3,7,0,13,5,10,14,15,8,12,4,9,1,2,15,5,1,3,7,14,6,9,11,8,12,2,10,0,4,13,8,6,4,1,3,11,15,0,5,12,2,13,9,7,10,14,12,15,10,4,1,5,8,7,6,2,13,14,0,3,9,11]),p=l.create([11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8,7,6,8,13,11,9,7,15,7,12,15,9,11,7,13,12,11,13,6,7,14,9,13,15,14,8,13,6,5,12,7,5,11,12,14,15,14,15,9,8,9,14,5,6,8,6,5,12,9,15,5,11,6,8,13,12,5,12,13,14,11,8,5,6]),_=l.create([8,9,9,11,13,15,15,5,7,7,8,11,14,14,12,6,9,13,15,7,12,8,9,11,7,7,12,7,6,15,13,11,9,7,15,11,8,6,6,14,12,13,5,14,13,13,7,5,15,5,8,11,14,14,6,14,6,9,12,9,12,5,15,8,8,5,12,9,12,5,14,6,8,13,6,5,15,13,11,11]),y=l.create([0,1518500249,1859775393,2400959708,2840853838]),g=l.create([1352829926,1548603684,1836072691,2053994217,0]),B=u.RIPEMD160=f.extend({_doReset:function(){this._hash=l.create([1732584193,4023233417,2562383102,271733878,3285377520])},_doProcessBlock:function(t,r){for(var c=0;c<16;c++){var h=r+c,l=t[h];t[h]=16711935&(l<<8|l>>>24)|4278255360&(l<<24|l>>>8)}var f,u,B,w,k,S,m,x,b,H,z=this._hash.words,A=y.words,C=g.words,D=d.words,R=v.words,E=p.words,M=_.words;S=f=z[0],m=u=z[1],x=B=z[2],b=w=z[3],H=k=z[4];for(var F,c=0;c<80;c+=1)F=f+t[r+D[c]]|0,F+=c<16?e(u,B,w)+A[0]:c<32?i(u,B,w)+A[1]:c<48?n(u,B,w)+A[2]:c<64?o(u,B,w)+A[3]:s(u,B,w)+A[4],F|=0,F=a(F,E[c]),F=F+k|0,f=k,k=w,w=a(B,10),B=u,u=F,F=S+t[r+R[c]]|0,F+=c<16?s(m,x,b)+C[0]:c<32?o(m,x,b)+C[1]:c<48?n(m,x,b)+C[2]:c<64?i(m,x,b)+C[3]:e(m,x,b)+C[4],F|=0,F=a(F,M[c]),F=F+H|0,S=H,H=b,b=a(x,10),x=m,m=F;F=z[1]+B+b|0,z[1]=z[2]+w+H|0,z[2]=z[3]+k+S|0,z[3]=z[4]+f+m|0,z[4]=z[0]+u+x|0,z[0]=F},_doFinalize:function(){var t=this._data,r=t.words,e=8*this._nDataBytes,i=8*t.sigBytes;r[i>>>5]|=128<<24-i%32,r[(i+64>>>9<<4)+14]=16711935&(e<<8|e>>>24)|4278255360&(e<<24|e>>>8),t.sigBytes=4*(r.length+1),this._process();for(var n=this._hash,o=n.words,s=0;s<5;s++){var a=o[s];o[s]=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8)}return n},clone:function(){var t=f.clone.call(this);return t._hash=this._hash.clone(),t}});c.RIPEMD160=f._createHelper(B),c.HmacRIPEMD160=f._createHmacHelper(B)}(Math),function(){var r=t,e=r.lib,i=e.Base,n=r.enc,o=n.Utf8,s=r.algo;s.HMAC=i.extend({init:function(t,r){t=this._hasher=new t.init,"string"==typeof r&&(r=o.parse(r));var e=t.blockSize,i=4*e;r.sigBytes>i&&(r=t.finalize(r)),r.clamp();for(var n=this._oKey=r.clone(),s=this._iKey=r.clone(),a=n.words,c=s.words,h=0;h<e;h++)a[h]^=1549556828,c[h]^=909522486;n.sigBytes=s.sigBytes=i,this.reset()},reset:function(){var t=this._hasher;t.reset(),t.update(this._iKey)},update:function(t){return this._hasher.update(t),this},finalize:function(t){var r=this._hasher,e=r.finalize(t);r.reset();var i=r.finalize(this._oKey.clone().concat(e));return i}})}(),function(){var r=t,e=r.lib,i=e.Base,n=e.WordArray,o=r.algo,s=o.SHA1,a=o.HMAC,c=o.PBKDF2=i.extend({cfg:i.extend({keySize:4,hasher:s,iterations:1}),init:function(t){this.cfg=this.cfg.extend(t)},compute:function(t,r){for(var e=this.cfg,i=a.create(e.hasher,t),o=n.create(),s=n.create([1]),c=o.words,h=s.words,l=e.keySize,f=e.iterations;c.length<l;){var u=i.update(r).finalize(s);i.reset();for(var d=u.words,v=d.length,p=u,_=1;_<f;_++){p=i.finalize(p),i.reset();for(var y=p.words,g=0;g<v;g++)d[g]^=y[g]}o.concat(u),h[0]++}return o.sigBytes=4*l,o}});r.PBKDF2=function(t,r,e){return c.create(e).compute(t,r)}}(),function(){var r=t,e=r.lib,i=e.Base,n=e.WordArray,o=r.algo,s=o.MD5,a=o.EvpKDF=i.extend({cfg:i.extend({keySize:4,hasher:s,iterations:1}),init:function(t){this.cfg=this.cfg.extend(t)},compute:function(t,r){for(var e=this.cfg,i=e.hasher.create(),o=n.create(),s=o.words,a=e.keySize,c=e.iterations;s.length<a;){h&&i.update(h);var h=i.update(t).finalize(r);i.reset();for(var l=1;l<c;l++)h=i.finalize(h),i.reset();o.concat(h)}return o.sigBytes=4*a,o}});r.EvpKDF=function(t,r,e){return a.create(e).compute(t,r)}}(),function(){var r=t,e=r.lib,i=e.WordArray,n=r.algo,o=n.SHA256,s=n.SHA224=o.extend({_doReset:function(){this._hash=new i.init([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428])},_doFinalize:function(){var t=o._doFinalize.call(this);return t.sigBytes-=4,t}});r.SHA224=o._createHelper(s),r.HmacSHA224=o._createHmacHelper(s)}(),function(r){var e=t,i=e.lib,n=i.Base,o=i.WordArray,s=e.x64={};s.Word=n.extend({init:function(t,r){this.high=t,this.low=r}}),s.WordArray=n.extend({init:function(t,e){t=this.words=t||[],e!=r?this.sigBytes=e:this.sigBytes=8*t.length},toX32:function(){for(var t=this.words,r=t.length,e=[],i=0;i<r;i++){var n=t[i];e.push(n.high),e.push(n.low)}return o.create(e,this.sigBytes)},clone:function(){for(var t=n.clone.call(this),r=t.words=this.words.slice(0),e=r.length,i=0;i<e;i++)r[i]=r[i].clone();return t}})}(),function(r){var e=t,i=e.lib,n=i.WordArray,o=i.Hasher,s=e.x64,a=s.Word,c=e.algo,h=[],l=[],f=[];!function(){for(var t=1,r=0,e=0;e<24;e++){h[t+5*r]=(e+1)*(e+2)/2%64;var i=r%5,n=(2*t+3*r)%5;t=i,r=n}for(var t=0;t<5;t++)for(var r=0;r<5;r++)l[t+5*r]=r+(2*t+3*r)%5*5;for(var o=1,s=0;s<24;s++){for(var c=0,u=0,d=0;d<7;d++){if(1&o){var v=(1<<d)-1;v<32?u^=1<<v:c^=1<<v-32}128&o?o=o<<1^113:o<<=1}f[s]=a.create(c,u)}}();var u=[];!function(){for(var t=0;t<25;t++)u[t]=a.create()}();var d=c.SHA3=o.extend({cfg:o.cfg.extend({outputLength:512}),_doReset:function(){for(var t=this._state=[],r=0;r<25;r++)t[r]=new a.init;this.blockSize=(1600-2*this.cfg.outputLength)/32},_doProcessBlock:function(t,r){for(var e=this._state,i=this.blockSize/2,n=0;n<i;n++){var o=t[r+2*n],s=t[r+2*n+1];o=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8),s=16711935&(s<<8|s>>>24)|4278255360&(s<<24|s>>>8);var a=e[n];a.high^=s,a.low^=o}for(var c=0;c<24;c++){for(var d=0;d<5;d++){for(var v=0,p=0,_=0;_<5;_++){var a=e[d+5*_];v^=a.high,p^=a.low}var y=u[d];y.high=v,y.low=p}for(var d=0;d<5;d++)for(var g=u[(d+4)%5],B=u[(d+1)%5],w=B.high,k=B.low,v=g.high^(w<<1|k>>>31),p=g.low^(k<<1|w>>>31),_=0;_<5;_++){var a=e[d+5*_];a.high^=v,a.low^=p}for(var S=1;S<25;S++){var a=e[S],m=a.high,x=a.low,b=h[S];if(b<32)var v=m<<b|x>>>32-b,p=x<<b|m>>>32-b;else var v=x<<b-32|m>>>64-b,p=m<<b-32|x>>>64-b;var H=u[l[S]];H.high=v,H.low=p}var z=u[0],A=e[0];z.high=A.high,z.low=A.low;for(var d=0;d<5;d++)for(var _=0;_<5;_++){var S=d+5*_,a=e[S],C=u[S],D=u[(d+1)%5+5*_],R=u[(d+2)%5+5*_];a.high=C.high^~D.high&R.high,a.low=C.low^~D.low&R.low}var a=e[0],E=f[c];a.high^=E.high,a.low^=E.low}},_doFinalize:function(){var t=this._data,e=t.words,i=(8*this._nDataBytes,8*t.sigBytes),o=32*this.blockSize;e[i>>>5]|=1<<24-i%32,e[(r.ceil((i+1)/o)*o>>>5)-1]|=128,t.sigBytes=4*e.length,this._process();for(var s=this._state,a=this.cfg.outputLength/8,c=a/8,h=[],l=0;l<c;l++){var f=s[l],u=f.high,d=f.low;u=16711935&(u<<8|u>>>24)|4278255360&(u<<24|u>>>8),d=16711935&(d<<8|d>>>24)|4278255360&(d<<24|d>>>8),h.push(d),h.push(u)}return new n.init(h,a)},clone:function(){for(var t=o.clone.call(this),r=t._state=this._state.slice(0),e=0;e<25;e++)r[e]=r[e].clone();return t}});e.SHA3=o._createHelper(d),e.HmacSHA3=o._createHmacHelper(d)}(Math),function(){function r(){return s.create.apply(s,arguments)}var e=t,i=e.lib,n=i.Hasher,o=e.x64,s=o.Word,a=o.WordArray,c=e.algo,h=[r(1116352408,3609767458),r(1899447441,602891725),r(3049323471,3964484399),r(3921009573,2173295548),r(961987163,4081628472),r(1508970993,3053834265),r(2453635748,2937671579),r(2870763221,3664609560),r(3624381080,2734883394),r(310598401,1164996542),r(607225278,1323610764),r(1426881987,3590304994),r(1925078388,4068182383),r(2162078206,991336113),r(2614888103,633803317),r(3248222580,3479774868),r(3835390401,2666613458),r(4022224774,944711139),r(264347078,2341262773),r(604807628,2007800933),r(770255983,1495990901),r(1249150122,1856431235),r(1555081692,3175218132),r(1996064986,2198950837),r(2554220882,3999719339),r(2821834349,766784016),r(2952996808,2566594879),r(3210313671,3203337956),r(3336571891,1034457026),r(3584528711,2466948901),r(113926993,3758326383),r(338241895,168717936),r(666307205,1188179964),r(773529912,1546045734),r(1294757372,1522805485),r(1396182291,2643833823),r(1695183700,2343527390),r(1986661051,1014477480),r(2177026350,1206759142),r(2456956037,344077627),r(2730485921,1290863460),r(2820302411,3158454273),r(3259730800,3505952657),r(3345764771,106217008),r(3516065817,3606008344),r(3600352804,1432725776),r(4094571909,1467031594),r(275423344,851169720),r(430227734,3100823752),r(506948616,1363258195),r(659060556,3750685593),r(883997877,3785050280),r(958139571,3318307427),r(1322822218,3812723403),r(1537002063,2003034995),r(1747873779,3602036899),r(1955562222,1575990012),r(2024104815,1125592928),r(2227730452,2716904306),r(2361852424,442776044),r(2428436474,593698344),r(2756734187,3733110249),r(3204031479,2999351573),r(3329325298,3815920427),r(3391569614,3928383900),r(3515267271,566280711),r(3940187606,3454069534),r(4118630271,4000239992),r(116418474,1914138554),r(174292421,2731055270),r(289380356,3203993006),r(460393269,320620315),r(685471733,587496836),r(852142971,1086792851),r(1017036298,365543100),r(1126000580,2618297676),r(1288033470,3409855158),r(1501505948,4234509866),r(1607167915,987167468),r(1816402316,1246189591)],l=[];!function(){for(var t=0;t<80;t++)l[t]=r()}();var f=c.SHA512=n.extend({_doReset:function(){this._hash=new a.init([new s.init(1779033703,4089235720),new s.init(3144134277,2227873595),new s.init(1013904242,4271175723),new s.init(2773480762,1595750129),new s.init(1359893119,2917565137),new s.init(2600822924,725511199),new s.init(528734635,4215389547),new s.init(1541459225,327033209)])},_doProcessBlock:function(t,r){for(var e=this._hash.words,i=e[0],n=e[1],o=e[2],s=e[3],a=e[4],c=e[5],f=e[6],u=e[7],d=i.high,v=i.low,p=n.high,_=n.low,y=o.high,g=o.low,B=s.high,w=s.low,k=a.high,S=a.low,m=c.high,x=c.low,b=f.high,H=f.low,z=u.high,A=u.low,C=d,D=v,R=p,E=_,M=y,F=g,P=B,W=w,O=k,U=S,I=m,K=x,X=b,L=H,j=z,N=A,T=0;T<80;T++){var Z=l[T];if(T<16)var q=Z.high=0|t[r+2*T],G=Z.low=0|t[r+2*T+1];else{var J=l[T-15],$=J.high,Q=J.low,V=($>>>1|Q<<31)^($>>>8|Q<<24)^$>>>7,Y=(Q>>>1|$<<31)^(Q>>>8|$<<24)^(Q>>>7|$<<25),tt=l[T-2],rt=tt.high,et=tt.low,it=(rt>>>19|et<<13)^(rt<<3|et>>>29)^rt>>>6,nt=(et>>>19|rt<<13)^(et<<3|rt>>>29)^(et>>>6|rt<<26),ot=l[T-7],st=ot.high,at=ot.low,ct=l[T-16],ht=ct.high,lt=ct.low,G=Y+at,q=V+st+(G>>>0<Y>>>0?1:0),G=G+nt,q=q+it+(G>>>0<nt>>>0?1:0),G=G+lt,q=q+ht+(G>>>0<lt>>>0?1:0);Z.high=q,Z.low=G}var ft=O&I^~O&X,ut=U&K^~U&L,dt=C&R^C&M^R&M,vt=D&E^D&F^E&F,pt=(C>>>28|D<<4)^(C<<30|D>>>2)^(C<<25|D>>>7),_t=(D>>>28|C<<4)^(D<<30|C>>>2)^(D<<25|C>>>7),yt=(O>>>14|U<<18)^(O>>>18|U<<14)^(O<<23|U>>>9),gt=(U>>>14|O<<18)^(U>>>18|O<<14)^(U<<23|O>>>9),Bt=h[T],wt=Bt.high,kt=Bt.low,St=N+gt,mt=j+yt+(St>>>0<N>>>0?1:0),St=St+ut,mt=mt+ft+(St>>>0<ut>>>0?1:0),St=St+kt,mt=mt+wt+(St>>>0<kt>>>0?1:0),St=St+G,mt=mt+q+(St>>>0<G>>>0?1:0),xt=_t+vt,bt=pt+dt+(xt>>>0<_t>>>0?1:0);j=X,N=L,X=I,L=K,I=O,K=U,U=W+St|0,O=P+mt+(U>>>0<W>>>0?1:0)|0,P=M,W=F,M=R,F=E,R=C,E=D,D=St+xt|0,C=mt+bt+(D>>>0<St>>>0?1:0)|0}v=i.low=v+D,i.high=d+C+(v>>>0<D>>>0?1:0),_=n.low=_+E,n.high=p+R+(_>>>0<E>>>0?1:0),g=o.low=g+F,o.high=y+M+(g>>>0<F>>>0?1:0),w=s.low=w+W,s.high=B+P+(w>>>0<W>>>0?1:0),S=a.low=S+U,a.high=k+O+(S>>>0<U>>>0?1:0),x=c.low=x+K,c.high=m+I+(x>>>0<K>>>0?1:0),H=f.low=H+L,f.high=b+X+(H>>>0<L>>>0?1:0),A=u.low=A+N,u.high=z+j+(A>>>0<N>>>0?1:0)},_doFinalize:function(){var t=this._data,r=t.words,e=8*this._nDataBytes,i=8*t.sigBytes;r[i>>>5]|=128<<24-i%32,r[(i+128>>>10<<5)+30]=Math.floor(e/4294967296),r[(i+128>>>10<<5)+31]=e,t.sigBytes=4*r.length,this._process();var n=this._hash.toX32();return n},clone:function(){var t=n.clone.call(this);return t._hash=this._hash.clone(),t},blockSize:32});e.SHA512=n._createHelper(f),e.HmacSHA512=n._createHmacHelper(f)}(),function(){var r=t,e=r.x64,i=e.Word,n=e.WordArray,o=r.algo,s=o.SHA512,a=o.SHA384=s.extend({_doReset:function(){this._hash=new n.init([new i.init(3418070365,3238371032),new i.init(1654270250,914150663),new i.init(2438529370,812702999),new i.init(355462360,4144912697),new i.init(1731405415,4290775857),new i.init(2394180231,1750603025),new i.init(3675008525,1694076839),new i.init(1203062813,3204075428)])},_doFinalize:function(){var t=s._doFinalize.call(this);return t.sigBytes-=16,t}});r.SHA384=s._createHelper(a),r.HmacSHA384=s._createHmacHelper(a)}(),t.lib.Cipher||function(r){var e=t,i=e.lib,n=i.Base,o=i.WordArray,s=i.BufferedBlockAlgorithm,a=e.enc,c=(a.Utf8,a.Base64),h=e.algo,l=h.EvpKDF,f=i.Cipher=s.extend({cfg:n.extend(),createEncryptor:function(t,r){return this.create(this._ENC_XFORM_MODE,t,r)},createDecryptor:function(t,r){return this.create(this._DEC_XFORM_MODE,t,r)},init:function(t,r,e){this.cfg=this.cfg.extend(e),this._xformMode=t,this._key=r,this.reset()},reset:function(){s.reset.call(this),this._doReset()},process:function(t){return this._append(t),this._process()},finalize:function(t){t&&this._append(t);var r=this._doFinalize();return r},keySize:4,ivSize:4,_ENC_XFORM_MODE:1,_DEC_XFORM_MODE:2,_createHelper:function(){function t(t){return"string"==typeof t?m:w}return function(r){return{encrypt:function(e,i,n){return t(i).encrypt(r,e,i,n)},decrypt:function(e,i,n){return t(i).decrypt(r,e,i,n)}}}}()}),u=(i.StreamCipher=f.extend({_doFinalize:function(){var t=this._process(!0);return t},blockSize:1}),e.mode={}),d=i.BlockCipherMode=n.extend({createEncryptor:function(t,r){return this.Encryptor.create(t,r)},createDecryptor:function(t,r){return this.Decryptor.create(t,r)},init:function(t,r){this._cipher=t,this._iv=r}}),v=u.CBC=function(){function t(t,e,i){var n=this._iv;if(n){var o=n;this._iv=r}else var o=this._prevBlock;for(var s=0;s<i;s++)t[e+s]^=o[s]}var e=d.extend();return e.Encryptor=e.extend({processBlock:function(r,e){var i=this._cipher,n=i.blockSize;t.call(this,r,e,n),i.encryptBlock(r,e),this._prevBlock=r.slice(e,e+n)}}),e.Decryptor=e.extend({processBlock:function(r,e){var i=this._cipher,n=i.blockSize,o=r.slice(e,e+n);i.decryptBlock(r,e),t.call(this,r,e,n),this._prevBlock=o}}),e}(),p=e.pad={},_=p.Pkcs7={pad:function(t,r){for(var e=4*r,i=e-t.sigBytes%e,n=i<<24|i<<16|i<<8|i,s=[],a=0;a<i;a+=4)s.push(n);var c=o.create(s,i);t.concat(c)},unpad:function(t){var r=255&t.words[t.sigBytes-1>>>2];t.sigBytes-=r}},y=(i.BlockCipher=f.extend({cfg:f.cfg.extend({mode:v,padding:_}),reset:function(){f.reset.call(this);var t=this.cfg,r=t.iv,e=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var i=e.createEncryptor;else{var i=e.createDecryptor;this._minBufferSize=1}this._mode&&this._mode.__creator==i?this._mode.init(this,r&&r.words):(this._mode=i.call(e,this,r&&r.words),this._mode.__creator=i)},_doProcessBlock:function(t,r){this._mode.processBlock(t,r)},_doFinalize:function(){var t=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){t.pad(this._data,this.blockSize);var r=this._process(!0)}else{var r=this._process(!0);t.unpad(r)}return r},blockSize:4}),i.CipherParams=n.extend({init:function(t){this.mixIn(t)},toString:function(t){return(t||this.formatter).stringify(this)}})),g=e.format={},B=g.OpenSSL={stringify:function(t){var r=t.ciphertext,e=t.salt;if(e)var i=o.create([1398893684,1701076831]).concat(e).concat(r);else var i=r;return i.toString(c)},parse:function(t){var r=c.parse(t),e=r.words;if(1398893684==e[0]&&1701076831==e[1]){var i=o.create(e.slice(2,4));e.splice(0,4),r.sigBytes-=16}return y.create({ciphertext:r,salt:i})}},w=i.SerializableCipher=n.extend({cfg:n.extend({format:B}),encrypt:function(t,r,e,i){i=this.cfg.extend(i);var n=t.createEncryptor(e,i),o=n.finalize(r),s=n.cfg;return y.create({ciphertext:o,key:e,iv:s.iv,algorithm:t,mode:s.mode,padding:s.padding,blockSize:t.blockSize,formatter:i.format})},decrypt:function(t,r,e,i){i=this.cfg.extend(i),r=this._parse(r,i.format);var n=t.createDecryptor(e,i).finalize(r.ciphertext);return n},_parse:function(t,r){return"string"==typeof t?r.parse(t,this):t}}),k=e.kdf={},S=k.OpenSSL={execute:function(t,r,e,i){i||(i=o.random(8));var n=l.create({keySize:r+e}).compute(t,i),s=o.create(n.words.slice(r),4*e);return n.sigBytes=4*r,y.create({key:n,iv:s,salt:i})}},m=i.PasswordBasedCipher=w.extend({cfg:w.cfg.extend({kdf:S}),encrypt:function(t,r,e,i){i=this.cfg.extend(i);var n=i.kdf.execute(e,t.keySize,t.ivSize);i.iv=n.iv;var o=w.encrypt.call(this,t,r,n.key,i);return o.mixIn(n),o},decrypt:function(t,r,e,i){i=this.cfg.extend(i),r=this._parse(r,i.format);var n=i.kdf.execute(e,t.keySize,t.ivSize,r.salt);i.iv=n.iv;var o=w.decrypt.call(this,t,r,n.key,i);return o}})}(),t.mode.CFB=function(){function r(t,r,e,i){var n=this._iv;if(n){var o=n.slice(0);this._iv=void 0}else var o=this._prevBlock;i.encryptBlock(o,0);for(var s=0;s<e;s++)t[r+s]^=o[s]}var e=t.lib.BlockCipherMode.extend();return e.Encryptor=e.extend({processBlock:function(t,e){var i=this._cipher,n=i.blockSize;r.call(this,t,e,n,i),this._prevBlock=t.slice(e,e+n)}}),e.Decryptor=e.extend({processBlock:function(t,e){var i=this._cipher,n=i.blockSize,o=t.slice(e,e+n);r.call(this,t,e,n,i),this._prevBlock=o}}),e}(),t.mode.ECB=function(){var r=t.lib.BlockCipherMode.extend();return r.Encryptor=r.extend({processBlock:function(t,r){this._cipher.encryptBlock(t,r)}}),r.Decryptor=r.extend({processBlock:function(t,r){this._cipher.decryptBlock(t,r)}}),r}(),t.pad.AnsiX923={pad:function(t,r){var e=t.sigBytes,i=4*r,n=i-e%i,o=e+n-1;t.clamp(),t.words[o>>>2]|=n<<24-o%4*8,t.sigBytes+=n},unpad:function(t){var r=255&t.words[t.sigBytes-1>>>2];t.sigBytes-=r}},t.pad.Iso10126={pad:function(r,e){var i=4*e,n=i-r.sigBytes%i;r.concat(t.lib.WordArray.random(n-1)).concat(t.lib.WordArray.create([n<<24],1))},unpad:function(t){var r=255&t.words[t.sigBytes-1>>>2];t.sigBytes-=r}},t.pad.Iso97971={pad:function(r,e){r.concat(t.lib.WordArray.create([2147483648],1)),t.pad.ZeroPadding.pad(r,e)},unpad:function(r){t.pad.ZeroPadding.unpad(r),r.sigBytes--}},t.mode.OFB=function(){var r=t.lib.BlockCipherMode.extend(),e=r.Encryptor=r.extend({processBlock:function(t,r){var e=this._cipher,i=e.blockSize,n=this._iv,o=this._keystream;n&&(o=this._keystream=n.slice(0),this._iv=void 0),e.encryptBlock(o,0);for(var s=0;s<i;s++)t[r+s]^=o[s]}});return r.Decryptor=e,r}(),t.pad.NoPadding={pad:function(){},unpad:function(){}},function(r){var e=t,i=e.lib,n=i.CipherParams,o=e.enc,s=o.Hex,a=e.format;a.Hex={stringify:function(t){return t.ciphertext.toString(s)},parse:function(t){var r=s.parse(t);return n.create({ciphertext:r})}}}(),function(){var r=t,e=r.lib,i=e.BlockCipher,n=r.algo,o=[],s=[],a=[],c=[],h=[],l=[],f=[],u=[],d=[],v=[];!function(){for(var t=[],r=0;r<256;r++)r<128?t[r]=r<<1:t[r]=r<<1^283;for(var e=0,i=0,r=0;r<256;r++){var n=i^i<<1^i<<2^i<<3^i<<4;n=n>>>8^255&n^99,o[e]=n,s[n]=e;var p=t[e],_=t[p],y=t[_],g=257*t[n]^16843008*n;a[e]=g<<24|g>>>8,c[e]=g<<16|g>>>16,h[e]=g<<8|g>>>24,l[e]=g;var g=16843009*y^65537*_^257*p^16843008*e;f[n]=g<<24|g>>>8,u[n]=g<<16|g>>>16,d[n]=g<<8|g>>>24,v[n]=g,e?(e=p^t[t[t[y^p]]],i^=t[t[i]]):e=i=1}}();var p=[0,1,2,4,8,16,32,64,128,27,54],_=n.AES=i.extend({_doReset:function(){if(!this._nRounds||this._keyPriorReset!==this._key){for(var t=this._keyPriorReset=this._key,r=t.words,e=t.sigBytes/4,i=this._nRounds=e+6,n=4*(i+1),s=this._keySchedule=[],a=0;a<n;a++)if(a<e)s[a]=r[a];else{var c=s[a-1];a%e?e>6&&a%e==4&&(c=o[c>>>24]<<24|o[c>>>16&255]<<16|o[c>>>8&255]<<8|o[255&c]):(c=c<<8|c>>>24,c=o[c>>>24]<<24|o[c>>>16&255]<<16|o[c>>>8&255]<<8|o[255&c],c^=p[a/e|0]<<24),s[a]=s[a-e]^c}for(var h=this._invKeySchedule=[],l=0;l<n;l++){var a=n-l;if(l%4)var c=s[a];else var c=s[a-4];l<4||a<=4?h[l]=c:h[l]=f[o[c>>>24]]^u[o[c>>>16&255]]^d[o[c>>>8&255]]^v[o[255&c]]}}},encryptBlock:function(t,r){this._doCryptBlock(t,r,this._keySchedule,a,c,h,l,o)},decryptBlock:function(t,r){var e=t[r+1];t[r+1]=t[r+3],t[r+3]=e,this._doCryptBlock(t,r,this._invKeySchedule,f,u,d,v,s);var e=t[r+1];t[r+1]=t[r+3],t[r+3]=e},_doCryptBlock:function(t,r,e,i,n,o,s,a){for(var c=this._nRounds,h=t[r]^e[0],l=t[r+1]^e[1],f=t[r+2]^e[2],u=t[r+3]^e[3],d=4,v=1;v<c;v++){var p=i[h>>>24]^n[l>>>16&255]^o[f>>>8&255]^s[255&u]^e[d++],_=i[l>>>24]^n[f>>>16&255]^o[u>>>8&255]^s[255&h]^e[d++],y=i[f>>>24]^n[u>>>16&255]^o[h>>>8&255]^s[255&l]^e[d++],g=i[u>>>24]^n[h>>>16&255]^o[l>>>8&255]^s[255&f]^e[d++];h=p,l=_,f=y,u=g}var p=(a[h>>>24]<<24|a[l>>>16&255]<<16|a[f>>>8&255]<<8|a[255&u])^e[d++],_=(a[l>>>24]<<24|a[f>>>16&255]<<16|a[u>>>8&255]<<8|a[255&h])^e[d++],y=(a[f>>>24]<<24|a[u>>>16&255]<<16|a[h>>>8&255]<<8|a[255&l])^e[d++],g=(a[u>>>24]<<24|a[h>>>16&255]<<16|a[l>>>8&255]<<8|a[255&f])^e[d++];t[r]=p,t[r+1]=_,t[r+2]=y,t[r+3]=g},keySize:8});r.AES=i._createHelper(_)}(),function(){function r(t,r){var e=(this._lBlock>>>t^this._rBlock)&r;this._rBlock^=e,this._lBlock^=e<<t}function e(t,r){var e=(this._rBlock>>>t^this._lBlock)&r;this._lBlock^=e,this._rBlock^=e<<t;
  2. }var i=t,n=i.lib,o=n.WordArray,s=n.BlockCipher,a=i.algo,c=[57,49,41,33,25,17,9,1,58,50,42,34,26,18,10,2,59,51,43,35,27,19,11,3,60,52,44,36,63,55,47,39,31,23,15,7,62,54,46,38,30,22,14,6,61,53,45,37,29,21,13,5,28,20,12,4],h=[14,17,11,24,1,5,3,28,15,6,21,10,23,19,12,4,26,8,16,7,27,20,13,2,41,52,31,37,47,55,30,40,51,45,33,48,44,49,39,56,34,53,46,42,50,36,29,32],l=[1,2,4,6,8,10,12,14,15,17,19,21,23,25,27,28],f=[{0:8421888,268435456:32768,536870912:8421378,805306368:2,1073741824:512,1342177280:8421890,1610612736:8389122,1879048192:8388608,2147483648:514,2415919104:8389120,2684354560:33280,2952790016:8421376,3221225472:32770,3489660928:8388610,3758096384:0,4026531840:33282,134217728:0,402653184:8421890,671088640:33282,939524096:32768,1207959552:8421888,1476395008:512,1744830464:8421378,2013265920:2,2281701376:8389120,2550136832:33280,2818572288:8421376,3087007744:8389122,3355443200:8388610,3623878656:32770,3892314112:514,4160749568:8388608,1:32768,268435457:2,536870913:8421888,805306369:8388608,1073741825:8421378,1342177281:33280,1610612737:512,1879048193:8389122,2147483649:8421890,2415919105:8421376,2684354561:8388610,2952790017:33282,3221225473:514,3489660929:8389120,3758096385:32770,4026531841:0,134217729:8421890,402653185:8421376,671088641:8388608,939524097:512,1207959553:32768,1476395009:8388610,1744830465:2,2013265921:33282,2281701377:32770,2550136833:8389122,2818572289:514,3087007745:8421888,3355443201:8389120,3623878657:0,3892314113:33280,4160749569:8421378},{0:1074282512,16777216:16384,33554432:524288,50331648:1074266128,67108864:1073741840,83886080:1074282496,100663296:1073758208,117440512:16,134217728:540672,150994944:1073758224,167772160:1073741824,184549376:540688,201326592:524304,218103808:0,234881024:16400,251658240:1074266112,8388608:1073758208,25165824:540688,41943040:16,58720256:1073758224,75497472:1074282512,92274688:1073741824,109051904:524288,125829120:1074266128,142606336:524304,159383552:0,176160768:16384,192937984:1074266112,209715200:1073741840,226492416:540672,243269632:1074282496,260046848:16400,268435456:0,285212672:1074266128,301989888:1073758224,318767104:1074282496,335544320:1074266112,352321536:16,369098752:540688,385875968:16384,402653184:16400,419430400:524288,436207616:524304,452984832:1073741840,469762048:540672,486539264:1073758208,503316480:1073741824,520093696:1074282512,276824064:540688,293601280:524288,310378496:1074266112,327155712:16384,343932928:1073758208,360710144:1074282512,377487360:16,394264576:1073741824,411041792:1074282496,427819008:1073741840,444596224:1073758224,461373440:524304,478150656:0,494927872:16400,511705088:1074266128,528482304:540672},{0:260,1048576:0,2097152:67109120,3145728:65796,4194304:65540,5242880:67108868,6291456:67174660,7340032:67174400,8388608:67108864,9437184:67174656,10485760:65792,11534336:67174404,12582912:67109124,13631488:65536,14680064:4,15728640:256,524288:67174656,1572864:67174404,2621440:0,3670016:67109120,4718592:67108868,5767168:65536,6815744:65540,7864320:260,8912896:4,9961472:256,11010048:67174400,12058624:65796,13107200:65792,14155776:67109124,15204352:67174660,16252928:67108864,16777216:67174656,17825792:65540,18874368:65536,19922944:67109120,20971520:256,22020096:67174660,23068672:67108868,24117248:0,25165824:67109124,26214400:67108864,27262976:4,28311552:65792,29360128:67174400,30408704:260,31457280:65796,32505856:67174404,17301504:67108864,18350080:260,19398656:67174656,20447232:0,21495808:65540,22544384:67109120,23592960:256,24641536:67174404,25690112:65536,26738688:67174660,27787264:65796,28835840:67108868,29884416:67109124,30932992:67174400,31981568:4,33030144:65792},{0:2151682048,65536:2147487808,131072:4198464,196608:2151677952,262144:0,327680:4198400,393216:2147483712,458752:4194368,524288:2147483648,589824:4194304,655360:64,720896:2147487744,786432:2151678016,851968:4160,917504:4096,983040:2151682112,32768:2147487808,98304:64,163840:2151678016,229376:2147487744,294912:4198400,360448:2151682112,425984:0,491520:2151677952,557056:4096,622592:2151682048,688128:4194304,753664:4160,819200:2147483648,884736:4194368,950272:4198464,1015808:2147483712,1048576:4194368,1114112:4198400,1179648:2147483712,1245184:0,1310720:4160,1376256:2151678016,1441792:2151682048,1507328:2147487808,1572864:2151682112,1638400:2147483648,1703936:2151677952,1769472:4198464,1835008:2147487744,1900544:4194304,1966080:64,2031616:4096,1081344:2151677952,1146880:2151682112,1212416:0,1277952:4198400,1343488:4194368,1409024:2147483648,1474560:2147487808,1540096:64,1605632:2147483712,1671168:4096,1736704:2147487744,1802240:2151678016,1867776:4160,1933312:2151682048,1998848:4194304,2064384:4198464},{0:128,4096:17039360,8192:262144,12288:536870912,16384:537133184,20480:16777344,24576:553648256,28672:262272,32768:16777216,36864:537133056,40960:536871040,45056:553910400,49152:553910272,53248:0,57344:17039488,61440:553648128,2048:17039488,6144:553648256,10240:128,14336:17039360,18432:262144,22528:537133184,26624:553910272,30720:536870912,34816:537133056,38912:0,43008:553910400,47104:16777344,51200:536871040,55296:553648128,59392:16777216,63488:262272,65536:262144,69632:128,73728:536870912,77824:553648256,81920:16777344,86016:553910272,90112:537133184,94208:16777216,98304:553910400,102400:553648128,106496:17039360,110592:537133056,114688:262272,118784:536871040,122880:0,126976:17039488,67584:553648256,71680:16777216,75776:17039360,79872:537133184,83968:536870912,88064:17039488,92160:128,96256:553910272,100352:262272,104448:553910400,108544:0,112640:553648128,116736:16777344,120832:262144,124928:537133056,129024:536871040},{0:268435464,256:8192,512:270532608,768:270540808,1024:268443648,1280:2097152,1536:2097160,1792:268435456,2048:0,2304:268443656,2560:2105344,2816:8,3072:270532616,3328:2105352,3584:8200,3840:270540800,128:270532608,384:270540808,640:8,896:2097152,1152:2105352,1408:268435464,1664:268443648,1920:8200,2176:2097160,2432:8192,2688:268443656,2944:270532616,3200:0,3456:270540800,3712:2105344,3968:268435456,4096:268443648,4352:270532616,4608:270540808,4864:8200,5120:2097152,5376:268435456,5632:268435464,5888:2105344,6144:2105352,6400:0,6656:8,6912:270532608,7168:8192,7424:268443656,7680:270540800,7936:2097160,4224:8,4480:2105344,4736:2097152,4992:268435464,5248:268443648,5504:8200,5760:270540808,6016:270532608,6272:270540800,6528:270532616,6784:8192,7040:2105352,7296:2097160,7552:0,7808:268435456,8064:268443656},{0:1048576,16:33555457,32:1024,48:1049601,64:34604033,80:0,96:1,112:34603009,128:33555456,144:1048577,160:33554433,176:34604032,192:34603008,208:1025,224:1049600,240:33554432,8:34603009,24:0,40:33555457,56:34604032,72:1048576,88:33554433,104:33554432,120:1025,136:1049601,152:33555456,168:34603008,184:1048577,200:1024,216:34604033,232:1,248:1049600,256:33554432,272:1048576,288:33555457,304:34603009,320:1048577,336:33555456,352:34604032,368:1049601,384:1025,400:34604033,416:1049600,432:1,448:0,464:34603008,480:33554433,496:1024,264:1049600,280:33555457,296:34603009,312:1,328:33554432,344:1048576,360:1025,376:34604032,392:33554433,408:34603008,424:0,440:34604033,456:1049601,472:1024,488:33555456,504:1048577},{0:134219808,1:131072,2:134217728,3:32,4:131104,5:134350880,6:134350848,7:2048,8:134348800,9:134219776,10:133120,11:134348832,12:2080,13:0,14:134217760,15:133152,2147483648:2048,2147483649:134350880,2147483650:134219808,2147483651:134217728,2147483652:134348800,2147483653:133120,2147483654:133152,2147483655:32,2147483656:134217760,2147483657:2080,2147483658:131104,2147483659:134350848,2147483660:0,2147483661:134348832,2147483662:134219776,2147483663:131072,16:133152,17:134350848,18:32,19:2048,20:134219776,21:134217760,22:134348832,23:131072,24:0,25:131104,26:134348800,27:134219808,28:134350880,29:133120,30:2080,31:134217728,2147483664:131072,2147483665:2048,2147483666:134348832,2147483667:133152,2147483668:32,2147483669:134348800,2147483670:134217728,2147483671:134219808,2147483672:134350880,2147483673:134217760,2147483674:134219776,2147483675:0,2147483676:133120,2147483677:2080,2147483678:131104,2147483679:134350848}],u=[4160749569,528482304,33030144,2064384,129024,8064,504,2147483679],d=a.DES=s.extend({_doReset:function(){for(var t=this._key,r=t.words,e=[],i=0;i<56;i++){var n=c[i]-1;e[i]=r[n>>>5]>>>31-n%32&1}for(var o=this._subKeys=[],s=0;s<16;s++){for(var a=o[s]=[],f=l[s],i=0;i<24;i++)a[i/6|0]|=e[(h[i]-1+f)%28]<<31-i%6,a[4+(i/6|0)]|=e[28+(h[i+24]-1+f)%28]<<31-i%6;a[0]=a[0]<<1|a[0]>>>31;for(var i=1;i<7;i++)a[i]=a[i]>>>4*(i-1)+3;a[7]=a[7]<<5|a[7]>>>27}for(var u=this._invSubKeys=[],i=0;i<16;i++)u[i]=o[15-i]},encryptBlock:function(t,r){this._doCryptBlock(t,r,this._subKeys)},decryptBlock:function(t,r){this._doCryptBlock(t,r,this._invSubKeys)},_doCryptBlock:function(t,i,n){this._lBlock=t[i],this._rBlock=t[i+1],r.call(this,4,252645135),r.call(this,16,65535),e.call(this,2,858993459),e.call(this,8,16711935),r.call(this,1,1431655765);for(var o=0;o<16;o++){for(var s=n[o],a=this._lBlock,c=this._rBlock,h=0,l=0;l<8;l++)h|=f[l][((c^s[l])&u[l])>>>0];this._lBlock=c,this._rBlock=a^h}var d=this._lBlock;this._lBlock=this._rBlock,this._rBlock=d,r.call(this,1,1431655765),e.call(this,8,16711935),e.call(this,2,858993459),r.call(this,16,65535),r.call(this,4,252645135),t[i]=this._lBlock,t[i+1]=this._rBlock},keySize:2,ivSize:2,blockSize:2});i.DES=s._createHelper(d);var v=a.TripleDES=s.extend({_doReset:function(){var t=this._key,r=t.words;this._des1=d.createEncryptor(o.create(r.slice(0,2))),this._des2=d.createEncryptor(o.create(r.slice(2,4))),this._des3=d.createEncryptor(o.create(r.slice(4,6)))},encryptBlock:function(t,r){this._des1.encryptBlock(t,r),this._des2.decryptBlock(t,r),this._des3.encryptBlock(t,r)},decryptBlock:function(t,r){this._des3.decryptBlock(t,r),this._des2.encryptBlock(t,r),this._des1.decryptBlock(t,r)},keySize:6,ivSize:2,blockSize:2});i.TripleDES=s._createHelper(v)}(),function(){function r(){for(var t=this._S,r=this._i,e=this._j,i=0,n=0;n<4;n++){r=(r+1)%256,e=(e+t[r])%256;var o=t[r];t[r]=t[e],t[e]=o,i|=t[(t[r]+t[e])%256]<<24-8*n}return this._i=r,this._j=e,i}var e=t,i=e.lib,n=i.StreamCipher,o=e.algo,s=o.RC4=n.extend({_doReset:function(){for(var t=this._key,r=t.words,e=t.sigBytes,i=this._S=[],n=0;n<256;n++)i[n]=n;for(var n=0,o=0;n<256;n++){var s=n%e,a=r[s>>>2]>>>24-s%4*8&255;o=(o+i[n]+a)%256;var c=i[n];i[n]=i[o],i[o]=c}this._i=this._j=0},_doProcessBlock:function(t,e){t[e]^=r.call(this)},keySize:8,ivSize:0});e.RC4=n._createHelper(s);var a=o.RC4Drop=s.extend({cfg:s.cfg.extend({drop:192}),_doReset:function(){s._doReset.call(this);for(var t=this.cfg.drop;t>0;t--)r.call(this)}});e.RC4Drop=n._createHelper(a)}(),t.mode.CTRGladman=function(){function r(t){if(255===(t>>24&255)){var r=t>>16&255,e=t>>8&255,i=255&t;255===r?(r=0,255===e?(e=0,255===i?i=0:++i):++e):++r,t=0,t+=r<<16,t+=e<<8,t+=i}else t+=1<<24;return t}function e(t){return 0===(t[0]=r(t[0]))&&(t[1]=r(t[1])),t}var i=t.lib.BlockCipherMode.extend(),n=i.Encryptor=i.extend({processBlock:function(t,r){var i=this._cipher,n=i.blockSize,o=this._iv,s=this._counter;o&&(s=this._counter=o.slice(0),this._iv=void 0),e(s);var a=s.slice(0);i.encryptBlock(a,0);for(var c=0;c<n;c++)t[r+c]^=a[c]}});return i.Decryptor=n,i}(),function(){function r(){for(var t=this._X,r=this._C,e=0;e<8;e++)a[e]=r[e];r[0]=r[0]+1295307597+this._b|0,r[1]=r[1]+3545052371+(r[0]>>>0<a[0]>>>0?1:0)|0,r[2]=r[2]+886263092+(r[1]>>>0<a[1]>>>0?1:0)|0,r[3]=r[3]+1295307597+(r[2]>>>0<a[2]>>>0?1:0)|0,r[4]=r[4]+3545052371+(r[3]>>>0<a[3]>>>0?1:0)|0,r[5]=r[5]+886263092+(r[4]>>>0<a[4]>>>0?1:0)|0,r[6]=r[6]+1295307597+(r[5]>>>0<a[5]>>>0?1:0)|0,r[7]=r[7]+3545052371+(r[6]>>>0<a[6]>>>0?1:0)|0,this._b=r[7]>>>0<a[7]>>>0?1:0;for(var e=0;e<8;e++){var i=t[e]+r[e],n=65535&i,o=i>>>16,s=((n*n>>>17)+n*o>>>15)+o*o,h=((4294901760&i)*i|0)+((65535&i)*i|0);c[e]=s^h}t[0]=c[0]+(c[7]<<16|c[7]>>>16)+(c[6]<<16|c[6]>>>16)|0,t[1]=c[1]+(c[0]<<8|c[0]>>>24)+c[7]|0,t[2]=c[2]+(c[1]<<16|c[1]>>>16)+(c[0]<<16|c[0]>>>16)|0,t[3]=c[3]+(c[2]<<8|c[2]>>>24)+c[1]|0,t[4]=c[4]+(c[3]<<16|c[3]>>>16)+(c[2]<<16|c[2]>>>16)|0,t[5]=c[5]+(c[4]<<8|c[4]>>>24)+c[3]|0,t[6]=c[6]+(c[5]<<16|c[5]>>>16)+(c[4]<<16|c[4]>>>16)|0,t[7]=c[7]+(c[6]<<8|c[6]>>>24)+c[5]|0}var e=t,i=e.lib,n=i.StreamCipher,o=e.algo,s=[],a=[],c=[],h=o.Rabbit=n.extend({_doReset:function(){for(var t=this._key.words,e=this.cfg.iv,i=0;i<4;i++)t[i]=16711935&(t[i]<<8|t[i]>>>24)|4278255360&(t[i]<<24|t[i]>>>8);var n=this._X=[t[0],t[3]<<16|t[2]>>>16,t[1],t[0]<<16|t[3]>>>16,t[2],t[1]<<16|t[0]>>>16,t[3],t[2]<<16|t[1]>>>16],o=this._C=[t[2]<<16|t[2]>>>16,4294901760&t[0]|65535&t[1],t[3]<<16|t[3]>>>16,4294901760&t[1]|65535&t[2],t[0]<<16|t[0]>>>16,4294901760&t[2]|65535&t[3],t[1]<<16|t[1]>>>16,4294901760&t[3]|65535&t[0]];this._b=0;for(var i=0;i<4;i++)r.call(this);for(var i=0;i<8;i++)o[i]^=n[i+4&7];if(e){var s=e.words,a=s[0],c=s[1],h=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8),l=16711935&(c<<8|c>>>24)|4278255360&(c<<24|c>>>8),f=h>>>16|4294901760&l,u=l<<16|65535&h;o[0]^=h,o[1]^=f,o[2]^=l,o[3]^=u,o[4]^=h,o[5]^=f,o[6]^=l,o[7]^=u;for(var i=0;i<4;i++)r.call(this)}},_doProcessBlock:function(t,e){var i=this._X;r.call(this),s[0]=i[0]^i[5]>>>16^i[3]<<16,s[1]=i[2]^i[7]>>>16^i[5]<<16,s[2]=i[4]^i[1]>>>16^i[7]<<16,s[3]=i[6]^i[3]>>>16^i[1]<<16;for(var n=0;n<4;n++)s[n]=16711935&(s[n]<<8|s[n]>>>24)|4278255360&(s[n]<<24|s[n]>>>8),t[e+n]^=s[n]},blockSize:4,ivSize:2});e.Rabbit=n._createHelper(h)}(),t.mode.CTR=function(){var r=t.lib.BlockCipherMode.extend(),e=r.Encryptor=r.extend({processBlock:function(t,r){var e=this._cipher,i=e.blockSize,n=this._iv,o=this._counter;n&&(o=this._counter=n.slice(0),this._iv=void 0);var s=o.slice(0);e.encryptBlock(s,0),o[i-1]=o[i-1]+1|0;for(var a=0;a<i;a++)t[r+a]^=s[a]}});return r.Decryptor=e,r}(),function(){function r(){for(var t=this._X,r=this._C,e=0;e<8;e++)a[e]=r[e];r[0]=r[0]+1295307597+this._b|0,r[1]=r[1]+3545052371+(r[0]>>>0<a[0]>>>0?1:0)|0,r[2]=r[2]+886263092+(r[1]>>>0<a[1]>>>0?1:0)|0,r[3]=r[3]+1295307597+(r[2]>>>0<a[2]>>>0?1:0)|0,r[4]=r[4]+3545052371+(r[3]>>>0<a[3]>>>0?1:0)|0,r[5]=r[5]+886263092+(r[4]>>>0<a[4]>>>0?1:0)|0,r[6]=r[6]+1295307597+(r[5]>>>0<a[5]>>>0?1:0)|0,r[7]=r[7]+3545052371+(r[6]>>>0<a[6]>>>0?1:0)|0,this._b=r[7]>>>0<a[7]>>>0?1:0;for(var e=0;e<8;e++){var i=t[e]+r[e],n=65535&i,o=i>>>16,s=((n*n>>>17)+n*o>>>15)+o*o,h=((4294901760&i)*i|0)+((65535&i)*i|0);c[e]=s^h}t[0]=c[0]+(c[7]<<16|c[7]>>>16)+(c[6]<<16|c[6]>>>16)|0,t[1]=c[1]+(c[0]<<8|c[0]>>>24)+c[7]|0,t[2]=c[2]+(c[1]<<16|c[1]>>>16)+(c[0]<<16|c[0]>>>16)|0,t[3]=c[3]+(c[2]<<8|c[2]>>>24)+c[1]|0,t[4]=c[4]+(c[3]<<16|c[3]>>>16)+(c[2]<<16|c[2]>>>16)|0,t[5]=c[5]+(c[4]<<8|c[4]>>>24)+c[3]|0,t[6]=c[6]+(c[5]<<16|c[5]>>>16)+(c[4]<<16|c[4]>>>16)|0,t[7]=c[7]+(c[6]<<8|c[6]>>>24)+c[5]|0}var e=t,i=e.lib,n=i.StreamCipher,o=e.algo,s=[],a=[],c=[],h=o.RabbitLegacy=n.extend({_doReset:function(){var t=this._key.words,e=this.cfg.iv,i=this._X=[t[0],t[3]<<16|t[2]>>>16,t[1],t[0]<<16|t[3]>>>16,t[2],t[1]<<16|t[0]>>>16,t[3],t[2]<<16|t[1]>>>16],n=this._C=[t[2]<<16|t[2]>>>16,4294901760&t[0]|65535&t[1],t[3]<<16|t[3]>>>16,4294901760&t[1]|65535&t[2],t[0]<<16|t[0]>>>16,4294901760&t[2]|65535&t[3],t[1]<<16|t[1]>>>16,4294901760&t[3]|65535&t[0]];this._b=0;for(var o=0;o<4;o++)r.call(this);for(var o=0;o<8;o++)n[o]^=i[o+4&7];if(e){var s=e.words,a=s[0],c=s[1],h=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8),l=16711935&(c<<8|c>>>24)|4278255360&(c<<24|c>>>8),f=h>>>16|4294901760&l,u=l<<16|65535&h;n[0]^=h,n[1]^=f,n[2]^=l,n[3]^=u,n[4]^=h,n[5]^=f,n[6]^=l,n[7]^=u;for(var o=0;o<4;o++)r.call(this)}},_doProcessBlock:function(t,e){var i=this._X;r.call(this),s[0]=i[0]^i[5]>>>16^i[3]<<16,s[1]=i[2]^i[7]>>>16^i[5]<<16,s[2]=i[4]^i[1]>>>16^i[7]<<16,s[3]=i[6]^i[3]>>>16^i[1]<<16;for(var n=0;n<4;n++)s[n]=16711935&(s[n]<<8|s[n]>>>24)|4278255360&(s[n]<<24|s[n]>>>8),t[e+n]^=s[n]},blockSize:4,ivSize:2});e.RabbitLegacy=n._createHelper(h)}(),t.pad.ZeroPadding={pad:function(t,r){var e=4*r;t.clamp(),t.sigBytes+=e-(t.sigBytes%e||e)},unpad:function(t){for(var r=t.words,e=t.sigBytes-1;!(r[e>>>2]>>>24-e%4*8&255);)e--;t.sigBytes=e+1}},t});
  3. //# sourceMappingURL=crypto-js.min.js.map

页面先引入crypto-js.js在引入sm2.js

html页面

  1. //提交表单时先获取公钥对需要加密的字符串加密然后提交到后台
  2. //从后台获取公钥
  3. $.ajax.get({
  4. url: '${contextPath}/api/tools/v_sm2',
  5. success: function (result) {
  6. if (result.stat == 1) {
  7. //公钥
  8. var py = result.data.py;
  9. //加密
  10. var encryptData = sm2Encrypt($('#userpass').val(), py, 0);
  11. //var userpass = hex_md5($('#userpass').val());
  12.  
  13. $('#userpass').val(encryptData);
  14. WinAjax.ajaxSubmit({
  15. form : $("#loginForm"),
  16. success: function (result) { //提交成功的回调函数
  17. if (result.stat == 0) {
  18. slider.reset();
  19. layer.msg(result.msg);
  20. $('#tip_msg').html(result.msg);
  21. $(".kaptcha_img").click();
  22. $('#userpass').val('');
  23. } else {
  24. layer.msg('登录成功');
  25. window.location.href = '${contextPath}/home';
  26. }
  27. }
  28. });
  29. }else {
  30. layer.msg(result.msg);
  31. }
  32. }
  33. });
  34. }
  35. })

提交到后台之后对需要解密的字符串调用 Sm2Utils.decrypt();传入加密字符串和私钥;公钥和私用调用Sm2Utils.genPUPRkey()方法获取

  1.  

sm2加密的更多相关文章

  1. Java BC包做sm2加密方法 ,签名验签方法

    package com.sdyy.common.bc_sm2; import org.bouncycastle.jcajce.provider.asymmetric.x509.CertificateF ...

  2. 对于如何从SM2的pfx证书文件中解析公钥和私钥,并从二次加密的密文中解密

    首先呢,由于我的域名之前处理点问题,然后备案第二个网站时候,第一个网站没法访问,所以备案没过,阿里云告诉我要删除一个网站的备案,但是他没告诉我要删除主体,所以我的备案主体成了空壳主体,要传真或者发快递 ...

  3. 20155206赵飞 基于《Arm试验箱的国密算法应用》课程设计个人报告

    20155206赵飞 基于<Arm试验箱的国密算法应用>课程设计个人报告 课程设计中承担的任务 完成试验箱测试功能1,2,3 . 1:LED闪烁实验 一.实验目的  学习GPIO原理  ...

  4. 《基于Arm实验箱的国密算法应用》课程设计 结题报告

    <基于Arm实验箱的国密算法应用>课程设计 结题报告 小组成员姓名:20155206赵飞 20155220吴思其 20155234昝昕明 指导教师:娄嘉鹏 设计方案 题目要求:基于Arm实 ...

  5. Java国密相关算法(bouncycastle)

    公用类算法: PCIKeyPair.java /** * @Author: dzy * @Date: 2018/9/27 14:18 * @Describe: 公私钥对 */ @Data @AllAr ...

  6. 部署国密SSL证书,如何兼容国际主流浏览器?

    国密算法在主流操作系统.浏览器等客户端中,还没有实现广泛兼容.因此,在面向开放互联网的产品应用中,国密算法无法得到广泛应用.比如,在SSL证书应用领域,由于国际主流浏览器不信任国密算法,如果服务器部署 ...

  7. SM 国密算法踩坑指南

    各位,好久不见~ 最近接手网联的国密改造项目,由于对国密算法比较陌生,前期碰到了一系列国密算法加解密的问题. 所以这次总结一下,分享这个过程遇到的问题,希望帮到大家. 国密 什么是国密算法? 国密就是 ...

  8. C#实现SM2国密加密

    本文主要讲解"国密加密算法"SM系列的C#实现方法,不涉及具体的算法剖析,在网络上找到的java实现方法比较少,切在跨语言加密解密上会存在一些问题,所以整理此文志之.JAVA实现参 ...

  9. 制作SM2证书

    前段时间将系统的RSA算法全部升级为SM2国密算法,密码机和UKey硬件设备大都同时支持RSA和SM2算法,只是应用系统的加解密签名验证需要修改,这个更改底层调用的加密动态库来,原来RSA用的对称加密 ...

随机推荐

  1. django对layui中csrf_token处理方式及其它一些处理

    第一:由于layui官方是没有csrf_token处理机制,所以,在使用layui中post请求,请不要按layui官方提供的两种方法进行设置 官方设置如下: table.render({ elem: ...

  2. Loj#143-[模板]质数判定【Miller-Rabin】

    正题 题目链接:https://loj.ac/p/143 题目大意 给出一个数\(p\),让你判定是否为质数. 解题思路 \(Miller-Rabin\)是一种基于费马小定理和二次探测定理的具有较高正 ...

  3. P7717-「EZEC-10」序列【Trie】

    正题 题目链接:https://www.luogu.com.cn/problem/P7717 题目大意 求有多少个长度为\(n\)的序列\(a\)满足,都在\([0,k]\)的范围内且满足\(m\)个 ...

  4. 关于Postman你必须学会的技能

    关于Postman 工欲善其事,必先利其器,在了解了接口测试之后,就要选择一款适用的工具.之所以选择postman是因为它简单.容易上手.能覆盖大多数HTTP接口测试场景,性价比极高. Postman ...

  5. Ubuntu开发相关环境搭建

    一.Ubuntu系统语言环境切换修改 安装时,选择的中文版,但实际使用起来,很不爽,果断切换为英文 1.1 打开终端: vim /etc/default/locale 1.2 修改配置 LANG=&q ...

  6. Django+Nginx+Uwsgi(全网最全步骤工作原理流程与部署历程)

    一.必要前提 1.1 准备知识 django 一个基于python的开源web框架,请确保自己熟悉它的框架目录结构. uWSGI 一个基于自有的uwsgi协议.wsgi协议和http服务协议的web网 ...

  7. Java秘诀!Java逻辑运算符介绍

    运算符丰富是 Java 语言的主要特点之一,它提供的运算符数量之多,在高级语言中是少见的. Java 语言中的运算符除了具有优先级之外,还有结合性的特点.当一个表达式中出现多种运算符时,执行的先后顺序 ...

  8. Markdown语法熟悉

    ==(1)标题== # 一级标题 ## 二级标题 ### 三级标题 #### 四级标题 ##### 五级标题 ###### 六级标题 ==(2)字体== **加粗** *斜体* ***斜体加粗*** ...

  9. NOIP模拟76

    前言 还有不到 10 天就要 CSP-S ...马上我就要有我的第一篇游记了. 今天考试莽了一回,整了大概 2.5h 的 T1 ,可能是因为今天题目比较难,看起来成效不错. 以后还是要注意时间的分配( ...

  10. bzoj2038 小z的袜子 (莫队)

    题目大意 作为一个生活散漫的人,小Z每天早上都要耗费很久从一堆五颜六色的袜子中找出一双来穿.终于有一天,小Z再也无法忍受这恼人的找袜子过程,于是他决定听天由命-- 具体来说,小Z把这N只袜子从1到N编 ...