本文整理汇总了Java中sun.security.ec.NamedCurve.knownECParameterSpecs方法的典型用法代码示例。如果您正苦于以下问题:Java NamedCurve.knownECParameterSpecs方法的具体用法?Java NamedCurve.knownECParameterSpecs怎么用?Java NamedCurve.knownECParameterSpecs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sun.security.ec.NamedCurve
的用法示例。
在下文中一共展示了NamedCurve.knownECParameterSpecs方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import sun.security.ec.NamedCurve; //导入方法依赖的package包/类
public void main(Provider p) throws Exception {
if (p.getService("KeyAgreement", "ECDH") == null) {
System.out.println("Not supported by provider, skipping");
return;
}
Random random = new Random();
byte[] data = new byte[2048];
random.nextBytes(data);
Collection<? extends ECParameterSpec> curves =
NamedCurve.knownECParameterSpecs();
for (ECParameterSpec params : curves) {
System.out.println("Testing " + params + "...");
KeyPairGenerator kpg = KeyPairGenerator.getInstance("EC", p);
kpg.initialize(params);
KeyPair kp1, kp2;
kp1 = kpg.generateKeyPair();
kp2 = kpg.generateKeyPair();
testSigning(p, "SHA1withECDSA", data, kp1, kp2);
testSigning(p, "SHA256withECDSA", data, kp1, kp2);
testSigning(p, "SHA384withECDSA", data, kp1, kp2);
testSigning(p, "SHA512withECDSA", data, kp1, kp2);
// System.out.println();
KeyAgreement ka1 = KeyAgreement.getInstance("ECDH", p);
ka1.init(kp1.getPrivate());
ka1.doPhase(kp2.getPublic(), true);
byte[] secret1 = ka1.generateSecret();
KeyAgreement ka2 = KeyAgreement.getInstance("ECDH", p);
ka2.init(kp2.getPrivate());
ka2.doPhase(kp1.getPublic(), true);
byte[] secret2 = ka2.generateSecret();
if (Arrays.equals(secret1, secret2) == false) {
throw new Exception("Secrets do not match");
}
}
System.out.println("OK");
}