本文整理汇总了Java中org.bouncycastle.jce.spec.ECNamedCurveParameterSpec.getCurve方法的典型用法代码示例。如果您正苦于以下问题:Java ECNamedCurveParameterSpec.getCurve方法的具体用法?Java ECNamedCurveParameterSpec.getCurve怎么用?Java ECNamedCurveParameterSpec.getCurve使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bouncycastle.jce.spec.ECNamedCurveParameterSpec
的用法示例。
在下文中一共展示了ECNamedCurveParameterSpec.getCurve方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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;
}
}
示例3: 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];
}
}
示例4: 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;
}
示例5: 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;
}
}
示例6: 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);
}
示例7: 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);
}
示例8: getPublicKeyFromBytes
import org.bouncycastle.jce.spec.ECNamedCurveParameterSpec; //导入方法依赖的package包/类
private PublicKey getPublicKeyFromBytes(byte[] pubKey) throws NoSuchAlgorithmException, InvalidKeySpecException {
ECNamedCurveParameterSpec spec = ECNamedCurveTable.getParameterSpec("secp384r1");
KeyFactory keyFactory = KeyFactory.getInstance("ECDH", new BouncyCastleProvider());
ECNamedCurveSpec params = new ECNamedCurveSpec("secp384r1", spec.getCurve(), spec.getG(), spec.getN());
ECPoint point = ECPointUtil.decodePoint(params.getCurve(), pubKey);
ECPublicKeySpec pubKeySpec = new ECPublicKeySpec(point, params);
ECPublicKey ecPublicKey = (ECPublicKey) keyFactory.generatePublic(pubKeySpec);
return ecPublicKey;
}
示例9: signTransaction
import org.bouncycastle.jce.spec.ECNamedCurveParameterSpec; //导入方法依赖的package包/类
/**
* Sign data using the ECDSA algorithm.
*/
public static byte[][] signTransaction(byte[] data, byte[] privateKey) {
try {
Security.addProvider(new BouncyCastleProvider());
ECNamedCurveParameterSpec spec = ECNamedCurveTable.getParameterSpec(SECP256K1);
ECDSASigner ecdsaSigner = new ECDSASigner();
ECDomainParameters domain = new ECDomainParameters(spec.getCurve(), spec.getG(), spec.getN());
ECPrivateKeyParameters privateKeyParms =
new ECPrivateKeyParameters(new BigInteger(1, privateKey), domain);
ParametersWithRandom params = new ParametersWithRandom(privateKeyParms);
ecdsaSigner.init(true, params);
BigInteger[] sig = ecdsaSigner.generateSignature(data);
LinkedList<byte[]> sigData = new LinkedList<>();
byte[] publicKey = getPublicKey(privateKey);
byte recoveryId = getRecoveryId(sig[0].toByteArray(), sig[1].toByteArray(), data, publicKey);
for (BigInteger sigChunk : sig) {
sigData.add(sigChunk.toByteArray());
}
sigData.add(new byte[]{recoveryId});
return sigData.toArray(new byte[][]{});
} catch (Exception e) {
LOGGER.error(null, e);
return new byte[0][0];
}
}
示例10: populateFromPubKeyInfo
import org.bouncycastle.jce.spec.ECNamedCurveParameterSpec; //导入方法依赖的package包/类
private void populateFromPubKeyInfo(SubjectPublicKeyInfo info)
{
DERBitString bits = info.getPublicKeyData();
ASN1OctetString key;
this.algorithm = "ECGOST3410";
try
{
key = (ASN1OctetString)ASN1Primitive.fromByteArray(bits.getBytes());
}
catch (IOException ex)
{
throw new IllegalArgumentException("error recovering public key");
}
byte[] keyEnc = key.getOctets();
byte[] x = new byte[32];
byte[] y = new byte[32];
for (int i = 0; i != x.length; i++)
{
x[i] = keyEnc[32 - 1 - i];
}
for (int i = 0; i != y.length; i++)
{
y[i] = keyEnc[64 - 1 - i];
}
gostParams = GOST3410PublicKeyAlgParameters.getInstance(info.getAlgorithm().getParameters());
ECNamedCurveParameterSpec spec = ECGOST3410NamedCurveTable.getParameterSpec(ECGOST3410NamedCurves.getName(gostParams.getPublicKeyParamSet()));
ECCurve curve = spec.getCurve();
EllipticCurve ellipticCurve = EC5Util.convertCurve(curve, spec.getSeed());
this.q = curve.createPoint(new BigInteger(1, x), new BigInteger(1, y));
ecSpec = new ECNamedCurveSpec(
ECGOST3410NamedCurves.getName(gostParams.getPublicKeyParamSet()),
ellipticCurve,
new ECPoint(
spec.getG().getAffineXCoord().toBigInteger(),
spec.getG().getAffineYCoord().toBigInteger()),
spec.getN(), spec.getH());
}
示例11: populateFromPubKeyInfo
import org.bouncycastle.jce.spec.ECNamedCurveParameterSpec; //导入方法依赖的package包/类
private void populateFromPubKeyInfo(SubjectPublicKeyInfo info)
{
DERBitString bits = info.getPublicKeyData();
ASN1OctetString key;
this.algorithm = "ECGOST3410";
try
{
key = (ASN1OctetString)ASN1Primitive.fromByteArray(bits.getBytes());
}
catch (IOException ex)
{
throw new IllegalArgumentException("error recovering public key");
}
byte[] keyEnc = key.getOctets();
byte[] x = new byte[32];
byte[] y = new byte[32];
for (int i = 0; i != x.length; i++)
{
x[i] = keyEnc[32 - 1 - i];
}
for (int i = 0; i != y.length; i++)
{
y[i] = keyEnc[64 - 1 - i];
}
gostParams = GOST3410PublicKeyAlgParameters.getInstance(info.getAlgorithm().getParameters());
ECNamedCurveParameterSpec spec = ECGOST3410NamedCurveTable.getParameterSpec(ECGOST3410NamedCurves.getName(gostParams.getPublicKeyParamSet()));
ECCurve curve = spec.getCurve();
EllipticCurve ellipticCurve = EC5Util.convertCurve(curve, spec.getSeed());
this.q = curve.createPoint(new BigInteger(1, x), new BigInteger(1, y));
ecSpec = new ECNamedCurveSpec(
ECGOST3410NamedCurves.getName(gostParams.getPublicKeyParamSet()),
ellipticCurve,
new ECPoint(
spec.getG().getX().toBigInteger(),
spec.getG().getY().toBigInteger()),
spec.getN(), spec.getH());
}