本文整理匯總了Java中org.bouncycastle.asn1.x9.X9ECParameters.getH方法的典型用法代碼示例。如果您正苦於以下問題:Java X9ECParameters.getH方法的具體用法?Java X9ECParameters.getH怎麽用?Java X9ECParameters.getH使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.bouncycastle.asn1.x9.X9ECParameters
的用法示例。
在下文中一共展示了X9ECParameters.getH方法的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: testExportImport
import org.bouncycastle.asn1.x9.X9ECParameters; //導入方法依賴的package包/類
@Test
public void testExportImport() throws GeneralSecurityException {
// Create a curve25519 parameter spec
X9ECParameters params = CustomNamedCurves.getByName("curve25519");
ECParameterSpec ecParameterSpec = new ECParameterSpec(params.getCurve(), params.getG(), params.getN(), params.getH(), params.getSeed());
// Create public key
KeyAgreementPeer peer = new ECDHPeer(ecParameterSpec, null, "BC");
ECPublicKey ecPublicKey = (ECPublicKey) peer.getPublicKey();
// Export public key
byte[] encoded = ecPublicKey.getQ().getEncoded(true);
System.out.println(Arrays.toString(encoded));
System.out.println("Encoded length: " + encoded.length);
// Import public key
ECPublicKey importedECPublicKey = loadPublicKey(encoded);
Assert.assertArrayEquals(ecPublicKey.getEncoded(), importedECPublicKey.getEncoded());
}
示例4: 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());
}
示例5: 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;
}
示例6: 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());
}
示例7: 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());
}
示例8: loadPublicKey
import org.bouncycastle.asn1.x9.X9ECParameters; //導入方法依賴的package包/類
/**
* Loads and returns the elliptic-curve public key from the data byte array.
* @param data
* @return
* @throws NoSuchAlgorithmException
* @throws NoSuchProviderException
* @throws InvalidKeySpecException
*/
public static ECPublicKey loadPublicKey(byte[] data) throws NoSuchAlgorithmException, NoSuchProviderException, InvalidKeySpecException
{
X9ECParameters params = CustomNamedCurves.getByName("curve25519");
ECParameterSpec ecParameterSpec = new ECParameterSpec(params.getCurve(), params.getG(), params.getN(), params.getH(), params.getSeed());
ECPublicKeySpec publicKey = new ECPublicKeySpec(ecParameterSpec.getCurve().decodePoint(data), ecParameterSpec);
KeyFactory kf = KeyFactory.getInstance("ECDH", "BC");
return (ECPublicKey) kf.generatePublic(publicKey);
}
示例9: 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();
}
示例10: 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);
}
示例11: 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");
}
}
示例12: 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");
}
}
示例13: 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;
}
示例14: 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);
}
示例15: testECDSASecP224k1sha256
import org.bouncycastle.asn1.x9.X9ECParameters; //導入方法依賴的package包/類
private void testECDSASecP224k1sha256()
{
X9ECParameters p = SECNamedCurves.getByName("secp224k1");
ECDomainParameters params = new ECDomainParameters(p.getCurve(), p.getG(), p.getN(), p.getH());
ECPrivateKeyParameters priKey = new ECPrivateKeyParameters(
new BigInteger("BE6F6E91FE96840A6518B56F3FE21689903A64FA729057AB872A9F51", 16), // d
params);
SecureRandom k = new FixedSecureRandom(Hex.decode("00c39beac93db21c3266084429eb9b846b787c094f23a4de66447efbb3"));
byte[] M = Hex.decode("E5D5A7ADF73C5476FAEE93A2C76CE94DC0557DB04CDC189504779117920B896D");
ECDSASigner dsa = new ECDSASigner();
dsa.init(true, new ParametersWithRandom(priKey, k));
BigInteger[] sig = dsa.generateSignature(M);
BigInteger r = new BigInteger("8163E5941BED41DA441B33E653C632A55A110893133351E20CE7CB75", 16);
BigInteger s = new BigInteger("D12C3FC289DDD5F6890DCE26B65792C8C50E68BF551D617D47DF15A8", 16);
if (!r.equals(sig[0]))
{
fail("r component wrong." + Strings.lineSeparator()
+ " expecting: " + r + Strings.lineSeparator()
+ " got : " + sig[0]);
}
if (!s.equals(sig[1]))
{
fail("s component wrong." + Strings.lineSeparator()
+ " expecting: " + s + Strings.lineSeparator()
+ " got : " + sig[1]);
}
// Verify the signature
ECPublicKeyParameters pubKey = new ECPublicKeyParameters(
params.getCurve().decodePoint(Hex.decode("04C5C9B38D3603FCCD6994CBB9594E152B658721E483669BB42728520F484B537647EC816E58A8284D3B89DFEDB173AFDC214ECA95A836FA7C")), // Q
params);
dsa.init(false, pubKey);
if (!dsa.verifySignature(M, sig[0], sig[1]))
{
fail("signature fails");
}
}