|
@@ -21,13 +21,11 @@ namespace AnHuiMI.Common
|
|
|
{
|
|
|
public class GmUtil
|
|
|
{
|
|
|
- // Token: 0x06000006 RID: 6 RVA: 0x0000217E File Offset: 0x0000037E
|
|
|
public static byte[] SignSm3WithSm2(byte[] msg, byte[] userId, AsymmetricKeyParameter privateKey)
|
|
|
{
|
|
|
return GmUtil.RsAsn1ToPlainByteArray(GmUtil.SignSm3WithSm2Asn1Rs(msg, userId, privateKey));
|
|
|
}
|
|
|
|
|
|
- // Token: 0x06000007 RID: 7 RVA: 0x00002190 File Offset: 0x00000390
|
|
|
public static byte[] SignSm3WithSm2Asn1Rs(byte[] msg, byte[] userId, AsymmetricKeyParameter privateKey)
|
|
|
{
|
|
|
byte[] result;
|
|
@@ -45,13 +43,11 @@ namespace AnHuiMI.Common
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
- // Token: 0x06000008 RID: 8 RVA: 0x000021E0 File Offset: 0x000003E0
|
|
|
public static bool VerifySm3WithSm2(byte[] msg, byte[] userId, byte[] rs, AsymmetricKeyParameter publicKey)
|
|
|
{
|
|
|
return rs != null && msg != null && userId != null && rs.Length == 64 && GmUtil.VerifySm3WithSm2Asn1Rs(msg, userId, GmUtil.RsPlainByteArrayToAsn1(rs), publicKey);
|
|
|
}
|
|
|
|
|
|
- // Token: 0x06000009 RID: 9 RVA: 0x00002204 File Offset: 0x00000404
|
|
|
public static bool VerifySm3WithSm2Asn1Rs(byte[] msg, byte[] userId, byte[] sign, AsymmetricKeyParameter publicKey)
|
|
|
{
|
|
|
bool result;
|
|
@@ -69,7 +65,6 @@ namespace AnHuiMI.Common
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
- // Token: 0x0600000A RID: 10 RVA: 0x00002250 File Offset: 0x00000450
|
|
|
private static byte[] ChangeC1C2C3ToC1C3C2(byte[] c1c2c3)
|
|
|
{
|
|
|
int num = (GmUtil.x9ECParameters.Curve.FieldSize + 7) / 8 * 2 + 1;
|
|
@@ -80,7 +75,6 @@ namespace AnHuiMI.Common
|
|
|
return array;
|
|
|
}
|
|
|
|
|
|
- // Token: 0x0600000B RID: 11 RVA: 0x000022B0 File Offset: 0x000004B0
|
|
|
private static byte[] ChangeC1C3C2ToC1C2C3(byte[] c1c3c2)
|
|
|
{
|
|
|
int num = (GmUtil.x9ECParameters.Curve.FieldSize + 7) / 8 * 2 + 1;
|
|
@@ -91,19 +85,16 @@ namespace AnHuiMI.Common
|
|
|
return array;
|
|
|
}
|
|
|
|
|
|
- // Token: 0x0600000C RID: 12 RVA: 0x0000230D File Offset: 0x0000050D
|
|
|
public static byte[] Sm2Decrypt(byte[] data, AsymmetricKeyParameter key)
|
|
|
{
|
|
|
return GmUtil.Sm2DecryptOld(GmUtil.ChangeC1C3C2ToC1C2C3(data), key);
|
|
|
}
|
|
|
|
|
|
- // Token: 0x0600000D RID: 13 RVA: 0x0000231B File Offset: 0x0000051B
|
|
|
public static byte[] Sm2Encrypt(byte[] data, AsymmetricKeyParameter key)
|
|
|
{
|
|
|
return GmUtil.ChangeC1C2C3ToC1C3C2(GmUtil.Sm2EncryptOld(data, key));
|
|
|
}
|
|
|
|
|
|
- // Token: 0x0600000E RID: 14 RVA: 0x0000232C File Offset: 0x0000052C
|
|
|
public static byte[] Sm2EncryptOld(byte[] data, AsymmetricKeyParameter pubkey)
|
|
|
{
|
|
|
byte[] result;
|
|
@@ -120,7 +111,6 @@ namespace AnHuiMI.Common
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
- // Token: 0x0600000F RID: 15 RVA: 0x00002374 File Offset: 0x00000574
|
|
|
public static byte[] Sm2DecryptOld(byte[] data, AsymmetricKeyParameter key)
|
|
|
{
|
|
|
byte[] result;
|
|
@@ -137,7 +127,6 @@ namespace AnHuiMI.Common
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
- // Token: 0x06000010 RID: 16 RVA: 0x000023B4 File Offset: 0x000005B4
|
|
|
public static byte[] Sm3(byte[] bytes)
|
|
|
{
|
|
|
byte[] result;
|
|
@@ -154,7 +143,6 @@ namespace AnHuiMI.Common
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
- // Token: 0x06000011 RID: 17 RVA: 0x000023F0 File Offset: 0x000005F0
|
|
|
private static byte[] BigIntToFixexLengthBytes(BigInteger rOrS)
|
|
|
{
|
|
|
byte[] array = rOrS.ToByteArray();
|
|
@@ -176,7 +164,6 @@ namespace AnHuiMI.Common
|
|
|
throw new ArgumentException("err rs: " + Hex.ToHexString(array));
|
|
|
}
|
|
|
|
|
|
- // Token: 0x06000012 RID: 18 RVA: 0x00002464 File Offset: 0x00000664
|
|
|
private static byte[] RsAsn1ToPlainByteArray(byte[] rsDer)
|
|
|
{
|
|
|
Asn1Sequence instance = Asn1Sequence.GetInstance(rsDer);
|
|
@@ -188,7 +175,6 @@ namespace AnHuiMI.Common
|
|
|
return array3;
|
|
|
}
|
|
|
|
|
|
- // Token: 0x06000013 RID: 19 RVA: 0x000024C8 File Offset: 0x000006C8
|
|
|
private static byte[] RsPlainByteArrayToAsn1(byte[] sign)
|
|
|
{
|
|
|
if (sign.Length != 64)
|
|
@@ -212,7 +198,6 @@ namespace AnHuiMI.Common
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
- // Token: 0x06000014 RID: 20 RVA: 0x00002550 File Offset: 0x00000750
|
|
|
public static AsymmetricCipherKeyPair GenerateKeyPair()
|
|
|
{
|
|
|
AsymmetricCipherKeyPair result;
|
|
@@ -229,13 +214,11 @@ namespace AnHuiMI.Common
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
- // Token: 0x06000015 RID: 21 RVA: 0x00002598 File Offset: 0x00000798
|
|
|
public static ECPrivateKeyParameters GetPrivatekeyFromD(BigInteger d)
|
|
|
{
|
|
|
return new ECPrivateKeyParameters(d, GmUtil.ecDomainParameters);
|
|
|
}
|
|
|
|
|
|
- // Token: 0x06000016 RID: 22 RVA: 0x000025A8 File Offset: 0x000007A8
|
|
|
public static ECPublicKeyParameters GetPublickeyFromXY(byte[] pubkey)
|
|
|
{
|
|
|
ECPoint q = GMNamedCurves.GetByName("SM2P256V1").Curve.DecodePoint(pubkey);
|
|
@@ -243,13 +226,11 @@ namespace AnHuiMI.Common
|
|
|
return new ECPublicKeyParameters(q, parameters);
|
|
|
}
|
|
|
|
|
|
- // Token: 0x06000017 RID: 23 RVA: 0x000025F4 File Offset: 0x000007F4
|
|
|
public static ECPublicKeyParameters GetPublickeyFromXY(BigInteger x, BigInteger y)
|
|
|
{
|
|
|
return new ECPublicKeyParameters(GmUtil.x9ECParameters.Curve.CreatePoint(x, y), GmUtil.ecDomainParameters);
|
|
|
}
|
|
|
|
|
|
- // Token: 0x06000018 RID: 24 RVA: 0x00002614 File Offset: 0x00000814
|
|
|
public static AsymmetricKeyParameter GetPublickeyFromX509File(FileInfo file)
|
|
|
{
|
|
|
FileStream fileStream = null;
|
|
@@ -271,7 +252,6 @@ namespace AnHuiMI.Common
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- // Token: 0x06000019 RID: 25 RVA: 0x00002670 File Offset: 0x00000870
|
|
|
private static byte[] ToByteArray(int i)
|
|
|
{
|
|
|
return new byte[]
|
|
@@ -283,7 +263,6 @@ namespace AnHuiMI.Common
|
|
|
};
|
|
|
}
|
|
|
|
|
|
- // Token: 0x0600001A RID: 26 RVA: 0x000026A8 File Offset: 0x000008A8
|
|
|
private static byte[] Join(params byte[][] byteArrays)
|
|
|
{
|
|
|
List<byte> list = new List<byte>();
|
|
@@ -294,7 +273,6 @@ namespace AnHuiMI.Common
|
|
|
return list.ToArray();
|
|
|
}
|
|
|
|
|
|
- // Token: 0x0600001B RID: 27 RVA: 0x000026D8 File Offset: 0x000008D8
|
|
|
private static byte[] KDF(byte[] Z, int klen)
|
|
|
{
|
|
|
int num = 1;
|
|
@@ -332,7 +310,6 @@ namespace AnHuiMI.Common
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- // Token: 0x0600001C RID: 28 RVA: 0x000027A0 File Offset: 0x000009A0
|
|
|
public static byte[] Sm4DecryptCBC(byte[] keyBytes, byte[] cipher, byte[] iv, string algo)
|
|
|
{
|
|
|
if (keyBytes.Length != 16)
|
|
@@ -362,7 +339,6 @@ namespace AnHuiMI.Common
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
- // Token: 0x0600001D RID: 29 RVA: 0x00002820 File Offset: 0x00000A20
|
|
|
public static byte[] Sm4EncryptCBC(byte[] keyBytes, byte[] plain, byte[] iv, string algo)
|
|
|
{
|
|
|
if (keyBytes.Length != 16)
|
|
@@ -392,7 +368,6 @@ namespace AnHuiMI.Common
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
- // Token: 0x0600001E RID: 30 RVA: 0x000028A0 File Offset: 0x00000AA0
|
|
|
public static byte[] Sm4EncryptECB(byte[] keyBytes, byte[] plain, string algo)
|
|
|
{
|
|
|
if (keyBytes.Length != 16)
|
|
@@ -414,7 +389,6 @@ namespace AnHuiMI.Common
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
- // Token: 0x0600001F RID: 31 RVA: 0x000028FC File Offset: 0x00000AFC
|
|
|
public static byte[] Sm4DecryptECB(byte[] keyBytes, byte[] cipher, string algo)
|
|
|
{
|
|
|
if (cipher.Length % 16 != 0)
|
|
@@ -436,7 +410,6 @@ namespace AnHuiMI.Common
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
- // Token: 0x06000020 RID: 32 RVA: 0x00002958 File Offset: 0x00000B58
|
|
|
public static GmUtil.Sm2Cert readSm2File(byte[] pem, string pwd)
|
|
|
{
|
|
|
GmUtil.Sm2Cert sm2Cert = new GmUtil.Sm2Cert();
|
|
@@ -463,7 +436,6 @@ namespace AnHuiMI.Common
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
- // Token: 0x06000021 RID: 33 RVA: 0x00002A4C File Offset: 0x00000C4C
|
|
|
public static GmUtil.Sm2Cert ReadSm2X509Cert(byte[] cert)
|
|
|
{
|
|
|
GmUtil.Sm2Cert sm2Cert = new GmUtil.Sm2Cert();
|
|
@@ -482,7 +454,6 @@ namespace AnHuiMI.Common
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
- // Token: 0x06000022 RID: 34 RVA: 0x00002AA4 File Offset: 0x00000CA4
|
|
|
public static byte[] ZeroIv(string algo)
|
|
|
{
|
|
|
byte[] result;
|
|
@@ -499,7 +470,6 @@ namespace AnHuiMI.Common
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
- // Token: 0x06000023 RID: 35 RVA: 0x00002AE4 File Offset: 0x00000CE4
|
|
|
public static void Main2(string[] s)
|
|
|
{
|
|
|
foreach (object obj in GMNamedCurves.Names)
|
|
@@ -533,37 +503,25 @@ namespace AnHuiMI.Common
|
|
|
GmUtil.SignSm3WithSm2(bytes3, bytes2, (ECPrivateKeyParameters)sm2Cert.privateKey);
|
|
|
}
|
|
|
|
|
|
- // Token: 0x04000003 RID: 3
|
|
|
private static X9ECParameters x9ECParameters = GMNamedCurves.GetByName("sm2p256v1");
|
|
|
|
|
|
- // Token: 0x04000004 RID: 4
|
|
|
private static ECDomainParameters ecDomainParameters = new ECDomainParameters(GmUtil.x9ECParameters.Curve, GmUtil.x9ECParameters.G, GmUtil.x9ECParameters.N);
|
|
|
|
|
|
- // Token: 0x04000005 RID: 5
|
|
|
- private const int RS_LEN = 32;
|
|
|
|
|
|
- // Token: 0x04000006 RID: 6
|
|
|
public const string SM4_ECB_NOPADDING = "SM4/ECB/NoPadding";
|
|
|
|
|
|
- // Token: 0x04000007 RID: 7
|
|
|
public const string SM4_ECB_PKCS7PADDING = "SM4/ECB/PKCS7Padding";
|
|
|
|
|
|
- // Token: 0x04000008 RID: 8
|
|
|
public const string SM4_CBC_NOPADDING = "SM4/CBC/NoPadding";
|
|
|
|
|
|
- // Token: 0x04000009 RID: 9
|
|
|
public const string SM4_CBC_PKCS7PADDING = "SM4/CBC/PKCS7Padding";
|
|
|
|
|
|
- // Token: 0x02000011 RID: 17
|
|
|
public class Sm2Cert
|
|
|
{
|
|
|
- // Token: 0x04000073 RID: 115
|
|
|
public AsymmetricKeyParameter privateKey;
|
|
|
|
|
|
- // Token: 0x04000074 RID: 116
|
|
|
public AsymmetricKeyParameter publicKey;
|
|
|
|
|
|
- // Token: 0x04000075 RID: 117
|
|
|
public string certId;
|
|
|
}
|
|
|
}
|