〇、简介
椭圆曲线密码学(Elliptic curve cryptography:ECC),一种建立公开密钥加密的演算法,基于椭圆曲线数学。利用有限域上椭圆曲线的点构成的 Abel 群离散对数难解性,实现加密、解密和数字签名。将椭圆曲线中的加法运算与离散对数中的模乘运算相对应,就可以建立基于椭圆曲线的对应密码体制。椭圆曲线在密码学中的使用是在 1985 年由 Neal Koblitz 和 Victor Miller 分别独立提出的。
注:计算与演算的区别,计算(包括的范围更大些,它可以是笔算、口算、估算等);演算(是按照一定的原理、公式计算,有时在黑板上,有时在纸上,还可以在计算机上,演算注重的是最初的计算)。
由于 RSA、AES 等国际算法面临高强度算法禁售和被部署后门风险,我国基于 ECC 椭圆曲线,自研 SM2/SM3/SM4/SM9 一套安全算法。根据国家整体战略,金融及重要领域要逐步实现国密算法替换,另根据中国人民银行总体规划,在 2022 年金融行业要全面应用国密算法。在 FireFly 移动金融开发平台中,完善的提供了支持国密算法的加解密算法包。
优点:
- 更适合于移动互联网。在同等加密安全强度下,ECC 密钥长度为 163bit,而 RSA 密钥长度为 1024bit。ECC 加密算法的密钥长度很短,意味着占用更少的存储空间,更低的 CPU 开销和占用更少的带宽。随着越来越多的用户使用移动设备来完成各种网上活动,ECC加 密算法为移动互联网安全提供更好的客户体验。
- 更好的安全性。ECC 加密算法提供更强的保护,比目前的其他加密算法能更好的防止攻击,使你的网站和基础设施比用传统的加密方法更安全,为移动互联网安全提供更好的保障。
- 更好的性能。ECC 加密算法需要较短的密钥长度来提供更好的安全。
椭圆曲线 ECC 算法基于椭圆曲线理论,可以用较少的计算能力提供更高的安全强度,有效地解决了“提高安全强度必须增加密钥长度”的工程实现问题,且已经得到广泛的支持和使用。因此,读者在选择加密算法时,ECC 算法不失为一个优秀的选择。
关于椭圆曲线加密详细,可参考:椭圆曲线加密原理与应用
一、C# 实现
SM2 测试示例:
static void Main(string[] args)
{
SM2KeyPair sM2KeyPair = SecurityECC.GenerateKeyPair("string", true);
// 国密规范正式私钥 Hex 格式:821A9140010C4D8392BFBB821CC10F4D9AD122D26489737DF4AAC1036105E0EE
// 国密规范正式公钥 Hex 格式:0407F6FA2C01F904A492173340D58E778272245AE01C2D1AEB42F487FF97C6F3880EC07721A5C892DA31595B7664D4095BBC6BBA565CF014B0A4DEA9C5498DFB09
string privatekey = sM2KeyPair.PriKey.ToString(); // string / base64
string publickey = sM2KeyPair.PubKey.ToString(); // string / base64
//byte[] privatekey = (byte[])sM2KeyPair.PriKey; // byte
//byte[] publickey = (byte[])sM2KeyPair.PubKey; // byte
string plaintext = "TestString测试";
byte[] sourceData = Encoding.Default.GetBytes(plaintext);
Console.WriteLine("加密: ");
string ciphertext = SecurityECC.Encrypt(Hex.Decode(publickey), sourceData); // string
//string ciphertext = SecurityECC.Encrypt(Convert.FromBase64String(publickey), sourceData); // base64
Console.WriteLine(ciphertext);
// 加密后的密文每次生成均不同, Hex 格式:
// 042730455A5DD607269EF336DE72098CFB95E2F280E656A27D44B2045E25A6574874A0E13EEEE46B763E74F48250DEC1445C390E2E13F7B55DA83E74DDAE4FD1C5F5E496B4461AFBE051504A0660B81CDB5A5514229CD058690CD9EA68F45FF94348B40A144EC47B5E202732B8C5900C95
Console.WriteLine("解密: ");
plaintext = Encoding.Default.GetString(SecurityECC.Decrypt(Hex.Decode(privatekey), Hex.Decode(ciphertext))); // string
//plainText = Encoding.Default.GetString(SecurityECC.Decrypt(Convert.FromBase64String(privatekey), Hex.Decode(ciphertext))); // base64
Console.WriteLine(plaintext);
//查验结果推荐在线工具:https://www.javalang.cn/crypto/sm2.html
}
以上测试的源码,如下两个部分:工具类 SecurityECC.cs、基础类集合。
点击查看 SecurityECC.cs 工具类
public class SecurityECC
{
///
/// 生成密钥
///
/// 生成 object 类型的密钥,可选数据样式:string(默认)、base64、byte
/// 当密钥类型为 string 时有效,且 false-小写;true-大写(默认)
///
///
public static SM2KeyPair GenerateKeyPair(string backtype = "string", bool isupper = true)
{
SM2Factory sm2Parameters = SM2Factory.Instance;
AsymmetricCipherKeyPair key = sm2Parameters.ecc_key_pair_generator.GenerateKeyPair();
ECPrivateKeyParameters ecpriv = (ECPrivateKeyParameters)key.Private;
ECPublicKeyParameters ecpub = (ECPublicKeyParameters)key.Public;
BigInteger privateKey = ecpriv.D;
ECPoint publicKey = ecpub.Q;
SM2KeyPair kp = new SM2KeyPair();
switch (backtype)
{
case "string":
kp.PubKey = isupper ? Hex.ToHexString(publicKey.GetEncoded()).ToUpper() : Hex.ToHexString(publicKey.GetEncoded());
kp.PriKey = isupper ? Hex.ToHexString(privateKey.ToByteArray32()).ToUpper() : Hex.ToHexString(privateKey.ToByteArray32());
break;
case "byte":
kp.PubKey = publicKey.GetEncoded();
kp.PriKey = privateKey.ToByteArray32();
break;
case "base64":
kp.PubKey = Convert.ToBase64String(publicKey.GetEncoded());
kp.PriKey = Convert.ToBase64String(privateKey.ToByteArray32());
break;
default:
throw new Exception("生成密钥时,传入参数无效!");
}
return kp;
}
public static SM2Signature Sign(byte[] msg, byte[] privateKey, byte[] userId = null)
{
if (userId == null)
{
//31323334353637383132333435363738
userId = new byte[] { 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38 };
}
BigInteger userD = new BigInteger(1, privateKey);
SM2Factory sm2Factory = SM2Factory.Instance;
ECPoint userKey = sm2Factory.ecc_point_g.Multiply(userD);
SM3Digest sm3Digest = new SM3Digest();
var z = sm2Factory.Sm2GetZ(userId, userKey);
sm3Digest.BlockUpdate(z, 0, z.Length);
sm3Digest.BlockUpdate(msg, 0, msg.Length);
var md = new byte[32];
sm3Digest.DoFinal(md, 0);
var result = sm2Factory.Sm2Sign(md, userD, userKey);
return result;
}
public static bool VerifySign(byte[] msg, SM2Signature sm2Signature, byte[] pubKey, byte[] userId = null)
{
if (userId == null)
{
userId = new byte[] { 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38 };
}
SM2Factory factory = SM2Factory.Instance;
ECPoint userKey = factory.ecc_curve.DecodePoint(pubKey);
SM3Digest sm3Digest = new SM3Digest();
var z = factory.Sm2GetZ(userId, userKey);
sm3Digest.BlockUpdate(z, 0, z.Length);
sm3Digest.BlockUpdate(msg, 0, msg.Length);
byte[] md = new byte[32];
sm3Digest.DoFinal(md, 0);
var r = new BigInteger(1, sm2Signature.R);
var s = new BigInteger(1, sm2Signature.S);
var sm2Result = new SM2Result();
sm2Result = factory.Sm2Verify(md, userKey, r, s);
if (sm2Result.R == null)
{
return false;
}
var verifyFlag = sm2Result.R.Equals(r);
return verifyFlag;
}
///
/// 加密(老标准)
///
///
///
///
public static string Encrypt(byte[] publicKey, byte[] data)
{
if (null == publicKey || publicKey.Length == 0)
return null;
if (data == null || data.Length == 0)
return null;
byte[] source = new byte[data.Length];
Array.Copy(data, 0, source, 0, data.Length);
Cipher cipher = new Cipher();
SM2Factory sm2 = SM2Factory.Instance;
ECPoint userKey = sm2.ecc_curve.DecodePoint(publicKey);
ECPoint c1 = cipher.Init_enc(sm2, userKey);
cipher.Encrypt(source);
byte[] c3 = new byte[32];
cipher.Dofinal(c3);
string sc1 = Encoding.Default.GetString(Hex.Encode(c1.GetEncoded()));
string sc2 = Encoding.Default.GetString(Hex.Encode(source));
string sc3 = Encoding.Default.GetString(Hex.Encode(c3));
return (sc1 + sc2 + sc3).ToUpper();
}
///
/// 加密(新标准)
///
///
///
///
public static byte[] EncryptC1C3C2(byte[] publicKey, byte[] data)
{
if (null == publicKey || publicKey.Length == 0)
{
return null;
}
if (data == null || data.Length == 0)
{
return null;
}
byte[] source = new byte[data.Length];
Array.Copy(data, 0, source, 0, data.Length);
Cipher cipher = new Cipher();
SM2Factory sm2Parameters = SM2Factory.Instance;
ECPoint userKey = sm2Parameters.ecc_curve.DecodePoint(publicKey);
ECPoint c1 = cipher.Init_enc(sm2Parameters, userKey);
cipher.Encrypt(source);
byte[] c3 = new byte[32];
cipher.Dofinal(c3);
//String sc1 = Encoding.Default.GetString(Hex.Encode(c1.GetEncoded()));
//String sc2 = Encoding.Default.GetString(Hex.Encode(source));
//String sc3 = Encoding.Default.GetString(Hex.Encode(c3));
return c1.GetEncoded()
.Concat(c3)
.Concat(source).ToArray();
}
public static byte[] Decrypt(byte[] privateKey, byte[] encryptedData)
{
if (null == privateKey || privateKey.Length == 0)
{
return null;
}
if (encryptedData == null || encryptedData.Length == 0)
{
return null;
}
string data = Encoding.Default.GetString(Hex.Encode(encryptedData));
byte[] c1Bytes = Hex.Decode(Encoding.Default.GetBytes(data.Substring(0, 130)));
int c2Len = encryptedData.Length - 97;
byte[] c2 = Hex.Decode(Encoding.Default.GetBytes(data.Substring(130, 2 * c2Len)));
byte[] c3 = Hex.Decode(Encoding.Default.GetBytes(data.Substring(130 + 2 * c2Len, 64)));
SM2Factory sm2 = SM2Factory.Instance;
BigInteger userD = new BigInteger(1, privateKey);
ECPoint c1 = sm2.ecc_curve.DecodePoint(c1Bytes);
Cipher cipher = new Cipher();
cipher.Init_dec(userD, c1);
cipher.Decrypt(c2);
cipher.Dofinal(c3);
return c2;
}
public static byte[] DecryptC1C3C2(byte[] privateKey, byte[] encryptedData)
{
if (null == privateKey || privateKey.Length == 0)
{
return null;
}
if (encryptedData == null || encryptedData.Length == 0)
{
return null;
}
byte[] c1Bytes = encryptedData.Take(65).ToArray();
byte[] c3 = encryptedData.Skip(65).Take(32).ToArray();
byte[] c2 = encryptedData.Skip(97).ToArray();
SM2Factory sm2 = SM2Factory.Instance;
BigInteger userD = new BigInteger(1, privateKey);
ECPoint c1 = sm2.ecc_curve.DecodePoint(c1Bytes);
Cipher cipher = new Cipher();
cipher.Init_dec(userD, c1);
cipher.Decrypt(c2);
cipher.Dofinal(c3);
return c2;
}
}
点击查看 第二部分:基础类集合
public class SM2Signature
{
public SM2Signature()
{ }
public SM2Signature(byte[] signData)
{
if (signData.Length == 65)
{
signData = signData.Skip(1).ToArray();
}
if (signData.Length == 64)
{
this.R = signData.Take(32).ToArray();
this.S = signData.Skip(32).ToArray();
}
}
public byte[] R { get; set; }
public byte[] S { get; set; }
public byte[] ToByteArray()
{
return R.Concat(S).ToArray();
}
public byte[] ToByteArray04()
{
var buffer = new byte[65];
buffer[0] = 0x04;
Array.Copy(this.R, 0, buffer, 1, 32);
Array.Copy(this.S, 0, buffer, 33, 32);
return buffer;
}
}
public class SM2Result
{
public SM2Result()
{ }
//验签R
public BigInteger R;
public BigInteger S;
// 密钥交换
public byte[] sa;
public byte[] sb;
public byte[] s1;
public byte[] s2;
public ECPoint keyra;
public ECPoint keyrb;
}
public class SM2Factory
{
public static SM2Factory Instance
{
get
{
return new SM2Factory();
}
}
public static SM2Factory InstanceTest
{
get
{
return new SM2Factory();
}
}
///
/// 国密曲线参数
///
public static readonly string[] sm2_param = {
"FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFF",// p,0
"FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFC",// a,1
"28E9FA9E9D9F5E344D5A9E4BCF6509A7F39789F515AB8F92DDBCBD414D940E93",// b,2
"FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFF7203DF6B21C6052B53BBF40939D54123",// n,3
"32C4AE2C1F1981195F9904466A39C9948FE30BBFF2660BE1715A4589334C74C7",// gx,4
"BC3736A2F4F6779C59BDCEE36B692153D0A9877CC62A474002DF32E52139F0A0" // gy,5
};
public string[] ecc_param = sm2_param;
public readonly BigInteger ecc_p;
public readonly BigInteger ecc_a;
public readonly BigInteger ecc_b;
public readonly BigInteger ecc_n;
public readonly BigInteger ecc_gx;
public readonly BigInteger ecc_gy;
public readonly ECCurve ecc_curve;
public readonly ECPoint ecc_point_g;
public readonly ECDomainParameters ecc_bc_spec;
public readonly ECKeyPairGenerator ecc_key_pair_generator;
private SM2Factory()
{
ecc_param = sm2_param;
ECFieldElement ecc_gx_fieldelement;
ECFieldElement ecc_gy_fieldelement;
ecc_p = new BigInteger(ecc_param[0], 16);
ecc_a = new BigInteger(ecc_param[1], 16);
ecc_b = new BigInteger(ecc_param[2], 16);
ecc_n = new BigInteger(ecc_param[3], 16);
ecc_gx = new BigInteger(ecc_param[4], 16);
ecc_gy = new BigInteger(ecc_param[5], 16);
ecc_gx_fieldelement = new FpFieldElement(ecc_p, ecc_gx);
ecc_gy_fieldelement = new FpFieldElement(ecc_p, ecc_gy);
ecc_curve = new FpCurve(ecc_p, ecc_a, ecc_b);
ecc_point_g = new FpPoint(ecc_curve, ecc_gx_fieldelement, ecc_gy_fieldelement);
ecc_bc_spec = new ECDomainParameters(ecc_curve, ecc_point_g, ecc_n);
ECKeyGenerationParameters ecc_ecgenparam;
ecc_ecgenparam = new ECKeyGenerationParameters(ecc_bc_spec, new SecureRandom());
ecc_key_pair_generator = new ECKeyPairGenerator();
ecc_key_pair_generator.Init(ecc_ecgenparam);
}
public SM2Signature Sm2Sign(byte[] md, BigInteger userD, ECPoint userKey)
{
BigInteger e = new BigInteger(1, md);
BigInteger k = null;
ECPoint kp = null;
BigInteger r = null;
BigInteger s = null;
do
{
do
{
// 正式环境
AsymmetricCipherKeyPair keypair = ecc_key_pair_generator.GenerateKeyPair();
ECPrivateKeyParameters ecpriv = (ECPrivateKeyParameters)keypair.Private;
ECPublicKeyParameters ecpub = (ECPublicKeyParameters)keypair.Public;
k = ecpriv.D;
kp = ecpub.Q;
//System.out.println("BigInteger:" + k + "nECPoint:" + kp);
//System.out.println("计算曲线点X1: "+ kp.getXCoord().toBigInteger().toString(16));
//System.out.println("计算曲线点Y1: "+ kp.getYCoord().toBigInteger().toString(16));
//System.out.println("");
// r
r = e.Add(kp.XCoord.ToBigInteger());
r = r.Mod(this.ecc_n);
} while (r.Equals(BigInteger.Zero) || r.Add(k).Equals(this.ecc_n) || r.ToString(16).Length != 64);
// (1 + dA)~-1
BigInteger da_1 = userD.Add(BigInteger.One);
da_1 = da_1.ModInverse(this.ecc_n);
// s
s = r.Multiply(userD);
s = k.Subtract(s).Mod(this.ecc_n);
s = da_1.Multiply(s).Mod(this.ecc_n);
} while (s.Equals(BigInteger.Zero) || s.ToString(16).Length != 64);
var sM2Signature = new SM2Signature
{
R = r.ToByteArray32(),
S = s.ToByteArray32()
};
return sM2Signature;
}
public SM2Result Sm2Verify(byte[] md, ECPoint userKey, BigInteger r, BigInteger s)
{
var sm2Result = new SM2Result();
BigInteger e = new BigInteger(1, md);
BigInteger t = r.Add(s).Mod(this.ecc_n);
if (t.Equals(BigInteger.Zero))
{
return sm2Result;
}
else
{
ECPoint x1y1 = ecc_point_g.Multiply(s);
//System.out.println("计算曲线点X0: "+ x1y1.normalize().getXCoord().toBigInteger().toString(16));
//System.out.println("计算曲线点Y0: "+ x1y1.normalize().getYCoord().toBigInteger().toString(16));
//System.out.println("");
x1y1 = x1y1.Add(userKey.Multiply(t));
//System.out.println("计算曲线点X1: "+ x1y1.normalize().getXCoord().toBigInteger().toString(16));
//System.out.println("计算曲线点Y1: "+ x1y1.normalize().getYCoord().toBigInteger().toString(16));
//System.out.println("");
sm2Result.R = e.Add(x1y1.Normalize().XCoord.ToBigInteger()).Mod(this.ecc_n);
//System.out.println("R: " + sm2Result.R.toString(16));
return sm2Result;
}
}
public virtual byte[] Sm2GetZ(byte[] userId, ECPoint userKey)
{
SM3Digest sm3 = new SM3Digest();
byte[] p;
// userId length
int len = userId.Length * 8;
sm3.Update((byte)(len >> 8 & 0x00ff));
sm3.Update((byte)(len & 0x00ff));
// userId
sm3.BlockUpdate(userId, 0, userId.Length);
// a,b
p = ecc_a.ToByteArray32();
sm3.BlockUpdate(p, 0, p.Length);
p = ecc_b.ToByteArray32();
sm3.BlockUpdate(p, 0, p.Length);
// gx,gy
p = ecc_gx.ToByteArray32();
sm3.BlockUpdate(p, 0, p.Length);
p = ecc_gy.ToByteArray32();
sm3.BlockUpdate(p, 0, p.Length);
// x,y
p = userKey.Normalize().XCoord.ToBigInteger().ToByteArray32();
sm3.BlockUpdate(p, 0, p.Length);
p = userKey.Normalize().YCoord.ToBigInteger().ToByteArray32();
sm3.BlockUpdate(p, 0, p.Length);
// Z
byte[] md = new byte[sm3.GetDigestSize()];
sm3.DoFinal(md, 0);
return md;
}
}
public class SM2KeyPair
{
public object PubKey { get; set; }
public object PriKey { get; set; }
}
public class Cipher
{
private int ct = 1;
private ECPoint p2;
private SM3Digest sm3keybase;
private SM3Digest sm3c3;
private byte[] key = new byte[32];
private byte keyOff = 0;
public Cipher()
{
}
private void Reset()
{
sm3keybase = new SM3Digest();
sm3c3 = new SM3Digest();
byte[] p;
p = p2.Normalize().XCoord.ToBigInteger().ToByteArray32();
sm3keybase.BlockUpdate(p, 0, p.Length);
sm3c3.BlockUpdate(p, 0, p.Length);
p = p2.Normalize().YCoord.ToBigInteger().ToByteArray32();
sm3keybase.BlockUpdate(p, 0, p.Length);
ct = 1;
NextKey();
}
private void NextKey()
{
SM3Digest sm3keycur = new SM3Digest(sm3keybase);
sm3keycur.Update((byte)(ct >> 24 & 0xff));
sm3keycur.Update((byte)(ct >> 16 & 0xff));
sm3keycur.Update((byte)(ct >> 8 & 0xff));
sm3keycur.Update((byte)(ct & 0xff));
sm3keycur.DoFinal(key, 0);
var testKey = HexUtil.ByteArrayToHex(key);
keyOff = 0;
ct++;
}
public virtual ECPoint Init_enc(SM2Factory sm2, ECPoint userKey)
{
BigInteger k = null;
ECPoint c1 = null;
AsymmetricCipherKeyPair key = sm2.ecc_key_pair_generator.GenerateKeyPair();
ECPrivateKeyParameters ecpriv = (ECPrivateKeyParameters)key.Private;
ECPublicKeyParameters ecpub = (ECPublicKeyParameters)key.Public;
k = ecpriv.D;
c1 = ecpub.Q;
p2 = userKey.Multiply(k);
Reset();
return c1;
}
public virtual void Encrypt(byte[] data)
{
sm3c3.BlockUpdate(data, 0, data.Length);
for (int i = 0; i
代码参考自:https://github.com/hyfree/github.hyfree.GM 其中还包含 SM3、SM4 等同类加解密算法,可供参考。
二、js 语言实现
引用开源 js 库的方式实现加解密。已测试可用。
// 引入 js 库
// 或者
import myStyles from '../myjs/sm2.js';
// 调用方法 message() 查看测试结果
window.onload = function () {
const privateKey = '821A9140010C4D8392BFBB821CC10F4D9AD122D26489737DF4AAC1036105E0EE';
const publicKey = '0407F6FA2C01F904A492173340D58E778272245AE01C2D1AEB42F487FF97C6F3880EC07721A5C892DA31595B7664D4095BBC6BBA565CF014B0A4DEA9C5498DFB09';
// 加密
const encode = smEncrypt.sm2Encrypt('TestString测试', publicKey);
console.log(encode);
// 加密结果每次均不同
// 044d85cc58578428f4ab1640bf804efc3d794494d3e37ba90a8a6cb26ff1bc5063896f3cc41f57ff98c0134e4f4095c70b1abe7da4a37dd1548f517a593a76dd8d0cbbf8d6141f67da191ef41e71596baf9828b02b945c985cbac813348bb9332867ea6fcc94449ec63e38756ebb3d9b70
// 解密
const decode = smEncrypt.sm2Decrypt(encode, privateKey);
console.log(decode);
// 推荐在线查验地址: https://www.javalang.cn/crypto/sm2.html
}
sm2.js 的内容:
注:详情请查看原地址:【(文件名为:smEncrypt.min.js
)】:https://github.com/44021987/smEncrypt
点击查看 js 文件内容
!function (t, e) { if ("object" == typeof exports && "object" == typeof module) module.exports = e(); else if ("function" == typeof define && define.amd) define([], e); else { var i = e(); for (var r in i) ("object" == typeof exports ? exports : t)[r] = i[r] } }(window, function () { return function (t) { var e = {}; function i(r) { if (e[r]) return e[r].exports; var s = e[r] = { i: r, l: !1, exports: {} }; return t[r].call(s.exports, s, s.exports, i), s.l = !0, s.exports } return i.m = t, i.c = e, i.d = function (t, e, r) { i.o(t, e) || Object.defineProperty(t, e, { enumerable: !0, get: r }) }, i.r = function (t) { "undefined" != typeof Symbol && Symbol.toStringTag && Object.defineProperty(t, Symbol.toStringTag, { value: "Module" }), Object.defineProperty(t, "__esModule", { value: !0 }) }, i.t = function (t, e) { if (1 & e && (t = i(t)), 8 & e) return t; if (4 & e && "object" == typeof t && t && t.__esModule) return t; var r = Object.create(null); if (i.r(r), Object.defineProperty(r, "default", { enumerable: !0, value: t }), 2 & e && "string" != typeof t) for (var s in t) i.d(r, s, function (e) { return t[e] }.bind(null, s)); return r }, i.n = function (t) { var e = t && t.__esModule ? function () { return t.default } : function () { return t }; return i.d(e, "a", e), e }, i.o = function (t, e) { return Object.prototype.hasOwnProperty.call(t, e) }, i.p = "", i(i.s = 5) }([function (t, e, i) { (function () { var e; function i(t, e, i) { null != t && ("number" == typeof t ? this.fromNumber(t, e, i) : null == e && "string" != typeof t ? this.fromString(t, 256) : this.fromString(t, e)) } function r() { return new i(null) } var s = "undefined" != typeof navigator; s && "Microsoft Internet Explorer" == navigator.appName ? (i.prototype.am = function (t, e, i, r, s, n) { for (var o = 32767 & e, h = e >> 15; --n >= 0;) { var u = 32767 & this[t], f = this[t++] >> 15, a = h * u + f * o; s = ((u = o * u + ((32767 & a) >> 30) + (a >>> 15) + h * f + (s >>> 30), i[r++] = 1073741823 & u } return s }, e = 30) : s && "Netscape" != navigator.appName ? (i.prototype.am = function (t, e, i, r, s, n) { for (; --n >= 0;) { var o = e * this[t++] + i[r] + s; s = Math.floor(o / 67108864), i[r++] = 67108863 & o } return s }, e = 26) : (i.prototype.am = function (t, e, i, r, s, n) { for (var o = 16383 & e, h = e >> 14; --n >= 0;) { var u = 16383 & this[t], f = this[t++] >> 14, a = h * u + f * o; s = ((u = o * u + ((16383 & a) > 28) + (a >> 14) + h * f, i[r++] = 268435455 & u } return s }, e = 28), i.prototype.DB = e, i.prototype.DM = (1 >> 16) && (t = e, i += 16), 0 != (e = t >> 8) && (t = e, i += 8), 0 != (e = t >> 4) && (t = e, i += 4), 0 != (e = t >> 2) && (t = e, i += 2), 0 != (e = t >> 1) && (t = e, i += 1), i } function c(t) { this.m = t } function g(t) { this.m = t, this.mp = t.invDigit(), this.mpl = 32767 & this.mp, this.mph = this.mp >> 15, this.um = (1 >= 16, e += 16), 0 == (255 & t) && (t >>= 8, e += 8), 0 == (15 & t) && (t >>= 4, e += 4), 0 == (3 & t) && (t >>= 2, e += 2), 0 == (1 & t) && ++e, e } function b(t) { for (var e = 0; 0 != t;)t &= t - 1, ++e; return e } function F() { } function B(t) { return t } function x(t) { this.r2 = r(), this.q3 = r(), i.ONE.dlShiftTo(2 * t.t, this.r2), this.mu = this.r2.divide(t), this.m = t } c.prototype.convert = function (t) { return t.s = 0 ? t.mod(this.m) : t }, c.prototype.revert = function (t) { return t }, c.prototype.reduce = function (t) { t.divRemTo(this.m, null, t) }, c.prototype.mulTo = function (t, e, i) { t.multiplyTo(e, i), this.reduce(i) }, c.prototype.sqrTo = function (t, e) { t.squareTo(e), this.reduce(e) }, g.prototype.convert = function (t) { var e = r(); return t.abs().dlShiftTo(this.m.t, e), e.divRemTo(this.m, null, e), t.s 0 && this.m.subTo(e, e), e }, g.prototype.revert = function (t) { var e = r(); return t.copyTo(e), this.reduce(e), e }, g.prototype.reduce = function (t) { for (; t.t > 15) * this.mpl & this.um) = t.DV;)t[i] -= t.DV, t[++i]++ } t.clamp(), t.drShiftTo(this.m.t, t), t.compareTo(this.m) >= 0 && t.subTo(this.m, t) }, g.prototype.mulTo = function (t, e, i) { t.multiplyTo(e, i), this.reduce(i) }, g.prototype.sqrTo = function (t, e) { t.squareTo(e), this.reduce(e) }, i.prototype.copyTo = function (t) { for (var e = this.t - 1; e >= 0; --e)t[e] = this[e]; t.t = this.t, t.s = this.s }, i.prototype.fromInt = function (t) { this.t = 1, this.s = t 0 ? this[0] = t : t = 0;) { var h = 8 == r ? 255 & t[s] : a(t, s); h this.DB ? (this[this.t - 1] |= (h & (1 > this.DB - o) : this[this.t - 1] |= h = this.DB && (o -= this.DB)) } 8 == r && 0 != (128 & t[0]) && (this.s = -1, o > 0 && (this[this.t - 1] |= (1 0 && this[this.t - 1] == t;)--this.t }, i.prototype.dlShiftTo = function (t, e) { var i; for (i = this.t - 1; i >= 0; --i)e[i + t] = this[i]; for (i = t - 1; i >= 0; --i)e[i] = 0; e.t = this.t + t, e.s = this.s }, i.prototype.drShiftTo = function (t, e) { for (var i = t; i = 0; --i)e[i + o + 1] = this[i] >> s | h, h = (this[i] & n) = 0; --i)e[i] = 0; e[o] = h, e.t = this.t + o + 1, e.s = this.s, e.clamp() }, i.prototype.rShiftTo = function (t, e) { e.s = this.s; var i = Math.floor(t / this.DB); if (i >= this.t) e.t = 0; else { var r = t % this.DB, s = this.DB - r, n = (1 > r; for (var o = i + 1; o > r; r > 0 && (e[this.t - i - 1] |= (this.s & n) >= this.DB; if (t.t >= this.DB; r += this.s } else { for (r += this.s; i >= this.DB; r -= t.s } e.s = r 0 && (e[i++] = r), e.t = i, e.clamp() }, i.prototype.multiplyTo = function (t, e) { var r = this.abs(), s = t.abs(), n = r.t; for (e.t = n + s.t; --n >= 0;)e[n] = 0; for (n = 0; n = 0;)t[i] = 0; for (i = 0; i = e.DV && (t[i + e.t] -= e.DV, t[i + e.t + 1] = 1) } t.t > 0 && (t[t.t - 1] += e.am(i, e[i], t, 2 * i, 0, 1)), t.s = 0, t.clamp() }, i.prototype.divRemTo = function (t, e, s) { var n = t.abs(); if (!(n.t 0 ? (n.lShiftTo(a, h), o.lShiftTo(a, s)) : (n.copyTo(h), o.copyTo(s)); var l = h.t, c = h[l - 1]; if (0 != c) { var g = c * (1 1 ? h[l - 2] >> this.F2 : 0), y = this.FV / g, m = (1 = 0 && (s[s.t++] = 1, s.subTo(b, s)), i.ONE.dlShiftTo(l, b), b.subTo(h, h); h.t = 0;) { var F = s[--v] == c ? this.DM : Math.floor(s[v] * y + (s[v - 1] + d) * m); if ((s[v] += h.am(0, F, s, T, 0, l)) 0 && s.rShiftTo(a, s), u 0 ? this.DV - e : -e }, i.prototype.isEven = function () { return 0 == (this.t > 0 ? 1 & this[0] : this.s) }, i.prototype.exp = function (t, e) { if (t > 4294967295 || t = 0;)if (e.sqrTo(s, n), (t & 1 0) e.mulTo(n, o, s); else { var u = s; s = n, n = u } return e.revert(s) }, i.prototype.toString = function (t) { if (this.s 0) for (h > h) > 0 && (s = !0, n = f(i)); o >= 0;)h > (h += this.DB - e)) : (i = this[o] >> (h -= e) & r, h 0 && (s = !0), s && (n += f(i)); return s ? n : "0" }, i.prototype.negate = function () { var t = r(); return i.ZERO.subTo(this, t), t }, i.prototype.abs = function () { return this.s = 0;)if (0 != (e = this[i] - t[i])) return e; return 0 }, i.prototype.bitLength = function () { return this.t 0 && t.subTo(e, e), e }, i.prototype.modPowInt = function (t, e) { var i; return i = t 2 * this.m.t) return t.mod(this.m); if (t.compareTo(this.m) this.m.t + 1 && (t.t = this.m.t + 1, t.clamp()), this.mu.multiplyUpperTo(this.r2, this.m.t + 1, this.q3), this.m.multiplyLowerTo(this.q3, this.m.t + 1, this.r2); t.compareTo(this.r2) = 0;)t.subTo(this.m, t) }, x.prototype.mulTo = function (t, e, i) { t.multiplyTo(e, i), this.reduce(i) }, x.prototype.sqrTo = function (t, e) { t.squareTo(e), this.reduce(e) }; var w, S, I, D = [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], E = (1 > 8 & 255, S[I++] ^= t >> 16 & 255, S[I++] ^= t >> 24 & 255, I >= L && (I -= L) } if (i.prototype.chunkSize = function (t) { return Math.floor(Math.LN2 * this.DB / Math.log(t)) }, i.prototype.toRadix = function (t) { if (null == t && (t = 10), 0 == this.signum() || t 36) return "0"; var e = this.chunkSize(t), i = Math.pow(t, e), s = l(i), n = r(), o = r(), h = ""; for (this.divRemTo(s, n, o); n.signum() > 0;)h = (i + o.intValue()).toString(t).substr(1) + h, n.divRemTo(s, n, o); return o.intValue().toString(t) + h }, i.prototype.fromRadix = function (t, e) { this.fromInt(0), null == e && (e = 10); for (var r = this.chunkSize(e), s = Math.pow(e, r), n = !1, o = 0, h = 0, u = 0; u = r && (this.dMultiply(s), this.dAddOffset(h, 0), o = 0, h = 0)) } o > 0 && (this.dMultiply(Math.pow(e, o)), this.dAddOffset(h, 0)), n && i.ZERO.subTo(this, this) }, i.prototype.fromNumber = function (t, e, r) { if ("number" == typeof e) if (t t && this.subTo(i.ONE.shiftLeft(t - 1), this); else { var s = new Array, n = 7 & t; s.length = 1 + (t >> 3), e.nextBytes(s), n > 0 ? s[0] &= (1 >= this.DB; if (t.t >= this.DB; r += this.s } else { for (r += this.s; i >= this.DB; r += t.s } e.s = r 0 ? e[i++] = r : r = this.DV;)this[e] -= this.DV, ++e >= this.t && (this[this.t++] = 0), ++this[e] } }, i.prototype.multiplyLowerTo = function (t, e, i) { var r, s = Math.min(this.t + t.t, e); for (i.s = 0, i.t = s; s > 0;)i[--s] = 0; for (r = i.t - this.t; s = 0;)i[r] = 0; for (r = Math.max(e - this.t, 0); r 0) if (0 == e) i = this[0] % t; else for (var r = this.t - 1; r >= 0; --r)i = (e * i + this[r]) % t; return i }, i.prototype.millerRabin = function (t) { var e = this.subtract(i.ONE), s = e.getLowestSetBit(); if (s > 1) > D.length && (t = D.length); for (var o = r(), h = 0; h > 24 }, i.prototype.shortValue = function () { return 0 == this.t ? this.s : this[0] > 16 }, i.prototype.signum = function () { return this.s 0) for (r > r) != (this.s & this.DM) >> r && (e[s++] = i | this.s = 0;)r > (r += this.DB - 8)) : (i = this[t] >> (r -= 8) & 255, r 0 || i != this.s) && (e[s++] = i); return e }, i.prototype.equals = function (t) { return 0 == this.compareTo(t) }, i.prototype.min = function (t) { return this.compareTo(t) 0 ? this : t }, i.prototype.and = function (t) { var e = r(); return this.bitwiseTo(t, y, e), e }, i.prototype.or = function (t) { var e = r(); return this.bitwiseTo(t, m, e), e }, i.prototype.xor = function (t) { var e = r(); return this.bitwiseTo(t, d, e), e }, i.prototype.andNot = function (t) { var e = r(); return this.bitwiseTo(t, v, e), e }, i.prototype.not = function () { for (var t = r(), e = 0; e = this.t ? 0 != this.s : 0 != (this[e] & 1 1) { var y = r(); for (s.sqrTo(h[1], y); u = 0;) { for (n >= f ? m = t[v] >> n - f & a : (m = (t[v] & (1 0 && (m |= t[v - 1] >> this.DB + n - f)), u = i; 0 == (1 & m);)m >>= 1, --u; if ((n -= u) 1;)s.sqrTo(o, b), s.sqrTo(b, o), u -= 2; u > 0 ? s.sqrTo(o, b) : (d = o, o = b, b = d), s.mulTo(b, h[m], o) } for (; v >= 0 && 0 == (t[v] & 1 = 0 ? (r.subTo(s, r), e && n.subTo(h, n), o.subTo(u, o)) : (s.subTo(r, s), e && h.subTo(n, h), u.subTo(o, u)) } return 0 != s.compareTo(i.ONE) ? i.ZERO : u.compareTo(t) >= 0 ? u.subtract(t) : u.signum() 0 && (e.rShiftTo(n, e), i.rShiftTo(n, i)); e.signum() > 0;)(s = e.getLowestSetBit()) > 0 && e.rShiftTo(s, e), (s = i.getLowestSetBit()) > 0 && i.rShiftTo(s, i), e.compareTo(i) >= 0 ? (e.subTo(i, e), e.rShiftTo(1, e)) : (i.subTo(e, i), i.rShiftTo(1, i)); return n > 0 && i.lShiftTo(n, i), i }, i.prototype.isProbablePrime = function (t) { var e, i = this.abs(); if (1 == i.t && i[0] >> 8, S[I++] = 255 & A; I = 0, q() } function V() { if (null == w) { for (q(), (w = new k).init(S), I = 0; I 0; --t) { n = n.twice(); let r = i.testBit(t); r != e.testBit(t) && (n = n.add(r ? this : s)) } return n } multiplyTwo(t, e, i) { let r = t.bitLength() > i.bitLength() ? t.bitLength() - 1 : i.bitLength() - 1, s = this.curve.getInfinity(), n = this.add(e); for (; r >= 0;)s = s.twice(), t.testBit(r) ? s = i.testBit(r) ? s.add(n) : s.add(this) : i.testBit(r) && (s = s.add(e)), --r; return s } static decodeFromHex(t, e) { let i = e.length - 2, s = e.substr(2, i / 2), n = e.substr(2 + i / 2, i / 2), h = new r(s, 16), u = new r(n, 16); return new o(t, t.fromBigInteger(h), t.fromBigInteger(u)) } } t.exports = { ECFieldElementFp: n, ECPointFp: o, ECCurveFp: class { constructor(t, e, i) { this.q = t, this.a = this.fromBigInteger(e), this.b = this.fromBigInteger(i), this.infinity = new o(this, null, null) } getQ() { return this.q } getA() { return this.a } getB() { return this.b } equals(t) { return t === this || this.q.equals(t.q) && this.a.equals(t.a) && this.b.equals(t.b) } getInfinity() { return this.infinity } fromBigInteger(t) { return new n(this.q, t) } decodePointHex(t) { switch (parseInt(t.substr(0, 2), 16)) { case 0: return this.infinity; case 2: case 3: return null; case 4: case 6: case 7: let e = (t.length - 2) / 2, i = t.substr(2, e), s = t.substr(e + 2, e); return new o(this, this.fromBigInteger(new r(i, 16)), this.fromBigInteger(new r(s, 16))); default: return null } } } } }, function (t, e, i) { const { BigInteger: r, SecureRandom: s } = i(0), { ECCurveFp: n } = i(2); let o = new s, { G: h, n: u } = f(); function f() { let t = new r("FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFF", 16), e = new r("FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFC", 16), i = new r("28E9FA9E9D9F5E344D5A9E4BCF6509A7F39789F515AB8F92DDBCBD414D940E93", 16), s = new r("FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFF7203DF6B21C6052B53BBF40939D54123", 16), o = new n(t, e, i), h = o.decodePointHex("0432C4AE2C1F1981195F9904466A39C9948FE30BBFF2660BE1715A4589334C74C7BC3736A2F4F6779C59BDCEE36B692153D0A9877CC62A474002DF32E52139F0A0"); return { curve: o, G: h, n: s } } function a(t, e) { return t.length >= e ? t : new Array(e - t.length + 1).join("0") + t } t.exports = { generateEcparam: f, generateKeyPairHex: function () { let t = new r(u.bitLength(), o).mod(u.subtract(r.ONE)).add(r.ONE), e = a(t.toString(16), 64), i = h.multiply(t); return { privateKey: e, publicKey: "04" + a(i.getX().toBigInteger().toString(16), 64) + a(i.getY().toBigInteger().toString(16), 64) } }, parseUtf8StringToHex: function (t) { let e = (t = unescape(encodeURIComponent(t))).length, i = []; for (let r = 0; r >> 2] |= (255 & t.charCodeAt(r)) >> 2] >>> 24 - t % 4 * 8 & 255; r.push((e >>> 4).toString(16)), r.push((15 & e).toString(16)) } return r.join("") }, parseArrayBufferToHex: function (t) { return Array.prototype.map.call(new Uint8Array(t), t => ("00" + t.toString(16)).slice(-2)).join("") }, leftPad: a, arrayToHex: function (t) { let e = [], i = 0; for (let r = 0; r >> 3] |= parseInt(t[i]) >> 2] >>> 24 - i % 4 * 8 & 255; r.push((t >>> 4).toString(16)), r.push((15 & t).toString(16)) } return r.join("") }, arrayToUtf8: function (t) { let e = [], i = 0; for (let r = 0; r >> 3] |= parseInt(t[i]) >> 2] >>> 24 - r % 4 * 8 & 255; i.push(String.fromCharCode(t)) } return decodeURIComponent(escape(i.join(""))) } catch (t) { throw new Error("Malformed UTF-8 data") } }, hexToArray: function (t) { let e = [], i = t.length; i % 2 != 0 && (t = a(t, i + 1)), i = t.length; for (let r = 0; r this.maxValue) { let e = Number(t).toString(2), i = e.substr(e.length - 31, 31), r = ""; for (let t = 0; t 255) { let e = Number(t).toString(2); return parseInt(e.substr(e.length - 8, 8), 2) } return t } }; t.exports = class { constructor() { this.xBuf = new Array, this.xBufOff = 0, this.byteCount = 0, this.DIGEST_LENGTH = 32, this.v0 = [1937774191, 1226093241, 388252375, 3666478592, 2842636476, 372324522, 3817729613, 2969243214], this.v0 = [1937774191, 1226093241, 388252375, -628488704, -1452330820, 372324522, -477237683, -1325724082], this.v = new Array(8), this.v_ = new Array(8), this.X0 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], this.X = new Array(68), this.xOff = 0, this.T_00_15 = 2043430169, this.T_16_63 = 2055708042, arguments.length > 0 ? this.initDigest(arguments[0]) : this.init() } init() { this.xBuf = new Array(4), this.reset() } initDigest(t) { this.xBuf = [].concat(t.xBuf), this.xBufOff = t.xBufOff, this.byteCount = t.byteCount, n(t.X, 0, this.X, 0, t.X.length), this.xOff = t.xOff, n(t.v, 0, this.v, 0, t.v.length) } getDigestSize() { return this.DIGEST_LENGTH } reset() { this.byteCount = 0, this.xBufOff = 0; for (let t in this.xBuf) this.xBuf[t] = null; n(this.v0, 0, this.v, 0, this.v0.length), this.xOff = 0, n(this.X0, 0, this.X, 0, this.X0.length) } processBlock() { let t, e = this.X, i = new Array(64); for (t = 16; t 14 && this.processBlock(), this.X[14] = this.urShiftLong(t, 32), this.X[15] = 4294967295 & t } intToBigEndian(t, e, i) { e[i] = o.parseByte(this.urShift(t, 24)), e[++i] = o.parseByte(this.urShift(t, 16)), e[++i] = o.parseByte(this.urShift(t, 8)), e[++i] = o.parseByte(t) } doFinal(t, e) { this.finish(); for (let i = 0; i 0;)this.update(t[e]), e++, i--; for (; i > this.xBuf.length;)this.processWord(t, e), e += this.xBuf.length, i -= this.xBuf.length, this.byteCount += this.xBuf.length; for (; i > 0;)this.update(t[e]), e++, i-- } finish() { let t = this.byteCount o.maxValue || t = 0 ? t >> e : (t >> e) + (2 = 0) i = s.shiftRight(e).intValue(); else { let s = new r; s.fromInt(2); let n = ~e, o = ""; if (n > e); let u = new r("10" + o, 2); o = u.toRadix(10), i = u.add(h).toRadix(10) } else i = (t >> e) + (o = s.shiftLeft(~e).intValue()) } return i } getZ(t, e) { let i = s.parseUtf8StringToHex("1234567812345678"), r = 4 * i.length; this.update(r >> 8 & 255), this.update(255 & r); let n = s.hexToArray(i); this.blockUpdate(n, 0, n.length); let o = s.hexToArray(t.curve.a.toBigInteger().toRadix(16)), h = s.hexToArray(t.curve.b.toBigInteger().toRadix(16)), u = s.hexToArray(t.getX().toBigInteger().toRadix(16)), f = s.hexToArray(t.getY().toBigInteger().toRadix(16)), a = s.hexToArray(e.substr(0, 64)), l = s.hexToArray(e.substr(64, 64)); this.blockUpdate(o, 0, o.length), this.blockUpdate(h, 0, h.length), this.blockUpdate(u, 0, u.length), this.blockUpdate(f, 0, f.length), this.blockUpdate(a, 0, a.length), this.blockUpdate(l, 0, l.length); let p = new Array(this.getDigestSize()); return this.doFinal(p, 0), p } } }, function (t, e, i) { "use strict"; i.r(e), i.d(e, "smEncrypt", function () { return s }); var r = i(1), s = { sm2Encrypt: function (t, e) { var i = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : 0; return "04" + r.sm2.doEncrypt(t, e, i) }, sm2Decrypt: function (t, e) { var i = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : 0, s = t.toLowerCase().replace(/^04/, ""); return r.sm2.doDecrypt(s, e.toLowerCase(), i) }, sm2: r.sm2, sm3: r.sm3, sm4: r.sm4 } }, function (t, e) { var i; i = function () { return this }(); try { i = i || new Function("return this")() } catch (t) { "object" == typeof window && (i = window) } t.exports = i }, function (t, e, i) { const { BigInteger: r } = i(0), { encodeDer: s, decodeDer: n } = i(8), { ECPointFp: o } = i(2), h = i(4), u = i(9), f = i(3); let { G: a, curve: l, n: p } = f.generateEcparam(); const c = 0; function g(t, e) { let i = new h, r = (new h).getZ(a, e.substr(2, 128)), s = f.hexToArray(f.arrayToHex(r).toString()), n = t, o = f.hexToArray(n), u = new Array(i.getDigestSize()); return i.blockUpdate(s, 0, s.length), i.blockUpdate(o, 0, o.length), i.doFinal(u, 0), f.arrayToHex(u).toString() } function y() { let t = f.generateKeyPairHex(), e = o.decodeFromHex(l, t.publicKey); return t.k = new r(t.privateKey, 16), t.x1 = e.getX().toBigInteger(), t } t.exports = { generateKeyPairHex: f.generateKeyPairHex, doEncrypt: function (t, e, i = 1) { let r = new u; t = f.hexToArray(f.parseUtf8StringToHex(t)), e.length > 128 && (e = e.substr(e.length - 128)); let s = e.substr(0, 64), n = e.substr(64); e = r.createPoint(s, n); let o = r.initEncipher(e); r.encryptBlock(t); let h = f.arrayToHex(t), a = new Array(32); return r.doFinal(a), a = f.arrayToHex(a), i === c ? o + h + a : o + a + h }, doDecrypt: function (t, e, i = 1) { let s = new u(i); e = new r(e, 16); let n = t.substr(0, 64), o = t.substr(0 + n.length, 64), h = n.length + o.length, a = t.substr(h, 64), l = t.substr(h + 64); i === c && (a = t.substr(t.length - 64), l = t.substr(h, t.length - h - 64)); let p = f.hexToArray(l), g = s.createPoint(n, o); s.initDecipher(e, g), s.decryptBlock(p); let y = new Array(32); if (s.doFinal(y), f.arrayToHex(y) == a) return f.arrayToUtf8(p); return "" }, doSignature: function (t, e, { pointPool: i, der: n, hash: o, publicKey: h } = {}) { let u = "string" == typeof t ? f.parseUtf8StringToHex(t) : f.parseArrayBufferToHex(t); o && (u = g(u, h = h || function (t) { let e = a.multiply(new r(t, 16)), i = f.leftPad(e.getX().toBigInteger().toString(16), 64), s = f.leftPad(e.getY().toBigInteger().toString(16), 64); return "04" + i + s }(e))); let l = new r(e, 16), c = new r(u, 16), m = null, d = null, v = null; do { do { let t; m = (t = i && i.length ? i.pop() : y()).k, d = c.add(t.x1).mod(p) } while (d.equals(r.ZERO) || d.add(m).equals(p)); v = l.add(r.ONE).modInverse(p).multiply(m.subtract(d.multiply(l))).mod(p) } while (v.equals(r.ZERO)); return n ? s(d, v) : f.leftPad(d.toString(16), 64) + f.leftPad(v.toString(16), 64) }, doVerifySignature: function (t, e, i, { der: s, hash: h } = {}) { let u, c, y = "string" == typeof t ? f.parseUtf8StringToHex(t) : f.parseArrayBufferToHex(t); if (h && (y = g(y, i)), s) { let t = n(e); u = t.r, c = t.s } else u = new r(e.substring(0, 64), 16), c = new r(e.substring(64), 16); let m = o.decodeFromHex(l, i), d = new r(y, 16), v = u.add(c).mod(p); if (v.equals(r.ZERO)) return !1; let T = a.multiply(c).add(m.multiply(v)), b = d.add(T.getX().toBigInteger()).mod(p); return u.equals(b) }, getPoint: y } }, function (t, e, i) { const { BigInteger: r } = i(0); class s { constructor() { this.isModified = !0, this.hTLV = null, this.hT = "00", this.hL = "00", this.hV = "" } getLengthHexFromValue() { let t = this.hV.length / 2, e = t.toString(16); if (e.length % 2 == 1 && (e = "0" + e), t = 2 * s) break; if (o >= 200) break; i.push(h), n = h, o++ } return i }(t, 0), i = e[0], s = e[1], n = a(t, i), o = a(t, s); return { r: new r(n, 16), s: new r(o, 16) } } } }, function (t, e, i) { const { BigInteger: r } = i(0), { ECPointFp: s } = i(2), n = i(4), o = i(3); t.exports = class { constructor() { this.ct = 1, this.p2 = null, this.sm3keybase = null, this.sm3c3 = null, this.key = new Array(32), this.keyOff = 0 } reset() { this.sm3keybase = new n, this.sm3c3 = new n; let t = o.hexToArray(this.p2.getX().toBigInteger().toRadix(16)), e = o.hexToArray(this.p2.getY().toBigInteger().toRadix(16)); this.sm3keybase.blockUpdate(t, 0, t.length), this.sm3c3.blockUpdate(t, 0, t.length), this.sm3keybase.blockUpdate(e, 0, e.length), this.ct = 1, this.nextKey() } nextKey() { let t = new n(this.sm3keybase); t.update(this.ct >> 24 & 255), t.update(this.ct >> 16 & 255), t.update(this.ct >> 8 & 255), t.update(255 & this.ct), t.doFinal(this.key, 0), this.keyOff = 0, this.ct++ } initEncipher(t) { let e = o.generateKeyPairHex(), i = new r(e.privateKey, 16), s = e.publicKey; return this.p2 = t.multiply(i), this.reset(), s.length > 128 && (s = s.substr(s.length - 128)), s } encryptBlock(t) { this.sm3c3.blockUpdate(t, 0, t.length); for (let e = 0; e = e ? t : new Array(e - t.length + 1).join("0") + t } function s(t) { let e = ""; for (let i = 0; i = 0; t--)o = i(r[t], s[t], o), n[t] = o[0]; return n.join("") } function h(t, e) { return o(t, e, (t, e) => [t === e ? "0" : "1"]) } function u(t, e) { return o(t, e, (t, e) => ["1" === t && "1" === e ? "1" : "0"]) } function f(t, e) { return o(t, e, (t, e) => ["1" === t || "1" === e ? "1" : "0"]) } function a(t, e) { return o(t, e, (t, e, i) => { const r = i ? i[1] : "0"; return t !== e ? ["0" === r ? "1" : "0", r] : [r, t] }) } function l(t) { return (...e) => e.reduce((e, i) => t(e, i)) } function p(t) { return l(h)(t, n(t, 9), n(t, 17)) } function c(t, e, i, r) { return r >= 0 && r = 0 && r ["1" === t ? "0" : "1"]), i)) } function y(t) { return s(t >= 0 && t = 448 ? 512 - n % 448 - 1 : 448 - n - 1)}${r(i.toString(2), 64)}`.toString(), h = (i + n + 65) / 512; let u = s("7380166f4914b2b9172442d7da8a0600a96f30bc163138aae38dee4db0fb0e4e"); for (let t = 0; t >> 32 - e } function u(t) { return (255 & n[t >>> 24 & 255]) >> 16 & 255]) >> 8 & 255]) >> 24 & 255, e[t + 1] = n[3 - t / 4] >>> 16 & 255, e[t + 2] = n[3 - t / 4] >>> 8 & 255, e[t + 3] = 255 & n[3 - t / 4] } function p(t, e, n) { let h = [], f = 0, p = new Array(r); !function (t, e, r) { let s, n, h = new Array(4), f = new Array(4); for (let e = 0; e = s;) { l(c = t.slice(f, f + 16), g, p); for (let t = 0; t p(t, e, 1), decrypt: (t, e) => p(t, e, 0) } }]) });
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
机房租用,北京机房租用,IDC机房托管, http://www.e1idc.net