本文整理汇总了Java中org.bouncycastle.jce.spec.ECNamedCurveParameterSpec类的典型用法代码示例。如果您正苦于以下问题:Java ECNamedCurveParameterSpec类的具体用法?Java ECNamedCurveParameterSpec怎么用?Java ECNamedCurveParameterSpec使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ECNamedCurveParameterSpec类属于org.bouncycastle.jce.spec包,在下文中一共展示了ECNamedCurveParameterSpec类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convertSpec
import org.bouncycastle.jce.spec.ECNamedCurveParameterSpec; //导入依赖的package包/类
public static ECParameterSpec convertSpec(
EllipticCurve ellipticCurve,
org.bouncycastle.jce.spec.ECParameterSpec spec)
{
if (spec instanceof ECNamedCurveParameterSpec)
{
return new ECNamedCurveSpec(
((ECNamedCurveParameterSpec)spec).getName(),
ellipticCurve,
new ECPoint(
spec.getG().getX().toBigInteger(),
spec.getG().getY().toBigInteger()),
spec.getN(),
spec.getH());
}
else
{
return new ECParameterSpec(
ellipticCurve,
new ECPoint(
spec.getG().getX().toBigInteger(),
spec.getG().getY().toBigInteger()),
spec.getN(),
spec.getH().intValue());
}
}
示例2: generateECKeypair
import org.bouncycastle.jce.spec.ECNamedCurveParameterSpec; //导入依赖的package包/类
public static KeyPair generateECKeypair(ASN1ObjectIdentifier curveId, SecureRandom random)
throws NoSuchAlgorithmException, NoSuchProviderException,
InvalidAlgorithmParameterException {
ParamUtil.requireNonNull("curveId", curveId);
ECNamedCurveParameterSpec spec = ECNamedCurveTable.getParameterSpec(curveId.getId());
KeyPairGenerator kpGen = getKeyPairGenerator("EC");
synchronized (kpGen) {
if (random == null) {
kpGen.initialize(spec);
} else {
kpGen.initialize(spec, random);
}
return kpGen.generateKeyPair();
}
}
示例3: getParameterSpec
import org.bouncycastle.jce.spec.ECNamedCurveParameterSpec; //导入依赖的package包/类
/**
* return a parameter spec representing the passed in named
* curve. The routine returns null if the curve is not present.
*
* @param name the name of the curve requested
* @return a parameter spec for the curve, null if it is not available.
*/
public static ECNamedCurveParameterSpec getParameterSpec(
String name)
{
X9ECParameters ecP = X962NamedCurves.getByName(name);
if (ecP == null)
{
return null;
}
return new ECNamedCurveParameterSpec(
name,
ecP.getCurve(),
ecP.getG(),
ecP.getN(),
ecP.getH(),
ecP.getSeed());
}
示例4: getPubKeyFromCurve
import org.bouncycastle.jce.spec.ECNamedCurveParameterSpec; //导入依赖的package包/类
/**
* Decode based on X, Y 32 byte integers
*
* @param pubKey
* @param curveName
* - Example secp256r1
* @return
* @throws InvalidKeySpecException
* @throws NoSuchAlgorithmException
* @throws NoSuchProviderException
*/
public static PublicKey getPubKeyFromCurve(byte[] pubKey, String curveName)
throws InvalidKeySpecException, NoSuchAlgorithmException,
NoSuchProviderException {
ECNamedCurveParameterSpec spec = ECNamedCurveTable
.getParameterSpec(curveName);
KeyFactory kf = KeyFactory.getInstance("ECDSA",
new BouncyCastleProvider());
ECNamedCurveSpec params = new ECNamedCurveSpec(curveName,
spec.getCurve(), spec.getG(), spec.getN());
ECPoint point = ECPointUtil.decodePoint(params.getCurve(), pubKey);
ECPublicKeySpec pubKeySpec = new ECPublicKeySpec(point, params);
ECPublicKey pk = (ECPublicKey) kf.generatePublic(pubKeySpec);
return pk;
}
示例5: convertSpec
import org.bouncycastle.jce.spec.ECNamedCurveParameterSpec; //导入依赖的package包/类
public static ECParameterSpec convertSpec(
EllipticCurve ellipticCurve,
org.bouncycastle.jce.spec.ECParameterSpec spec)
{
if (spec instanceof ECNamedCurveParameterSpec)
{
return new ECNamedCurveSpec(
((ECNamedCurveParameterSpec)spec).getName(),
ellipticCurve,
new ECPoint(
spec.getG().getAffineXCoord().toBigInteger(),
spec.getG().getAffineYCoord().toBigInteger()),
spec.getN(),
spec.getH());
}
else
{
return new ECParameterSpec(
ellipticCurve,
new ECPoint(
spec.getG().getAffineXCoord().toBigInteger(),
spec.getG().getAffineYCoord().toBigInteger()),
spec.getN(),
spec.getH().intValue());
}
}
示例6: verifySignature
import org.bouncycastle.jce.spec.ECNamedCurveParameterSpec; //导入依赖的package包/类
public static boolean verifySignature(byte[] sigR, byte sigS[], byte[] publicKey, byte[] message) {
try {
Security.addProvider(new BouncyCastleProvider());
ECNamedCurveParameterSpec spec = ECNamedCurveTable.getParameterSpec(SECP256K1);
ECDomainParameters domain = new ECDomainParameters(spec.getCurve(), spec.getG(), spec.getN());
ECPublicKeyParameters publicKeyParams =
new ECPublicKeyParameters(spec.getCurve().decodePoint(publicKey), domain);
ECDSASigner signer = new ECDSASigner();
signer.init(false, publicKeyParams);
return signer.verifySignature(message, new BigInteger(1, sigR), new BigInteger(1, sigS));
} catch (Exception e) {
LOGGER.error(null, e);
return false;
}
}
示例7: generateSharedSecret
import org.bouncycastle.jce.spec.ECNamedCurveParameterSpec; //导入依赖的package包/类
/**
* Generate a shared AES key using ECDH.
*/
public static byte[] generateSharedSecret(byte[] privateKey, byte[] publicKey) {
try {
ECNamedCurveParameterSpec spec = ECNamedCurveTable.getParameterSpec(SECP256K1);
ECDomainParameters domain =
new ECDomainParameters(spec.getCurve(), spec.getG(), spec.getN(), spec.getH());
ECPublicKeyParameters pubKey =
new ECPublicKeyParameters(spec.getCurve().decodePoint(publicKey), domain);
ECPrivateKeyParameters prvkey =
new ECPrivateKeyParameters(new BigInteger(1, privateKey), domain);
ECDHBasicAgreement agreement = new ECDHBasicAgreement();
agreement.init(prvkey);
byte[] password = agreement.calculateAgreement(pubKey).toByteArray();
return Aes.generateKey(ByteUtilities.toHexString(password), password);
} catch (Exception e) {
LOGGER.error(null, e);
return new byte[0];
}
}
示例8: toJcaPrivateKey
import org.bouncycastle.jce.spec.ECNamedCurveParameterSpec; //导入依赖的package包/类
private static ECPrivateKey toJcaPrivateKey(org.bouncycastle.asn1.sec.ECPrivateKey ecPrivateKey)
throws GeneralSecurityException {
String curveName = null;
ASN1ObjectIdentifier curveId = (ASN1ObjectIdentifier) ecPrivateKey.getParameters();
if (curveId.equals(secp224r1_OID)) {
curveName = "secp224r1";
} else if (curveId.equals(prime256v1_OID)) {
curveName = "prime256v1";
} else if (curveId.equals(secp384r1_OID)) {
curveName = "secp384r1";
} else if (curveId.equals(secp521r1_OID)) {
curveName = "secp521r1";
} else {
throw new IllegalStateException("Unknown curve OID: " + curveId);
}
ECNamedCurveParameterSpec sp = ECNamedCurveTable.getParameterSpec(curveName);
ECParameterSpec params = new ECNamedCurveSpec(sp.getName(), sp.getCurve(), sp.getG(),
sp.getN(), sp.getH());
ECPrivateKeySpec pkSpec = new ECPrivateKeySpec(ecPrivateKey.getKey(), params);
KeyFactory kf = KeyFactory.getInstance("EC");
ECPrivateKey privateKey = (ECPrivateKey) kf.generatePrivate(pkSpec);
return privateKey;
}
示例9: generateECKeys
import org.bouncycastle.jce.spec.ECNamedCurveParameterSpec; //导入依赖的package包/类
private static KeyPair generateECKeys() {
try {
ECNamedCurveParameterSpec parameterSpec = ECNamedCurveTable
.getParameterSpec("secp256k1");
KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(
"ECDH", BouncyCastleProvider.PROVIDER_NAME);
keyPairGenerator.initialize(parameterSpec);
KeyPair keyPair = keyPairGenerator.generateKeyPair();
System.out.println("Private key length: "
+ keyPair.getPrivate().getEncoded().length);
System.out.println("Public key length: "
+ keyPair.getPublic().getEncoded().length);
return keyPair;
} catch (NoSuchAlgorithmException | InvalidAlgorithmParameterException
| NoSuchProviderException e) {
e.printStackTrace();
return null;
}
}
示例10: createPublicEncryptionKey
import org.bouncycastle.jce.spec.ECNamedCurveParameterSpec; //导入依赖的package包/类
/**
* Creates a ECPublicKey with the given coordinates. The key will have valid
* parameters.
*
* @param x
* The x coordinate on the curve.
* @param y
* The y coordinate on the curve.
* @return A ECPublicKey with the given coordinates.
*/
public ECPublicKey createPublicEncryptionKey(BigInteger x, BigInteger y) {
try {
java.security.spec.ECPoint w = new java.security.spec.ECPoint(x, y);
ECNamedCurveParameterSpec params = ECNamedCurveTable.getParameterSpec("secp256k1");
KeyFactory fact = KeyFactory.getInstance("ECDSA", "BC");
ECCurve curve = params.getCurve();
java.security.spec.EllipticCurve ellipticCurve = EC5Util.convertCurve(curve, params.getSeed());
java.security.spec.ECParameterSpec params2 = EC5Util.convertSpec(ellipticCurve, params);
java.security.spec.ECPublicKeySpec keySpec = new java.security.spec.ECPublicKeySpec(w, params2);
return (ECPublicKey) fact.generatePublic(keySpec);
} catch (InvalidKeySpecException | NoSuchAlgorithmException | NoSuchProviderException e) {
LOG.log(Level.SEVERE, "Could not create public key.", e);
return null;
}
}
示例11: getParameterSpec
import org.bouncycastle.jce.spec.ECNamedCurveParameterSpec; //导入依赖的package包/类
/**
* return a parameter spec representing the passed in named
* curve. The routine returns null if the curve is not present.
*
* @param name the name of the curve requested
* @return a parameter spec for the curve, null if it is not available.
*/
public static ECNamedCurveParameterSpec getParameterSpec(
String name)
{
ECDomainParameters ecP = ECGOST3410NamedCurves.getByName(name);
if (ecP == null)
{
try
{
ecP = ECGOST3410NamedCurves.getByOID(new ASN1ObjectIdentifier(name));
}
catch (IllegalArgumentException e)
{
return null; // not an oid.
}
}
if (ecP == null)
{
return null;
}
return new ECNamedCurveParameterSpec(
name,
ecP.getCurve(),
ecP.getG(),
ecP.getN(),
ecP.getH(),
ecP.getSeed());
}
示例12: getECPublicKey
import org.bouncycastle.jce.spec.ECNamedCurveParameterSpec; //导入依赖的package包/类
public static PublicKey getECPublicKey(java.security.spec.ECPoint w, String stdCurveName) throws NoSuchAlgorithmException, InvalidKeySpecException {
ECNamedCurveParameterSpec parameterSpec = ECNamedCurveTable.getParameterSpec(stdCurveName);
java.security.spec.ECParameterSpec params = new ECNamedCurveSpec(parameterSpec.getName(), parameterSpec.getCurve(),
parameterSpec.getG(), parameterSpec.getN(), parameterSpec.getH(), parameterSpec.getSeed());
KeySpec keySpec = new java.security.spec.ECPublicKeySpec(w, params);
KeyFactory keyFactory = KeyFactory.getInstance("EC");
return keyFactory.generatePublic(keySpec);
}
示例13: getPrivKeyFromCurve
import org.bouncycastle.jce.spec.ECNamedCurveParameterSpec; //导入依赖的package包/类
/**
* Decode based on d - 32 byte integer
*
* @param privKey
* @param curveName
* - Example secp256r1
* @return
* @throws InvalidKeySpecException
* @throws NoSuchAlgorithmException
* @throws NoSuchProviderException
*/
public static PrivateKey getPrivKeyFromCurve(byte[] privKey,
String curveName) throws InvalidKeySpecException,
NoSuchAlgorithmException, NoSuchProviderException {
ECNamedCurveParameterSpec spec = ECNamedCurveTable
.getParameterSpec(curveName);
KeyFactory kf = KeyFactory.getInstance("ECDSA",
new BouncyCastleProvider());
ECNamedCurveSpec params = new ECNamedCurveSpec(curveName,
spec.getCurve(), spec.getG(), spec.getN());
ECPrivateKeySpec priKey = new ECPrivateKeySpec(new BigInteger(privKey), // d
params);
return kf.generatePrivate(priKey);
}
示例14: getEncoded
import org.bouncycastle.jce.spec.ECNamedCurveParameterSpec; //导入依赖的package包/类
public byte[] getEncoded()
{
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
DEROutputStream dOut = new DEROutputStream(bOut);
X962Parameters params = null;
if (ecSpec instanceof ECNamedCurveParameterSpec)
{
params = new X962Parameters(X962NamedCurves.getOID(((ECNamedCurveParameterSpec)ecSpec).getName()));
}
else
{
X9ECParameters ecP = new X9ECParameters(
ecSpec.getCurve(),
ecSpec.getG(),
ecSpec.getN(),
ecSpec.getH(),
ecSpec.getSeed());
params = new X962Parameters(ecP);
}
ASN1OctetString p = (ASN1OctetString)(new X9ECPoint(this.getQ()).getDERObject());
SubjectPublicKeyInfo info = new SubjectPublicKeyInfo(new AlgorithmIdentifier(X9ObjectIdentifiers.id_ecPublicKey, params.getDERObject()), p.getOctets());
try
{
dOut.writeObject(info);
dOut.close();
}
catch (IOException e)
{
throw new RuntimeException("Error encoding EC public key");
}
return bOut.toByteArray();
}
示例15: readECParameters
import org.bouncycastle.jce.spec.ECNamedCurveParameterSpec; //导入依赖的package包/类
private ECNamedCurveParameterSpec readECParameters(String endMarker)
throws IOException
{
DERObjectIdentifier oid = (DERObjectIdentifier)ASN1Object.fromByteArray(readBytes(endMarker));
return ECNamedCurveTable.getParameterSpec(oid.getId());
}