本文整理匯總了Java中org.bouncycastle.asn1.x9.X9ECParameters.getCurve方法的典型用法代碼示例。如果您正苦於以下問題:Java X9ECParameters.getCurve方法的具體用法?Java X9ECParameters.getCurve怎麽用?Java X9ECParameters.getCurve使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.bouncycastle.asn1.x9.X9ECParameters
的用法示例。
在下文中一共展示了X9ECParameters.getCurve方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getParameterSpec
import org.bouncycastle.asn1.x9.X9ECParameters; //導入方法依賴的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());
}
示例2: getParametersForNamedCurve
import org.bouncycastle.asn1.x9.X9ECParameters; //導入方法依賴的package包/類
public static ECDomainParameters getParametersForNamedCurve(int namedCurve)
{
String curveName = getNameOfNamedCurve(namedCurve);
if (curveName == null)
{
return null;
}
// Lazily created the first time a particular curve is accessed
X9ECParameters ecP = SECNamedCurves.getByName(curveName);
if (ecP == null)
{
return null;
}
// It's a bit inefficient to do this conversion every time
return new ECDomainParameters(ecP.getCurve(), ecP.getG(), ecP.getN(), ecP.getH(), ecP.getSeed());
}
示例3: getParametersForNamedCurve
import org.bouncycastle.asn1.x9.X9ECParameters; //導入方法依賴的package包/類
public static ECDomainParameters getParametersForNamedCurve(int namedCurve)
{
String curveName = getNameOfNamedCurve(namedCurve);
if (curveName == null)
{
return null;
}
// Parameters are lazily created the first time a particular curve is accessed
X9ECParameters ecP = CustomNamedCurves.getByName(curveName);
if (ecP == null)
{
ecP = ECNamedCurveTable.getByName(curveName);
if (ecP == null)
{
return null;
}
}
// It's a bit inefficient to do this conversion every time
return new ECDomainParameters(ecP.getCurve(), ecP.getG(), ecP.getN(), ecP.getH(), ecP.getSeed());
}
示例4: ECDSAgeneratePublicAndPrivateKey
import org.bouncycastle.asn1.x9.X9ECParameters; //導入方法依賴的package包/類
/*************
* This method will create the ECDSA public and private key which is returned in a Byte array of Byte arrays, index 0 is the private key and
* index 1 of the array will return the ECDSA public key
*
* -Wisdom: This guy didn't check whether the returned Private Key would be more than 32.
* @return
*/
private byte[][] ECDSAgeneratePublicAndPrivateKey(){
int length = 0;
byte[][] keys;
do{
ECKeyPairGenerator gen = new ECKeyPairGenerator();
SecureRandom secureRandom = new SecureRandom();
X9ECParameters secnamecurves = SECNamedCurves.getByName("secp256k1");
ECDomainParameters ecParams = new ECDomainParameters(secnamecurves.getCurve(), secnamecurves.getG(), secnamecurves.getN(), secnamecurves.getH());
ECKeyGenerationParameters keyGenParam = new ECKeyGenerationParameters(ecParams, secureRandom);
gen.init(keyGenParam);
AsymmetricCipherKeyPair kp = gen.generateKeyPair();
ECPrivateKeyParameters privatekey = (ECPrivateKeyParameters)kp.getPrivate();
ECPoint dd = secnamecurves.getG().multiply(privatekey.getD());
byte[] publickey=new byte[65];
System.arraycopy(dd.getY().toBigInteger().toByteArray(), 0, publickey, 64-dd.getY().toBigInteger().toByteArray().length+1, dd.getY().toBigInteger().toByteArray().length);
System.arraycopy(dd.getX().toBigInteger().toByteArray(), 0, publickey, 32-dd.getX().toBigInteger().toByteArray().length+1, dd.getX().toBigInteger().toByteArray().length);
publickey[0]=4;
length = privatekey.getD().toByteArray().length;
keys = new byte[][]{privatekey.getD().toByteArray(),publickey};
}while(length != 32);
return keys;
}
示例5: discoverEndomorphisms
import org.bouncycastle.asn1.x9.X9ECParameters; //導入方法依賴的package包/類
public static void discoverEndomorphisms(X9ECParameters x9)
{
if (x9 == null)
{
throw new NullPointerException("x9");
}
ECCurve c = x9.getCurve();
if (ECAlgorithms.isFpCurve(c))
{
BigInteger characteristic = c.getField().getCharacteristic();
if (c.getA().isZero() && characteristic.mod(ECConstants.THREE).equals(ECConstants.ONE))
{
System.out.println("Curve has a 'GLV Type B' endomorphism with these parameters:");
printGLVTypeBParameters(x9);
}
}
}
示例6: signAndFromatToRS
import org.bouncycastle.asn1.x9.X9ECParameters; //導入方法依賴的package包/類
/**
* UAF_ALG_SIGN_SECP256R1_ECDSA_SHA256_RAW 0x01 An ECDSA signature on the
* NIST secp256r1 curve which MUST have raw R and S buffers, encoded in
* big-endian order. I.e. [R (32 bytes), S (32 bytes)]
*
* @param priv
* - Private key
* @param input
* - Data to sign
* @return BigInteger[] - [R,S]
*/
public static BigInteger[] signAndFromatToRS(PrivateKey priv, byte[] input) {
X9ECParameters params = SECNamedCurves.getByName("secp256r1");
ECDomainParameters ecParams = new ECDomainParameters(params.getCurve(),
params.getG(), params.getN(), params.getH());
if (priv == null)
throw new IllegalStateException(
"This ECKey does not have the private key necessary for signing.");
ECDSASigner signer = new ECDSASigner();
ECPrivateKeyParameters privKey = new ECPrivateKeyParameters(
((ECPrivateKey) priv).getS(), ecParams);
signer.init(true, privKey);
BigInteger[] sigs = signer.generateSignature(input);
return sigs;
}
示例7: verify
import org.bouncycastle.asn1.x9.X9ECParameters; //導入方法依賴的package包/類
public static boolean verify(byte[] pub, byte[] dataForSigning,
BigInteger[] rs) throws Exception {
ECDSASigner signer = new ECDSASigner();
X9ECParameters params = SECNamedCurves.getByName("secp256r1");
ECDomainParameters ecParams = new ECDomainParameters(params.getCurve(),
params.getG(), params.getN(), params.getH());
ECPublicKeyParameters pubKeyParams = new ECPublicKeyParameters(ecParams
.getCurve().decodePoint(pub), ecParams);
signer.init(false, pubKeyParams);
return signer.verifySignature(dataForSigning, rs[0].abs(), rs[1].abs());
}
示例8: verifyUsingSecp256k1
import org.bouncycastle.asn1.x9.X9ECParameters; //導入方法依賴的package包/類
public static boolean verifyUsingSecp256k1(byte[] pub, byte[] dataForSigning,
BigInteger[] rs) throws Exception {
ECDSASigner signer = new ECDSASigner();
X9ECParameters params = SECNamedCurves.getByName("secp256k1");
ECDomainParameters ecParams = new ECDomainParameters(params.getCurve(),
params.getG(), params.getN(), params.getH());
ECPublicKeyParameters pubKeyParams = new ECPublicKeyParameters(ecParams
.getCurve().decodePoint(pub), ecParams);
signer.init(false, pubKeyParams);
return signer.verifySignature(dataForSigning, rs[0].abs(), rs[1].abs());
}
示例9: setUpClass
import org.bouncycastle.asn1.x9.X9ECParameters; //導入方法依賴的package包/類
@BeforeClass
public static void setUpClass() throws CoseException {
X9ECParameters p = NISTNamedCurves.getByName("P-256");
ECDomainParameters parameters = new ECDomainParameters(p.getCurve(), p.getG(), p.getN(), p.getH());
ECKeyPairGenerator pGen = new ECKeyPairGenerator();
ECKeyGenerationParameters genParam = new ECKeyGenerationParameters(parameters, null);
pGen.init(genParam);
AsymmetricCipherKeyPair p1 = pGen.generateKeyPair();
keyPublic = (ECPublicKeyParameters) p1.getPublic();
keyPrivate = (ECPrivateKeyParameters) p1.getPrivate();
byte[] rgbX = keyPublic.getQ().normalize().getXCoord().getEncoded();
byte[] rgbY = keyPublic.getQ().normalize().getYCoord().getEncoded();
boolean signY = true;
byte[] rgbD = keyPrivate.getD().toByteArray();
CBORObject key = CBORObject.NewMap();
key.Add(KeyKeys.KeyType.AsCBOR(), KeyKeys.KeyType_EC2);
key.Add(KeyKeys.EC2_Curve.AsCBOR(), KeyKeys.EC2_P256);
key.Add(KeyKeys.EC2_X.AsCBOR(), rgbX);
key.Add(KeyKeys.EC2_Y.AsCBOR(), rgbY);
cnKeyPublic = new OneKey(key);
key = CBORObject.NewMap();
key.Add(KeyKeys.KeyType.AsCBOR(), KeyKeys.KeyType_EC2);
key.Add(KeyKeys.EC2_Curve.AsCBOR(), KeyKeys.EC2_P256);
key.Add(KeyKeys.EC2_X.AsCBOR(), rgbX);
key.Add(KeyKeys.EC2_Y.AsCBOR(), rgbY);
cnKeyPublicCompressed = new OneKey(key);
key = CBORObject.NewMap();
key.Add(KeyKeys.KeyType.AsCBOR(), KeyKeys.KeyType_EC2);
key.Add(KeyKeys.EC2_Curve.AsCBOR(), KeyKeys.EC2_P256);
key.Add(KeyKeys.EC2_D.AsCBOR(), rgbD);
cnKeyPrivate = new OneKey(key);
}
示例10: createNamedCurveSpec
import org.bouncycastle.asn1.x9.X9ECParameters; //導入方法依賴的package包/類
protected ECNamedCurveSpec createNamedCurveSpec(String curveName)
throws InvalidAlgorithmParameterException
{
// NOTE: Don't bother with custom curves here as the curve will be converted to JCE type shortly
X9ECParameters p = ECUtils.getDomainParametersFromName(curveName);
if (p == null)
{
try
{
// Check whether it's actually an OID string (SunJSSE ServerHandshaker setupEphemeralECDHKeys bug)
p = ECNamedCurveTable.getByOID(new ASN1ObjectIdentifier(curveName));
if (p == null)
{
throw new InvalidAlgorithmParameterException("unknown curve OID: " + curveName);
}
}
catch (IllegalArgumentException ex)
{
throw new InvalidAlgorithmParameterException("unknown curve name: " + curveName);
}
}
// Work-around for JDK bug -- it won't look up named curves properly if seed is present
byte[] seed = null; //p.getSeed();
return new ECNamedCurveSpec(curveName, p.getCurve(), p.getG(), p.getN(), p.getH(), seed);
}
示例11: generateECPublicKey
import org.bouncycastle.asn1.x9.X9ECParameters; //導入方法依賴的package包/類
public static AsymmetricCipherKeyPair generateECPublicKey() {
// Should we also generate random curves?
X9ECParameters ecp = SECNamedCurves.getByName(getRandomCurveName());
ECKeyPairGenerator keygen = new ECKeyPairGenerator();
ECDomainParameters domainParams = new ECDomainParameters(ecp.getCurve(), ecp.getG(), ecp.getN(), ecp.getH(),
ecp.getSeed());
keygen.init(new ECKeyGenerationParameters(domainParams, RandomHelper.getBadSecureRandom()));
return keygen.generateKeyPair();
}
示例12: generateECDSAKey
import org.bouncycastle.asn1.x9.X9ECParameters; //導入方法依賴的package包/類
static private OneKey generateECDSAKey(String curveName, CBORObject curve) {
X9ECParameters p = NISTNamedCurves.getByName(curveName);
ECDomainParameters parameters = new ECDomainParameters(p.getCurve(), p.getG(), p.getN(), p.getH());
ECKeyPairGenerator pGen = new ECKeyPairGenerator();
ECKeyGenerationParameters genParam = new ECKeyGenerationParameters(parameters, null);
pGen.init(genParam);
AsymmetricCipherKeyPair p1 = pGen.generateKeyPair();
ECPublicKeyParameters keyPublic = (ECPublicKeyParameters) p1.getPublic();
ECPrivateKeyParameters keyPrivate = (ECPrivateKeyParameters) p1.getPrivate();
byte[] rgbX = keyPublic.getQ().normalize().getXCoord().getEncoded();
byte[] rgbY = keyPublic.getQ().normalize().getYCoord().getEncoded();
boolean signY = true;
byte[] rgbD = keyPrivate.getD().toByteArray();
OneKey key = new OneKey();
key.add(KeyKeys.KeyType, KeyKeys.KeyType_EC2);
key.add(KeyKeys.EC2_Curve, curve);
key.add(KeyKeys.EC2_X, CBORObject.FromObject(rgbX));
key.add(KeyKeys.EC2_Y, CBORObject.FromObject(rgbY));
key.add(KeyKeys.EC2_D, CBORObject.FromObject(rgbD));
return key;
}
示例13: testECMQVTestVector1
import org.bouncycastle.asn1.x9.X9ECParameters; //導入方法依賴的package包/類
private void testECMQVTestVector1()
{
// Test Vector from GEC-2
X9ECParameters x9 = SECNamedCurves.getByName("secp160r1");
ECDomainParameters p = new ECDomainParameters(
x9.getCurve(), x9.getG(), x9.getN(), x9.getH(), x9.getSeed());
AsymmetricCipherKeyPair U1 = new AsymmetricCipherKeyPair(
new ECPublicKeyParameters(
p.getCurve().decodePoint(Hex.decode("0251B4496FECC406ED0E75A24A3C03206251419DC0")), p),
new ECPrivateKeyParameters(
new BigInteger("AA374FFC3CE144E6B073307972CB6D57B2A4E982", 16), p));
AsymmetricCipherKeyPair U2 = new AsymmetricCipherKeyPair(
new ECPublicKeyParameters(
p.getCurve().decodePoint(Hex.decode("03D99CE4D8BF52FA20BD21A962C6556B0F71F4CA1F")), p),
new ECPrivateKeyParameters(
new BigInteger("149EC7EA3A220A887619B3F9E5B4CA51C7D1779C", 16), p));
AsymmetricCipherKeyPair V1 = new AsymmetricCipherKeyPair(
new ECPublicKeyParameters(
p.getCurve().decodePoint(Hex.decode("0349B41E0E9C0369C2328739D90F63D56707C6E5BC")), p),
new ECPrivateKeyParameters(
new BigInteger("45FB58A92A17AD4B15101C66E74F277E2B460866", 16), p));
AsymmetricCipherKeyPair V2 = new AsymmetricCipherKeyPair(
new ECPublicKeyParameters(
p.getCurve().decodePoint(Hex.decode("02706E5D6E1F640C6E9C804E75DBC14521B1E5F3B5")), p),
new ECPrivateKeyParameters(
new BigInteger("18C13FCED9EADF884F7C595C8CB565DEFD0CB41E", 16), p));
BigInteger x = calculateAgreement(U1, U2, V1, V2);
if (x == null
|| !x.equals(new BigInteger("5A6955CEFDB4E43255FB7FCF718611E4DF8E05AC", 16)))
{
fail("MQV Test Vector #1 agreement failed");
}
}
示例14: testECMQVTestVector2
import org.bouncycastle.asn1.x9.X9ECParameters; //導入方法依賴的package包/類
private void testECMQVTestVector2()
{
// Test Vector from GEC-2
X9ECParameters x9 = SECNamedCurves.getByName("sect163k1");
ECDomainParameters p = new ECDomainParameters(
x9.getCurve(), x9.getG(), x9.getN(), x9.getH(), x9.getSeed());
AsymmetricCipherKeyPair U1 = new AsymmetricCipherKeyPair(
new ECPublicKeyParameters(
p.getCurve().decodePoint(Hex.decode("03037D529FA37E42195F10111127FFB2BB38644806BC")), p),
new ECPrivateKeyParameters(
new BigInteger("03A41434AA99C2EF40C8495B2ED9739CB2155A1E0D", 16), p));
AsymmetricCipherKeyPair U2 = new AsymmetricCipherKeyPair(
new ECPublicKeyParameters(
p.getCurve().decodePoint(Hex.decode("02015198E74BC2F1E5C9A62B80248DF0D62B9ADF8429")), p),
new ECPrivateKeyParameters(
new BigInteger("032FC4C61A8211E6A7C4B8B0C03CF35F7CF20DBD52", 16), p));
AsymmetricCipherKeyPair V1 = new AsymmetricCipherKeyPair(
new ECPublicKeyParameters(
p.getCurve().decodePoint(Hex.decode("03072783FAAB9549002B4F13140B88132D1C75B3886C")), p),
new ECPrivateKeyParameters(
new BigInteger("57E8A78E842BF4ACD5C315AA0569DB1703541D96", 16), p));
AsymmetricCipherKeyPair V2 = new AsymmetricCipherKeyPair(
new ECPublicKeyParameters(
p.getCurve().decodePoint(Hex.decode("03067E3AEA3510D69E8EDD19CB2A703DDC6CF5E56E32")), p),
new ECPrivateKeyParameters(
new BigInteger("02BD198B83A667A8D908EA1E6F90FD5C6D695DE94F", 16), p));
BigInteger x = calculateAgreement(U1, U2, V1, V2);
if (x == null
|| !x.equals(new BigInteger("038359FFD30C0D5FC1E6154F483B73D43E5CF2B503", 16)))
{
fail("MQV Test Vector #2 agreement failed");
}
}
示例15: ECDH_GenerateEphemeral
import org.bouncycastle.asn1.x9.X9ECParameters; //導入方法依賴的package包/類
private void ECDH_GenerateEphemeral() throws CoseException
{
X9ECParameters p = privateKey.GetCurve();
ECDomainParameters parameters = new ECDomainParameters(p.getCurve(), p.getG(), p.getN(), p.getH());
ECKeyPairGenerator pGen = new ECKeyPairGenerator();
ECKeyGenerationParameters genParam = new ECKeyGenerationParameters(parameters, null);
pGen.init(genParam);
AsymmetricCipherKeyPair p1 = pGen.generateKeyPair();
CBORObject epk = CBORObject.NewMap();
epk.Add(KeyKeys.KeyType.AsCBOR(), KeyKeys.KeyType_EC2);
epk.Add(KeyKeys.EC2_Curve.AsCBOR(), privateKey.get(KeyKeys.EC2_Curve.AsCBOR()));
ECPublicKeyParameters priv = (ECPublicKeyParameters) p1.getPublic();
byte[] rgbEncoded = priv.getQ().normalize().getEncoded(true);
byte[] X = new byte[rgbEncoded.length - 1];
System.arraycopy(rgbEncoded, 1, X, 0, X.length);
epk.Add(KeyKeys.EC2_X.AsCBOR(), CBORObject.FromObject(X));
epk.Add(KeyKeys.EC2_Y.AsCBOR(), CBORObject.FromObject((rgbEncoded[0] & 1) == 1));
addAttribute(HeaderKeys.ECDH_EPK, epk, Attribute.UNPROTECTED);
OneKey secretKey = new OneKey();
secretKey.add(KeyKeys.KeyType, KeyKeys.KeyType_EC2);
secretKey.add(KeyKeys.EC2_Curve, privateKey.get(KeyKeys.EC2_Curve.AsCBOR()));
secretKey.add(KeyKeys.EC2_X, CBORObject.FromObject(X));
secretKey.add(KeyKeys.EC2_Y, CBORObject.FromObject((rgbEncoded[0] & 1) == 1));
ECPrivateKeyParameters priv1 = (ECPrivateKeyParameters) p1.getPrivate();
secretKey.add(KeyKeys.EC2_D, CBORObject.FromObject(BigIntegers.asUnsignedByteArray( priv1.getD())));
senderKey = secretKey;
}