本文整理汇总了Java中org.spongycastle.jce.spec.ECParameterSpec类的典型用法代码示例。如果您正苦于以下问题:Java ECParameterSpec类的具体用法?Java ECParameterSpec怎么用?Java ECParameterSpec使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ECParameterSpec类属于org.spongycastle.jce.spec包,在下文中一共展示了ECParameterSpec类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isSignatureValid
import org.spongycastle.jce.spec.ECParameterSpec; //导入依赖的package包/类
@Override
public boolean isSignatureValid(byte[] data, byte[] signature, Pubkey pubkey) {
try {
ECParameterSpec spec = new ECParameterSpec(
EC_CURVE_PARAMETERS.getCurve(),
EC_CURVE_PARAMETERS.getG(),
EC_CURVE_PARAMETERS.getN(),
EC_CURVE_PARAMETERS.getH(),
EC_CURVE_PARAMETERS.getSeed()
);
ECPoint Q = keyToPoint(pubkey.getSigningKey());
KeySpec keySpec = new ECPublicKeySpec(Q, spec);
PublicKey publicKey = KeyFactory.getInstance(ALGORITHM_ECDSA, provider).generatePublic(keySpec);
Signature sig = Signature.getInstance(ALGORITHM_ECDSA, provider);
sig.initVerify(publicKey);
sig.update(data);
return sig.verify(signature);
} catch (GeneralSecurityException e) {
throw new ApplicationException(e);
}
}
示例2: getSignature
import org.spongycastle.jce.spec.ECParameterSpec; //导入依赖的package包/类
@Override
public byte[] getSignature(byte[] data, PrivateKey privateKey) {
try {
ECParameterSpec spec = new ECParameterSpec(
EC_CURVE_PARAMETERS.getCurve(),
EC_CURVE_PARAMETERS.getG(),
EC_CURVE_PARAMETERS.getN(),
EC_CURVE_PARAMETERS.getH(),
EC_CURVE_PARAMETERS.getSeed()
);
BigInteger d = keyToBigInt(privateKey.getPrivateSigningKey());
KeySpec keySpec = new ECPrivateKeySpec(d, spec);
java.security.PrivateKey privKey = KeyFactory.getInstance(ALGORITHM_ECDSA, provider)
.generatePrivate(keySpec);
Signature sig = Signature.getInstance(ALGORITHM_ECDSA, provider);
sig.initSign(privKey);
sig.update(data);
return sig.sign();
} catch (GeneralSecurityException e) {
throw new ApplicationException(e);
}
}
示例3: createNewKeyPair
import org.spongycastle.jce.spec.ECParameterSpec; //导入依赖的package包/类
/**
* Creates a new (elliptic curve) KeyPair according to the given arguments.
* @param curveName The given curnename
* @param algorithm The used algorithm
* @param provider The security provider
* @param custom If this is a custom curve (see BouncyCastle for what custom curves are).
* @return The generated keypair.
*/
public static KeyPair createNewKeyPair(String curveName, String algorithm, String provider, boolean custom) {
ECParameterSpec ecSpec = getParameterSpec(curveName, custom);
KeyPair keyPair = null;
try {
KeyPairGenerator g = KeyPairGenerator.getInstance(algorithm, provider);
g.initialize(ecSpec, new SecureRandom());
keyPair = g.generateKeyPair();
} catch (Exception e) {
e.printStackTrace();
}
return keyPair;
}
示例4: getParameterSpec
import org.spongycastle.jce.spec.ECParameterSpec; //导入依赖的package包/类
/**
* Retrieves the parameters of the given elliptic curve.
* @param curveName The curve name
* @param custom Custom or not?
* @return The elliptic curve parameters.
*/
private static ECParameterSpec getParameterSpec(String curveName, boolean custom) {
if(custom) {
X9ECParameters ecP = CustomNamedCurves.getByName(curveName);
return new ECParameterSpec(ecP.getCurve(), ecP.getG(),
ecP.getN(), ecP.getH(), ecP.getSeed());
}
return ECNamedCurveTable.getParameterSpec(curveName);
}
示例5: generate
import org.spongycastle.jce.spec.ECParameterSpec; //导入依赖的package包/类
public static KeyPair generate () throws NoSuchAlgorithmException, InvalidAlgorithmParameterException {
SecureRandom random = new SecureRandom();
ECParameterSpec ecSpec = ECNamedCurveTable.getParameterSpec("secp256r1");
KeyPairGenerator g = KeyPairGenerator.getInstance("ECDSA");
g.initialize(ecSpec, random);
return g.generateKeyPair();
}
示例6: generate
import org.spongycastle.jce.spec.ECParameterSpec; //导入依赖的package包/类
public static KeyPair generate() throws NoSuchAlgorithmException, InvalidAlgorithmParameterException {
SecureRandom random = new SecureRandom();
ECParameterSpec ecSpec = ECNamedCurveTable.getParameterSpec("secp256r1");
KeyPairGenerator g = KeyPairGenerator.getInstance("ECDSA");
g.initialize(ecSpec, random);
return g.generateKeyPair();
}
示例7: generateNewKey
import org.spongycastle.jce.spec.ECParameterSpec; //导入依赖的package包/类
private static KeyPair generateNewKey(String spec) {
try {
ECParameterSpec ecSpec = ECNamedCurveTable.getParameterSpec(spec);
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("ECDSA", "SC");
keyGen.initialize(ecSpec, new SecureRandom());
return keyGen.generateKeyPair();
} catch (Exception e) {
Log.e(TAG, "error", e);
System.exit(0);
return null;
}
}
示例8: createECCKeys
import org.spongycastle.jce.spec.ECParameterSpec; //导入依赖的package包/类
private static long createECCKeys(String spec) throws NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException {
long start = System.currentTimeMillis();
ECParameterSpec ecSpec = ECNamedCurveTable.getParameterSpec(spec);
KeyPairGenerator g = KeyPairGenerator.getInstance("ECDSA");
g.initialize(ecSpec, new SecureRandom());
g.generateKeyPair();
return (System.currentTimeMillis() - start);
}
示例9: generateKeyPair
import org.spongycastle.jce.spec.ECParameterSpec; //导入依赖的package包/类
public static KeyPair generateKeyPair(PKIAlgorithm algorithm) throws UnknownPKIAlgorithmException,
NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException {
if (algorithm.getCode() != PKIAlgorithm.DEFAULT.getCode())
throw new UnknownPKIAlgorithmException();
ECParameterSpec ecSpec = ECNamedCurveTable.getParameterSpec(algorithm.getKeyPairSpecification());
KeyPairGenerator keyGen = KeyPairGenerator.getInstance(algorithm.getKeyPairAlgorithm(), SECURITY_PROVIDER);
keyGen.initialize(ecSpec, new SecureRandom());
return keyGen.generateKeyPair();
}