本文整理汇总了Java中org.bouncycastle.jce.spec.ECNamedCurveParameterSpec.getG方法的典型用法代码示例。如果您正苦于以下问题:Java ECNamedCurveParameterSpec.getG方法的具体用法?Java ECNamedCurveParameterSpec.getG怎么用?Java ECNamedCurveParameterSpec.getG使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bouncycastle.jce.spec.ECNamedCurveParameterSpec
的用法示例。
在下文中一共展示了ECNamedCurveParameterSpec.getG方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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);
}
示例6: 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);
}
示例7: 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;
}
示例8: 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];
}
}