public class Signverify
implements FlexlmConstants
{
static final String CVSId = "$Id";
protected static String certicomName;
protected static final String signatureAlgorithmName = "ECDSA";
public static boolean pubkeyVerify(byte abyte0[], byte abyte1[], VendorInfo vendorinfo, int i)
throws FlexlmException
{
String s = initCerticom();
if (s == null)
throw new FlexlmException(-103, 1);
String s1;
switch (i)
{
case 2: // '\002'
s1 = "sect113r1";
break;
case 3: // '\003'
s1 = "ec163a02";
break;
case 4: // '\004'
s1 = "ec239a03";
break;
default:
throw new FlexlmException(-103, 2);
}
SystemConfig systemconfig = SystemConfig.getConfig();
systemconfig.setCurve(s1); //设置ecc曲线
systemconfig.setConformance(16);
systemconfig.setPtCompression(2);
systemconfig.setFormat(10);
java.security.PublicKey publickey = vendorimsg.getPublicKey(i); //提取公钥
if (publickey == null)
throw new FlexlmException(15, 28);
byte abyte2[] = publickey.getEncoded(); //L_G译码
X509EncodedKeySpec x509encodedkeyspec = new X509EncodedKeySpec(abyte2);
KeyFactory keyfactory;
keyfactory = KeyFactory.getInstance("ECDSA");
java.security.PublicKey publickey1;
publickey1 = keyfactory.generatePublic(x509encodedkeyspec); //生成ecc公钥,程序带的是压缩的(Gx,Gy)
boolean flag;
Signature signature = Signature.getInstance("ECDSA", s);
signature.initVerify(publickey1);
signature.update(abyte0);
flag = signature.verify(abyte1); //如果验证通过返回1
return flag;
}
protected static String initCerticom()
{
if (certicomName != null)
{
return certicomName;
} else
{
Certicom certicom = new Certicom();
if (Security.addProvider(certicom) >= 0);
certicomName = certicom.getName();
return certicomName;
}
}
}
[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!