List of usage examples for org.bouncycastle.jce.spec ECParameterSpec getCurve
public ECCurve getCurve()
From source file:com.sydefolk.crypto.zrtp.EC25SecretCalculator.java
License:Open Source License
@Override public byte[] calculateKeyAgreement(KeyPair localKey, byte[] publicKeyBytes) { // Log.w("EC25SecretCalculator", "Calculating EC25 Secret..."); try {/*from www . j a v a 2s . c o m*/ byte[] x = new byte[32]; byte[] y = new byte[32]; System.arraycopy(publicKeyBytes, 0, x, 0, x.length); System.arraycopy(publicKeyBytes, x.length, y, 0, y.length); ECParameterSpec params = ECNamedCurveTable.getParameterSpec("secp256r1"); ECPoint point = params.getCurve().createPoint(Conversions.byteArrayToBigInteger(x), Conversions.byteArrayToBigInteger(y), false); ECPublicKeySpec keySpec = new ECPublicKeySpec(point, params); KeyFactory keyFactory = KeyFactory.getInstance("ECDH", "BC"); PublicKey publicKey = keyFactory.generatePublic(keySpec); KeyAgreement agreement = KeyAgreement.getInstance("ECDH", "BC"); agreement.init(localKey.getPrivate()); agreement.doPhase(publicKey, true); return agreement.generateSecret(); } catch (NoSuchProviderException nspe) { throw new AssertionError(nspe); } catch (NoSuchAlgorithmException e) { throw new AssertionError(e); } catch (InvalidKeyException e) { throw new IllegalArgumentException(e); } catch (InvalidKeySpecException e) { throw new IllegalArgumentException(e); } }
From source file:com.yahoo.athenz.zts.store.DataStore.java
License:Apache License
String getCurveName(org.bouncycastle.jce.spec.ECParameterSpec ecParameterSpec) { String curveName = null;/*from w w w. jav a2 s . com*/ for (Enumeration names = ECNamedCurveTable.getNames(); names.hasMoreElements();) { final String name = (String) names.nextElement(); final X9ECParameters params = ECNamedCurveTable.getByName(name); if (params.getN().equals(ecParameterSpec.getN()) && params.getH().equals(ecParameterSpec.getH()) && params.getCurve().equals(ecParameterSpec.getCurve()) && params.getG().equals(ecParameterSpec.getG())) { curveName = name; break; } } return curveName; }
From source file:com.yahoo.athenz.zts.store.DataStoreTest.java
License:Apache License
@Test public void testGetInvalidCurveName() { ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0"); DataStore store = new DataStore(clogStore, null); ECParameterSpec spec = Mockito.mock(ECParameterSpec.class); Mockito.when(spec.getCurve()).thenReturn(null); Mockito.when(spec.getG()).thenReturn(null); Mockito.when(spec.getH()).thenReturn(new BigInteger("100")); Mockito.when(spec.getN()).thenReturn(new BigInteger("100")); assertNull(store.getCurveName(spec)); }
From source file:common.crypto.bouncycastle.CEcdsaSignerBC.java
License:Open Source License
@Override public void initialize(String szCurveName, CryptoTypes.ESHAMode eShaMode) { ECParameterSpec paramSpec = ECNamedCurveTable.getParameterSpec(szCurveName); m_eccParameter = new ECDomainParameters(paramSpec.getCurve(), paramSpec.getG(), paramSpec.getN()); m_signer = new ECDSASigner(); m_shaHash = new CCryptoSHABC(); m_shaHash.initialize(eShaMode);//from ww w . j av a 2 s. co m }
From source file:de.tsenger.animamea.ca.ChipAuthenticationECDH.java
License:Open Source License
public ChipAuthenticationECDH(ECParameterSpec ecp) { curve = (org.bouncycastle.math.ec.ECCurve.Fp) ecp.getCurve(); }
From source file:de.tsenger.animamea.pace.PaceECDH.java
License:Open Source License
public PaceECDH(ECParameterSpec ecParameterSpec) { pointG = ecParameterSpec.getG();//from ww w . j av a 2s .c om curve = (org.bouncycastle.math.ec.ECCurve.Fp) ecParameterSpec.getCurve(); Random rnd = new Random(); randomGenerator.setSeed(rnd.nextLong()); }
From source file:dorkbox.util.crypto.CryptoECC.java
License:Apache License
public static AsymmetricCipherKeyPair generateKeyPair(ECParameterSpec eccSpec, SecureRandom secureRandom) { ECKeyGenerationParameters ecParams = new ECKeyGenerationParameters( new ECDomainParameters(eccSpec.getCurve(), eccSpec.getG(), eccSpec.getN()), secureRandom); ECKeyPairGenerator ecKeyGen = new ECKeyPairGenerator(); ecKeyGen.init(ecParams);/*from ww w.j a v a 2 s. c o m*/ return ecKeyGen.generateKeyPair(); }
From source file:eu.europa.ec.markt.dss.DSSPKUtils.java
License:Open Source License
/** * This method returns the public key size extracted from public key infrastructure. * * @param publicKey//www. ja v a 2s . c om * @return */ public static int getPublicKeySize(final PublicKey publicKey) { int publicKeySize = -1; if (publicKey instanceof RSAPublicKey) { RSAPublicKey rsaPublicKey = (RSAPublicKey) publicKey; publicKeySize = rsaPublicKey.getModulus().bitLength(); } else if (publicKey instanceof JCEECPublicKey) { /** * The security of EC systems relies on the size of q, and the size of an EC key refers to the bit-length of * the subgroup size q. */ final JCEECPublicKey jceecPublicKey = (JCEECPublicKey) publicKey; ECParameterSpec spec = jceecPublicKey.getParameters(); if (spec != null) { publicKeySize = spec.getN().bitLength(); } else { // We support the key, but we don't know the key length publicKeySize = 0; // publicKeySize = jceecPublicKey.getQ().getCurve().getFieldSize(); } } else if (publicKey instanceof ECPublicKey) { ECPublicKey ecPublicKey = (ECPublicKey) publicKey; java.security.spec.ECParameterSpec spec = ecPublicKey.getParams(); if (spec != null) { // TODO: (Bob: 20130528) To be checked (need an example) publicKeySize = spec.getCurve().getField().getFieldSize(); } else { publicKeySize = 0; } } else if (publicKey instanceof DSAPublicKey) { DSAPublicKey dsaPublicKey = (DSAPublicKey) publicKey; publicKeySize = dsaPublicKey.getParams().getP().bitLength(); } else { LOG.error("Unknown public key infrastructure: " + publicKey.getClass().getName()); } return publicKeySize; }
From source file:eu.europa.ec.markt.dss.validation102853.toolbox.PublicKeyUtils.java
License:Open Source License
/** * This method returns the public key size extracted from public key infrastructure. * * @param publicKey/* w w w .j a va 2 s . co m*/ * @return */ public static int getPublicKeySize(final PublicKey publicKey) { int publicKeySize = -1; if (publicKey instanceof RSAPublicKeyImpl) { RSAPublicKeyImpl rsaPublicKey = (RSAPublicKeyImpl) publicKey; publicKeySize = rsaPublicKey.getModulus().bitLength(); } else if (publicKey instanceof JCERSAPublicKey) { final JCERSAPublicKey rsaPublicKey = (JCERSAPublicKey) publicKey; publicKeySize = rsaPublicKey.getModulus().bitLength(); } else if (publicKey instanceof JCEECPublicKey) { /** * The security of EC systems relies on the size of q, and the size of an EC key refers to the bit-length of * the subgroup size q. */ final JCEECPublicKey jceecPublicKey = (JCEECPublicKey) publicKey; ECParameterSpec spec = jceecPublicKey.getParameters(); if (spec != null) { publicKeySize = spec.getN().bitLength(); } else { // We support the key, but we don't know the key length publicKeySize = 0; // publicKeySize = jceecPublicKey.getQ().getCurve().getFieldSize(); } } else if (publicKey instanceof ECPublicKey) { ECPublicKey ecPublicKey = (ECPublicKey) publicKey; java.security.spec.ECParameterSpec spec = ecPublicKey.getParams(); if (spec != null) { // TODO: (Bob: 20130528) To be checked (need an example) publicKeySize = spec.getCurve().getField().getFieldSize(); } else { publicKeySize = 0; } } else if (publicKey instanceof DSAPublicKeyImpl) { DSAPublicKeyImpl dsaPublicKeyImpl = (DSAPublicKeyImpl) publicKey; publicKeySize = dsaPublicKeyImpl.getParams().getP().bitLength(); } else if (publicKey instanceof JDKDSAPublicKey) { JDKDSAPublicKey dsaPublicKeyImpl = (JDKDSAPublicKey) publicKey; publicKeySize = dsaPublicKeyImpl.getParams().getP().bitLength(); } else { LOG.warning("Unknown public key infrastructure: " + publicKey.getClass().getName()); } return publicKeySize; }
From source file:eu.europa.esig.dss.DSSPKUtils.java
License:Open Source License
/** * This method returns the public key size extracted from public key infrastructure. * * @param publicKey/*from w w w . j ava 2 s. c o m*/ * @return */ public static int getPublicKeySize(final PublicKey publicKey) { int publicKeySize = -1; if (publicKey instanceof RSAPublicKey) { RSAPublicKey rsaPublicKey = (RSAPublicKey) publicKey; publicKeySize = rsaPublicKey.getModulus().bitLength(); } else if (publicKey instanceof JCEECPublicKey) { /** * The security of EC systems relies on the size of q, and the size of an EC key refers to the bit-length of * the subgroup size q. */ final JCEECPublicKey jceecPublicKey = (JCEECPublicKey) publicKey; ECParameterSpec spec = jceecPublicKey.getParameters(); if (spec != null) { publicKeySize = spec.getN().bitLength(); } else { // We support the key, but we don't know the key length publicKeySize = 0; // publicKeySize = jceecPublicKey.getQ().getCurve().getFieldSize(); } } else if (publicKey instanceof ECPublicKey) { ECPublicKey ecPublicKey = (ECPublicKey) publicKey; java.security.spec.ECParameterSpec spec = ecPublicKey.getParams(); if (spec != null) { publicKeySize = spec.getCurve().getField().getFieldSize(); } else { publicKeySize = 0; } } else if (publicKey instanceof DSAPublicKey) { DSAPublicKey dsaPublicKey = (DSAPublicKey) publicKey; publicKeySize = dsaPublicKey.getParams().getP().bitLength(); } else { LOG.error("Unknown public key infrastructure: " + publicKey.getClass().getName()); } return publicKeySize; }