本文整理汇总了Java中sun.security.ec.NamedCurve类的典型用法代码示例。如果您正苦于以下问题:Java NamedCurve类的具体用法?Java NamedCurve怎么用?Java NamedCurve使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
NamedCurve类属于sun.security.ec包,在下文中一共展示了NamedCurve类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initialize
import sun.security.ec.NamedCurve; //导入依赖的package包/类
@Override
public void initialize(AlgorithmParameterSpec params, SecureRandom random)
throws InvalidAlgorithmParameterException {
if (params instanceof ECParameterSpec) {
this.params = ECParameters.getNamedCurve((ECParameterSpec)params);
if (this.params == null) {
throw new InvalidAlgorithmParameterException(
"Unsupported curve: " + params);
}
} else if (params instanceof ECGenParameterSpec) {
String name = ((ECGenParameterSpec)params).getName();
this.params = NamedCurve.getECParameterSpec(name);
if (this.params == null) {
throw new InvalidAlgorithmParameterException(
"Unknown curve name: " + name);
}
} else {
throw new InvalidAlgorithmParameterException(
"ECParameterSpec or ECGenParameterSpec required for EC");
}
this.keySize =
((ECParameterSpec)this.params).getCurve().getField().getFieldSize();
this.random = random;
}
示例2: getECParameterSpec
import sun.security.ec.NamedCurve; //导入依赖的package包/类
static ECParameterSpec getECParameterSpec(String namedCurveOid) {
return NamedCurve.getECParameterSpec(namedCurveOid);
}
示例3: getECParameterSpec
import sun.security.ec.NamedCurve; //导入依赖的package包/类
static ECParameterSpec getECParameterSpec(String name) {
return NamedCurve.getECParameterSpec(name);
}
示例4: 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");
}