List of usage examples for org.bouncycastle.jce.spec ECParameterSpec getN
public BigInteger getN()
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 .j a v a2 s. c om 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 w w w.jav a2 s . c o m*/ }
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);/* w w w . j a v a2s .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//from w w w. j a v a2 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) { // 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/*from www .j av a 2s.c o 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 www . j a v a 2 s . co 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; }