List of usage examples for org.bouncycastle.jce.spec ECParameterSpec ECParameterSpec
public ECParameterSpec(ECCurve curve, ECPoint G, BigInteger n)
From source file:card.CardClient.java
License:Open Source License
/** * Initialise the cryptographic parameters on the card * /*from w w w .ja va 2 s . c o m*/ * @param p Prime number for the finite field F_P * @param a A parameter defining the curve: y^2 = x^3 + Ax + B (mod P) * @param b B parameter defining the curve: y^2 = x^3 + Ax + B (mod P) * @param g Generator point on the curve * @param r Order of the generator * @return */ public ECPoint initialise(BigInteger p, BigInteger r, BigInteger a, BigInteger b, ECPoint g) { try { curve = new ECCurve.Fp(p, a, b); ecParams = new ECParameterSpec(curve, g, r); ecDom = new ECDomainParameters(curve, g, r); keyGen = KeyPairGenerator.getInstance("ECDH", "BC"); keyGen.initialize(ecParams); keys = keyGen.generateKeyPair(); } catch (Exception e) { e.printStackTrace(); } return ((ECPublicKey) keys.getPublic()).getQ(); }
From source file:com.netflix.msl.keyx.AsymmetricWrappedExchangeSuite.java
License:Open Source License
@BeforeClass public static synchronized void setup() throws NoSuchAlgorithmException, InvalidAlgorithmParameterException, MslEncodingException, MslCryptoException { if (ctx == null) { Security.addProvider(new BouncyCastleProvider()); final ECCurve curve = new ECCurve.Fp(EC_Q, EC_A, EC_B); final AlgorithmParameterSpec paramSpec = new ECParameterSpec(curve, curve.decodePoint(EC_G.toByteArray()), EC_N); final KeyPairGenerator eccGenerator = KeyPairGenerator.getInstance("ECIES"); eccGenerator.initialize(paramSpec); final KeyPair eccKeyPair = eccGenerator.generateKeyPair(); ECC_PUBLIC_KEY = eccKeyPair.getPublic(); ECC_PRIVATE_KEY = eccKeyPair.getPrivate(); final KeyPairGenerator rsaGenerator = KeyPairGenerator.getInstance("RSA"); rsaGenerator.initialize(2048);//from www .j a va 2 s .c o m final KeyPair rsaKeyPair = rsaGenerator.generateKeyPair(); RSA_PUBLIC_KEY = rsaKeyPair.getPublic(); RSA_PRIVATE_KEY = rsaKeyPair.getPrivate(); ctx = new MockMslContext(EntityAuthenticationScheme.PSK, false); MASTER_TOKEN = MslTestUtils.getMasterToken(ctx, 1, 1); ENCRYPTION_KEY = MASTER_TOKEN.getEncryptionKey().getEncoded(); HMAC_KEY = MASTER_TOKEN.getHmacKey().getEncoded(); } }
From source file:de.tsenger.animamea.asn1.DomainParameter.java
License:Open Source License
/** * Extrahiert aus dem AlogorithmIdentifier die Parameter fr DH oder ECDH. * Es werden standardisierte DomainParameter und explizite DP erkannt. * @param algorithm OID/* w w w .j a va2s . c o m*/ */ public DomainParameter(AlgorithmIdentifier aid) { if (aid.getAlgorithm().toString().equals(BSIObjectIdentifiers.standardizedDomainParameters.toString())) { int dpref = ((ASN1Integer) aid.getParameters()).getPositiveValue().intValue(); getParameters(dpref); } else if (aid.getAlgorithm().toString().equals("1.2.840.10045.2.1")) { X9ECParameters x9ecp = X9ECParameters.getInstance(aid.getParameters()); ecSpec = new ECParameterSpec(x9ecp.getCurve(), x9ecp.getG(), x9ecp.getN()); } //TODO properitre DH Domain Parameter else throw new UnsupportedOperationException( "unsupported Domain Parameters. Algorithm OID: " + aid.getAlgorithm().toString()); }
From source file:de.tsenger.animamea.ta.TerminalAuthenticationECDSA.java
License:Open Source License
/** * @param caDomainParameter/*from ww w . j av a2 s.co m*/ * @param ecParams * @param privateKey */ public TerminalAuthenticationECDSA(DomainParameter caDomainParameter, AmECPublicKey taPublicKey, BigInteger taSecretKey) { super(caDomainParameter); ECCurve.Fp curve = (Fp) taPublicKey.getParameters().getCurve(); ECPoint pointG = taPublicKey.getParameters().getG(); ecp = new ECParameterSpec(curve, pointG, taPublicKey.getParameters().getN()); if (taPublicKey.getOID().toString().equals(BSIObjectIdentifiers.id_TA_ECDSA_SHA_1.toString())) { signingAlgorithm = "SHA1withECDSA"; } else if (taPublicKey.getOID().toString().equals(BSIObjectIdentifiers.id_TA_ECDSA_SHA_224.toString())) { signingAlgorithm = "SHA224withECDSA"; } else if (taPublicKey.getOID().toString().equals(BSIObjectIdentifiers.id_TA_ECDSA_SHA_256.toString())) { signingAlgorithm = "SHA256withECDSA"; } else if (taPublicKey.getOID().toString().equals(BSIObjectIdentifiers.id_TA_ECDSA_SHA_384.toString())) { signingAlgorithm = "SHA384withECDSA"; } else if (taPublicKey.getOID().toString().equals(BSIObjectIdentifiers.id_TA_ECDSA_SHA_512.toString())) { signingAlgorithm = "SHA512withECDSA"; } this.terminalSK = taSecretKey; }
From source file:jpcsp.crypto.ECDSA.java
License:Open Source License
public void setCurve() { try {/* w w w . j ava2 s . c o m*/ curve = new ECCurve.Fp(new BigInteger("FFFFFFFFFFFFFFFF00000001FFFFFFFFFFFFFFFF", 16), // p new BigInteger("FFFFFFFFFFFFFFFF00000001FFFFFFFFFFFFFFFC", 16), // a new BigInteger("A68BEDC33418029C1D3CE33B9A321FCCBB9E0F0B", 16)); // b spec = new ECParameterSpec(curve, curve.createPoint(new BigInteger("128EC4256487FD8FDF64E2437BC0A1F6D5AFDE2C", 16), new BigInteger("5958557EB1DB001260425524DBC379D5AC5F4ADF", 16), false), // G new BigInteger("00FFFFFFFFFFFFFFFEFFFFB5AE3C523E63944F2127", 16)); // n g = KeyPairGenerator.getInstance("ECDSA", "BC"); f = KeyFactory.getInstance("ECDSA", "BC"); g.initialize(spec, new SecureRandom()); keyPair = g.generateKeyPair(); } catch (Exception e) { log.error("setCurve", e); } }
From source file:service.ACService.java
License:Open Source License
public ACService(byte[][] attrValues) { c = constructCurve(KEY_LENGTH);/*w ww.ja va 2 s. co m*/ System.out.println("P:" + Hex.toHexString(c.getP().toByteArray())); System.out.println("R:" + Hex.toHexString(c.getR().toByteArray())); System.out.println("A:" + Hex.toHexString(c.getA().toBigInteger().toByteArray())); System.out.println("B:" + Hex.toHexString(c.getB().toBigInteger().toByteArray())); System.out.println("Gx:" + Hex.toHexString(c.getG().getX().toBigInteger().toByteArray())); System.out.println("Gy:" + Hex.toHexString(c.getG().getY().toBigInteger().toByteArray())); c_params = new ECParameterSpec(c, c.getG(), c.getR()); // Construct the fixed point on the curve Q = constructFixedPoint(c); // Construct a number of attributes this.a = constructAttributes(attrValues); // Construct the private keys for the attributes sa = constructPrivateAttributeKeys(c); // Construct the public keys for the attributes from sa and Q saQ = constructPublicAttributeKeys(sa, Q); }
From source file:terminal.GateClient.java
License:Open Source License
public GateClient() { // Register BouncyCastle as a SecurityProvider Security.addProvider(new BouncyCastleProvider()); // Initialise the signer try {//from ww w .ja v a2 s . com signer = Signature.getInstance("SHA1WITHECDSA", "BC"); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (NoSuchProviderException e) { e.printStackTrace(); } // Select the CardInterface to use //if (SIMULATE) { //card = new CardClient(); card = new CardProxy(); //} else { //card = new CardProxy(); //} // Construct an Elliptic Curve based on the KEY_LENGTH used by the card c = constructCurve(KEY_LENGTH); c_params = new ECParameterSpec(c, c.getG(), c.getR()); // Construct the fixed point on the curve Q = constructFixedPoint(c); // Construct a number of attributes a = constructAttributes(); // Construct the private keys for the attributes sa = constructPrivateAttributeKeys(c); // Construct the public keys for the attributes from sa and Q saQ = constructPublicAttributeKeys(sa, Q); }