• sm2多端加密解密,java,js,android,ios实战


    SM2非对称加密

    1. 公钥 = 04xxxxxxxxxxxxxxxxxxxx,
    2. 私钥 = 276xxxx
    3. 原文:你哦哈1232154 3654 {} ,俺可接受不符点

    公钥私钥是我后台自己生成的,

    java代码实现

    pom.xml

    1. <dependency>
    2.     <groupId>org.bouncycastlegroupId>
    3.     <artifactId>bcprov-jdk15to18artifactId>
    4.     <version>1.71version>
    5. dependency>

    国密sm2算法秘钥对

    1. package com.sm.mscmsm2;
    2. /**
    3. * 描述: 国密sm2算法秘钥对 - 对象
    4. * 时间: 2022-07-14 16:01
    5. * 作者:IT学习道场
    6. */
    7. public class SM2KeyPairs {
    8. /**
    9. *公钥
    10. */
    11. private String publicKey;
    12. /**
    13. * 私钥
    14. */
    15. private String privateKey;
    16. public SM2KeyPairs() {
    17. }
    18. public SM2KeyPairs(String publicKey, String privateKey) {
    19. this.publicKey = publicKey;
    20. this.privateKey = privateKey;
    21. }
    22. public String getPublicKey() {
    23. return publicKey;
    24. }
    25. public void setPublicKey(String publicKey) {
    26. this.publicKey = publicKey;
    27. }
    28. public String getPrivateKey() {
    29. return privateKey;
    30. }
    31. public void setPrivateKey(String privateKey) {
    32. this.privateKey = privateKey;
    33. }
    34. @Override
    35. public String toString() {
    36. return "SM2KeyPairs{" +
    37. "publicKey='" + publicKey + '\'' +
    38. ", privateKey='" + privateKey + '\'' +
    39. '}';
    40. }
    41. }

    SM2辅助工具类

    采用数字证书类型 X9

    1. package com.sm.mscmsm2;
    2. import lombok.extern.slf4j.Slf4j;
    3. import org.bouncycastle.asn1.gm.GMNamedCurves;
    4. import org.bouncycastle.asn1.x9.X9ECParameters;
    5. import org.bouncycastle.crypto.AsymmetricCipherKeyPair;
    6. import org.bouncycastle.crypto.InvalidCipherTextException;
    7. import org.bouncycastle.crypto.engines.SM2Engine;
    8. import org.bouncycastle.crypto.generators.ECKeyPairGenerator;
    9. import org.bouncycastle.crypto.params.*;
    10. import org.bouncycastle.math.ec.ECPoint;
    11. import org.bouncycastle.util.encoders.Hex;
    12. import java.io.UnsupportedEncodingException;
    13. import java.math.BigInteger;
    14. import java.security.NoSuchAlgorithmException;
    15. import java.security.SecureRandom;
    16. import java.util.Base64;
    17. /**
    18. * 描述: 美术传媒sm2
    19. * 时间: 2022-07-25 17:32
    20. * 作者:王林冲
    21. */
    22. @Slf4j
    23. public class SM2Util {
    24. private static final ECDomainParameters domainParameters;
    25. private static final X9ECParameters sm2ECParameters;
    26. static {
    27. sm2ECParameters = GMNamedCurves.getByName("sm2p256v1");
    28. domainParameters = new ECDomainParameters(sm2ECParameters.getCurve(), sm2ECParameters.getG(), sm2ECParameters.getN());
    29. }
    30. public static SM2KeyPairs getSM2KeyPairs(){
    31. //生成密钥对
    32. ECKeyPairGenerator keyPairGenerator = new ECKeyPairGenerator();
    33. try {
    34. keyPairGenerator.init(new ECKeyGenerationParameters(domainParameters, SecureRandom.getInstance("SHA1PRNG")));
    35. AsymmetricCipherKeyPair asymmetricCipherKeyPair = keyPairGenerator.generateKeyPair();
    36. //私钥,16进制格式,自己保存,格式如a2081b5b81fbea0b6b973a3ab6dbbbc65b1164488bf22d8ae2ff0b8260f64853
    37. BigInteger privatekey = ((ECPrivateKeyParameters) asymmetricCipherKeyPair.getPrivate()).getD();
    38. String privateKeyHex = privatekey.toString(16);
    39. //公钥,16进制格式,发给前端,格式如04813d4d97ad31bd9d18d785f337f683233099d5abed09cb397152d50ac28cc0ba43711960e811d90453db5f5a9518d660858a8d0c57e359a8bf83427760ebcbba
    40. ECPoint ecPoint = ((ECPublicKeyParameters) asymmetricCipherKeyPair.getPublic()).getQ();
    41. String publicKeyHex = Hex.toHexString(ecPoint.getEncoded(false));
    42. SM2KeyPairs pairs = new SM2KeyPairs(publicKeyHex, privateKeyHex);
    43. return pairs;
    44. } catch (NoSuchAlgorithmException e) {
    45. log.error(e.getMessage(), e);
    46. throw new RuntimeException(e.getMessage());
    47. }
    48. }
    49. public static String decrypt(String data, String privateKey) {
    50. byte[] cipherDataByte = Hex.decode(data);
    51. //刚才的私钥Hex,先还原私钥
    52. BigInteger privateKeyD = new BigInteger(privateKey, 16);
    53. ECPrivateKeyParameters privateKeyParameters = new ECPrivateKeyParameters(privateKeyD, domainParameters);
    54. //用私钥解密
    55. SM2Engine sm2Engine = new SM2Engine();
    56. sm2Engine.init(false, privateKeyParameters);
    57. //processBlock得到Base64格式,记得解码
    58. byte[] arrayOfBytes = new byte[0];
    59. try {
    60. arrayOfBytes = Base64.getDecoder().decode(sm2Engine.processBlock(cipherDataByte, 0, cipherDataByte.length));
    61. } catch (InvalidCipherTextException e) {
    62. log.error(e.getMessage(), e);
    63. throw new RuntimeException(e.getMessage());
    64. }
    65. //得到明文:SM2 Encryption Test
    66. return new String(arrayOfBytes);
    67. }
    68. public static String encrypt(String data, String publicKey){
    69. //提取公钥点
    70. ECPoint pukPoint = sm2ECParameters.getCurve().decodePoint(Hex.decode(publicKey));
    71. //刚才的私钥Hex,先还原私钥
    72. ECPublicKeyParameters publicKeyParameters = new ECPublicKeyParameters(pukPoint, domainParameters);
    73. SM2Engine sm2Engine = new SM2Engine();
    74. sm2Engine.init(true, new ParametersWithRandom(publicKeyParameters, new SecureRandom()));
    75. byte[] arrayOfBytes = new byte[0];
    76. try {
    77. byte[] in = Base64.getEncoder().encode(data.getBytes("utf-8"));
    78. arrayOfBytes = sm2Engine.processBlock(in, 0, in.length);
    79. } catch (Exception e) {
    80. log.error(e.getMessage(), e);
    81. throw new RuntimeException(e.getMessage());
    82. }
    83. return Hex.toHexString(arrayOfBytes);
    84. }
    85. public static void main(String[] args) throws InvalidCipherTextException, UnsupportedEncodingException {
    86. //SM2KeyPairs sm2KeyPairs = getSM2KeyPairs();
    87. //System.out.println(sm2KeyPairs.toString());
    88. String publicKey = "0419080a9bdb6968f0ef31b2xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
    89. String privateKey = "2766001cc5d2888xxxxxxxxxxxxxxxxxxxxxxxxx";
    90. String text = "你哦哈1232154 3654 {} ,俺可接受不符点";
    91. String encrypt = encrypt(text, publicKey);
    92. System.out.println("encrypt = "+ encrypt);
    93. //String encrypt = "041fccce91d7a35a429f449aea758364826f688577bad9d3b9c99a1ab5c390fdf63f00232e0af4fcab8fccd70c46b636e42024f260973d73c8d1b6c3d41c2b26238b8a09c994e0a912ba2022b342af049b164979018af08e75cb63a66408fe9dfd553e7a350fb0d12405b984bde185ba38ca693c9c12b06dbe445abc5b9fc754f2424bab2a766d62c12b1832c51b2cab44ba4dc0049b5f3b479fe1cc348bcfd77f65db4267";
    94. String jm = decrypt(encrypt, privateKey);
    95. System.out.println(jm);
    96. }
    97. }

    JavaScript实现

    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;ovar s=e[o>>>2]>>>24-o%4*8&255;r[i+o>>>2]|=s<<24-(i+o)%4*8}else for(var o=0;o4)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;o4){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;nvar 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;i2)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;nvar 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>>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;fthis._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;sif(s%4){var a=e[t.charCodeAt(s-1)]<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;o3)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*lpush(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;olength;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<>>32-o)+r}function i(t,r,e,i,n,o,s){var a=t+(r&i|e&~i)+n+s;return(a<>>32-o)+r}function n(t,r,e,i,n,o,s){var a=t+(r^e^i)+n+s;return(a<>>32-o)+r}function o(t,r,e,i,n,o,s){var a=t+(e^(r|~i))+n+s;return(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;n2){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>>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;o2){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>>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>>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<>>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;h1549556828,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.lengthvar u=i.update(r).finalize(s);i.reset();for(var d=u.words,v=d.length,p=u,_=1;_finalize(p),i.reset();for(var y=p.words,g=0;gconcat(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.lengthupdate(h);var h=i.update(t).finalize(r);i.reset();for(var l=1;lfinalize(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;ivar 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;iclone();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<1;v<32?u^=1<<v:c^=1<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;nvar 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<>>32-b,p=x<>>32-b;else var v=x<32|m>>>64-b,p=m<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;lvar 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>>0?1:0),G=G+nt,q=q+it+(G>>>0>>0?1:0),G=G+lt,q=q+ht+(G>>>0>>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>>0?1:0),St=St+ut,mt=mt+ft+(St>>>0>>0?1:0),St=St+kt,mt=mt+wt+(St>>>0>>0?1:0),St=St+G,mt=mt+q+(St>>>0>>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>>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>>0?1:0),_=n.low=_+E,n.high=p+R+(_>>>0>>0?1:0),g=o.low=g+F,o.high=y+M+(g>>>0>>0?1:0),w=s.low=w+W,s.high=B+P+(w>>>0>>0?1:0),S=a.low=S+U,a.high=k+O+(S>>>0>>0?1:0),x=c.low=x+K,c.high=m+I+(x>>>0>>0?1:0),H=f.low=H+L,f.high=b+X+(H>>>0>>0?1:0),A=u.low=A+N,u.high=z+j+(A>>>0>>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;svar 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;a4)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;svar 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;sreturn 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;aif(aelse{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;lvar 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;vvar 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<function e(t,r){var e=(this._rBlock>>>t^this._lBlock)&r;this._lBlock^=e,this._rBlock^=e<
    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;creturn 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]>>>00]>>>0?1:0)|0,r[2]=r[2]+886263092+(r[1]>>>01]>>>0?1:0)|0,r[3]=r[3]+1295307597+(r[2]>>>02]>>>0?1:0)|0,r[4]=r[4]+3545052371+(r[3]>>>03]>>>0?1:0)|0,r[5]=r[5]+886263092+(r[4]>>>04]>>>0?1:0)|0,r[6]=r[6]+1295307597+(r[5]>>>05]>>>0?1:0)|0,r[7]=r[7]+3545052371+(r[6]>>>06]>>>0?1:0)|0,this._b=r[7]>>>07]>>>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;areturn 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]>>>00]>>>0?1:0)|0,r[2]=r[2]+886263092+(r[1]>>>01]>>>0?1:0)|0,r[3]=r[3]+1295307597+(r[2]>>>02]>>>0?1:0)|0,r[4]=r[4]+3545052371+(r[3]>>>03]>>>0?1:0)|0,r[5]=r[5]+886263092+(r[4]>>>04]>>>0?1:0)|0,r[6]=r[6]+1295307597+(r[5]>>>05]>>>0?1:0)|0,r[7]=r[7]+3545052371+(r[6]>>>06]>>>0?1:0)|0,this._b=r[7]>>>07]>>>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

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

    html使用demo

    1. html>
    2. <html lang="en">
    3. <head>
    4. <meta charset="UTF-8">
    5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
    6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
    7. <title>sm2加密title>
    8. <script src="./lib/crypto-js.js">script>
    9. <script src="./lib/sm2.js">script>
    10. head>
    11. <body>
    12. <script type="text/javascript">
    13. //私钥:2766001cc5d2888553efe566781d8fb25557aecd6435e731d21ad362af8a4eaf
    14. //公钥:前缀04+x坐标+y坐标
    15. var pubkeyHex = "04190xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
    16. var msg='你哦哈1232154 3654 {} ,俺可接受不符点';
    17. //加密格式0: C1C2C3、1: C1C3C2
    18. var encryptData = sm2Encrypt(msg, pubkeyHex, 0);
    19. document.write(encryptData);
    20. script>
    21. body>
    22. html>

    Android端和java端一样,jar包采用 bcprov-jdk15to18-1.71.jar

    java端基于hutool实现,上面不是hutool,因为个人喜欢hutool,必须要基于hutool实现一个

    pom.xml

    1. <dependency>
    2. <groupId>cn.hutoolgroupId>
    3. <artifactId>hutool-allartifactId>
    4. <version>5.7.4version>
    5. dependency>
    6. <dependency>
    7. <groupId>org.bouncycastlegroupId>
    8. <artifactId>bcpkix-jdk15onartifactId>
    9. <version>1.57version>
    10. dependency>
    SM2KeyPairs
    1. package com.sm.hutoolsm2;
    2. /**
    3. * 描述: 国密sm2算法秘钥对 - 对象
    4. * 时间: 2022-07-14 16:01
    5. * 作者:IT学习道场
    6. */
    7. public class SM2KeyPairs {
    8. /**
    9. *公钥
    10. */
    11. private String publicKey;
    12. /**
    13. * 私钥
    14. */
    15. private String privateKey;
    16. public SM2KeyPairs() {
    17. }
    18. public SM2KeyPairs(String publicKey, String privateKey) {
    19. this.publicKey = publicKey;
    20. this.privateKey = privateKey;
    21. }
    22. public String getPublicKey() {
    23. return publicKey;
    24. }
    25. public void setPublicKey(String publicKey) {
    26. this.publicKey = publicKey;
    27. }
    28. public String getPrivateKey() {
    29. return privateKey;
    30. }
    31. public void setPrivateKey(String privateKey) {
    32. this.privateKey = privateKey;
    33. }
    34. @Override
    35. public String toString() {
    36. return "SM2KeyPairs{" +
    37. "publicKey='" + publicKey + '\'' +
    38. ", privateKey='" + privateKey + '\'' +
    39. '}';
    40. }
    41. }
    SM2Util
    1. package com.sm.hutoolsm2;
    2. import cn.hutool.core.util.HexUtil;
    3. import cn.hutool.crypto.BCUtil;
    4. import cn.hutool.crypto.SmUtil;
    5. import cn.hutool.crypto.asymmetric.KeyType;
    6. import cn.hutool.crypto.asymmetric.SM2;
    7. import com.sm.sm2.SM2KeyPairs;
    8. import org.bouncycastle.crypto.engines.SM2Engine;
    9. import org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPublicKey;
    10. import java.nio.charset.Charset;
    11. import java.util.Base64;
    12. /**
    13. * 描述: todo
    14. * 时间: 2022-07-25 17:32
    15. * 作者:IT学习道场
    16. */
    17. public class SM2Util {
    18. /**
    19. * 获取公钥私钥
    20. * @return SM2KeyPairs 公私钥对象
    21. */
    22. public static SM2KeyPairs getKeyPairs(){
    23. SM2 sm2 = SmUtil.sm2();
    24. // sm2的加解密时有两种方式即 C1C2C3、 C1C3C2,
    25. sm2.setMode(SM2Engine.Mode.C1C2C3);
    26. // 生成私钥
    27. String privateKey = HexUtil.encodeHexStr(BCUtil.encodeECPrivateKey(sm2.getPrivateKey()));
    28. // 生成公钥
    29. String publicKey = HexUtil.encodeHexStr(((BCECPublicKey) sm2.getPublicKey()).getQ().getEncoded(false));
    30. SM2KeyPairs keyPairs = new SM2KeyPairs(publicKey, privateKey);
    31. return keyPairs;
    32. }
    33. /**
    34. * 公钥加密
    35. * @param publicKey 公钥
    36. * @param text 预加密文本
    37. * @return 加密后文本
    38. */
    39. public static String encrypt(String publicKey, String text){
    40. // 通过密钥解密
    41. SM2 sm2 = SmUtil.sm2(null, publicKey);
    42. sm2.setMode(SM2Engine.Mode.C1C2C3);
    43. //1 先把明文转成base64
    44. text = Base64.getEncoder().encodeToString(text.getBytes());
    45. //2 把base64的文本用公钥加密后在转成密文为16进制,否则前端解密前需要先转换格式
    46. String encryptStr = sm2.encryptHex(text, Charset.forName("utf-8"), KeyType.PublicKey);
    47. return encryptStr;
    48. }
    49. /**
    50. * 私钥解密
    51. * @param privateKey 私钥
    52. * @param text 加密文本
    53. * @return 解密后文本
    54. */
    55. public static String decrypt(String privateKey, String text){
    56. //创建sm2 对象
    57. SM2 sm2 = SmUtil.sm2(privateKey, null);
    58. sm2.setMode(SM2Engine.Mode.C1C2C3);
    59. // 私钥解密
    60. String decrypt = sm2.decryptStr(text, KeyType.PrivateKey);
    61. byte[] decode = Base64.getDecoder().decode(decrypt);
    62. String decryptStr = new String(decode);
    63. return decryptStr;
    64. }
    65. public static void main(String[] args) {
    66. //SM2KeyPairs keyPairs = getKeyPairs();
    67. //System.out.println(keyPairs.toString());
    68. String publicKey = "0407125a6dc1d73e41dc1b57xxxxxxxxxxxxxxxxxxxxxx";
    69. String privateKey = "0f3c459c2090eb5c35108xxxxxxxxxxxxx";
    70. String text = "你哦哈1232154 3654 {} ,俺可接受不符点";
    71. String encrypt = encrypt(publicKey, text);
    72. System.out.println("encrypt = " + encrypt);
    73. //String encrypt ="04ddb0f3622c51af847bbd528d9fb8cd264aa9341c817cb3077bb1464766b3b7e3a5ff523004d4f2259676267a080f66c4682844adef2e4b612e604071af16c6285fc48795e4ae1277e7d79b4bf420584dea2345eae0d5f2e12293013d25af09eaff4fabf5109a18fed74d07ed30a34b1623f161f7a70e2746accf9334b96cfc33f2aa6aae13c08b131604a9caa7d2c5453b8a021a6354ba27cd7d3f4ebcf93376efa9cf5d";
    74. String decrypt = decrypt(privateKey, encrypt);
    75. System.out.println("decrypt = " + decrypt);
    76. }
    77. }

    hutool实现和上面的Android可用的版本一样,当然,后端也可以直接使用Android和java通用的版本

    ios端必须和js和java和Android端一致,采用 C1C2C3模式

    下面是ios的实现。采用国密 国密的 Objective-C 封装

    查看具体实现过程,请至开源项目地址GitHub - muzipiao/GMObjC: SM2/SM3/SM4/ECDH library based on OpenSSL.

    在终端运行以下命令:

    1. git clone https://github.com/muzipiao/GMObjC.git
    2. cd GMObjC
    3. pod install
    4. open GMObjC.xcworkspace

    向项目中引入GMObjC即可

    使用代码如下

    SM2 加解密

    SM2 加解密都很简单,加密传入待加密明文和公钥,解密传入密文和私钥即可,代码:

    1. NSString *pubKey = @"0408E3FFF9505BCFAF9307E665E9229F4E1B3936437xxxxxxxxxxxxxxxxxxxxxxxxxxxx";
    2. NSString *priKey = @"90F3A42B9FE24AB196305FD92EC82E647616C3A369xxxxxxxxxx";
    3. NSString *plaintext = @"你哦哈1232154 3654 {} ,俺可接受不符点";
    4. //先对明文进行base64加密,再用GMSm2Utils 对其进行sm2加密,返回asn1编码格式的密文
    5. NSString *encode = [GMSm2Utils encryptText:[self base64:plaintext] publicKey:pubKey];
    6. //把asn1编码格式的密文的 encode 解码成C1C3C2的密文字符串 = c1c3c2
    7. NSString *c1c3c2 = [GMSm2Utils asn1DecodeToC1C3C2:encode];
    8. //再把c1c3c2这个字符串转成 C1C2C3 模式的密文字符串 = c1c2c3 ,这个可以直接传给java端,用上面的java端实现的sm2Util进行解密
    9. NSString *c1c2c3 = [GMSm2Utils convertC1C3C2ToC1C2C3:c1c3c2 hasPrefix:NO];
    10. NSLog(@"c1c2c3 : %@",c1c2c3);

    注意这里的密文要拼上 "04" 这个前缀,后端才能进行解密

    这是base64加密方法

    1. - (NSString *)base64:(NSString *)string{
    2. NSString *target = string;
    3. NSData *data = [target dataUsingEncoding:NSUTF8StringEncoding];
    4. NSString *base64Str = [data base64EncodedStringWithOptions:nil];
    5. // NSString *base64DecodeStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    6. return base64Str;
    7. }

    我们前后端的逻辑是 先对明文进行base64加密,再sm2加密,再转16进制。

    解密的逻辑,是先对密文进行16进制解密,再sm2解密,再base64解密

    你们具体可根据自己的情况来处理,但是最好搞清楚逻辑,不然很容易出错,或者直接按照我们的略记处理,直接copy,省事儿

  • 相关阅读:
    从JVM角度看继承
    商业智能BI如何帮助企业
    路由器拨号失败解决方法
    django MEDIA_URL 和 MEDIA_ROOT 如何配置
    抖音的文案怎么做|成都聚华祥
    【初始C语言】/*C语言初阶指针通俗详解*/
    蚂蚁面试官:Zookeeper 的选举流程是怎样的?我当场懵逼了
    Axure常用技巧及问题
    【Oralce】导出所有表名、表注释、创建时间、最后修改时间、主键
    Arduino--音乐频谱
  • 原文地址:https://blog.csdn.net/qq_38138069/article/details/126018214