@Override public ECParameterSpec getParams() { return this.key.getParams(); }
} else if ("EC".equalsIgnoreCase(keyAlgorithm)) { int keySizeBits = ((ECKey) signingKey).getParams().getOrder().bitLength(); if (keySizeBits <= 256) {
/** * Attempt to acquire parameters of the given type from the given key. * * @param key the key (must not be {@code null}) * @param paramSpecClass the parameter specification class (must not be {@code null}) * @param <P> the parameter specification type * @return the parameters, or {@code null} if no known parameters of the given type are available */ public static <P extends AlgorithmParameterSpec> P getParameters(Key key, Class<P> paramSpecClass) { if (key instanceof Password) { final AlgorithmParameterSpec parameterSpec = ((Password) key).getParameterSpec(); return paramSpecClass.isInstance(parameterSpec) ? paramSpecClass.cast(parameterSpec) : null; } else if (key instanceof RSAKey && paramSpecClass.isAssignableFrom(RSAParameterSpec.class)) { return paramSpecClass.cast(new RSAParameterSpec((RSAKey) key)); } else if (key instanceof DSAKey && paramSpecClass.isAssignableFrom(DSAParams.class)) { return paramSpecClass.cast(((DSAKey) key).getParams()); } else if (key instanceof ECKey && paramSpecClass.isAssignableFrom(ECParameterSpec.class)) { return paramSpecClass.cast(((ECKey) key).getParams()); } else if (key instanceof DHKey && paramSpecClass.isAssignableFrom(DHParameterSpec.class)) { return paramSpecClass.cast(((DHKey) key).getParams()); } else if (key instanceof PBEKey && paramSpecClass.isAssignableFrom(PBEParameterSpec.class)) { final PBEKey pbeKey = (PBEKey) key; final byte[] salt = pbeKey.getSalt(); // TODO: we miss the IV here return salt == null ? null : paramSpecClass.cast(new PBEParameterSpec(salt, pbeKey.getIterationCount())); } else { return null; } }
/** * Get the key size for the given {@code Key}. * * @param key the key * @return the key size or -1 if the key size cannot be determined */ public static int getKeySize(final Key key) { if (key instanceof ECKey) { ECParameterSpec params = ((ECKey) key).getParams(); if (params != null) { return params.getOrder().bitLength(); } } else if (key instanceof DSAKey) { DSAParams params = ((DSAKey) key).getParams(); if (params != null) { return params.getP().bitLength(); } } else if (key instanceof RSAKey) { return ((RSAKey) key).getModulus().bitLength(); } return -1; }
private static int fieldSizeFromKey(ECKey ecPublicKey) { return ecPublicKey.getParams().getCurve().getField().getFieldSize(); } }
int bitLength = ecKey.getParams().getOrder().bitLength();
int size = ecKey.getParams().getOrder().bitLength(); if (size < this.minKeyLength) { String msg = "The " + keyType(signing) + " key's size (ECParameterSpec order) is " + size +
@Override public ECParameterSpec getParams() { return this.key.getParams(); }
/** * @param key The {@link ECKey} - ignored if {@code null} * @return The matching {@link ECCurves} instance - {@code null} if no * match found */ public static ECCurves fromECKey(ECKey key) { return fromCurveParameters((key == null) ? null : key.getParams()); }
/** * @param key The {@link ECKey} - ignored if {@code null} * @return The matching {@link ECCurves} instance - {@code null} if no * match found */ public static ECCurves fromECKey(ECKey key) { return fromCurveParameters((key == null) ? null : key.getParams()); }
/** * @param key The {@link ECKey} - ignored if {@code null} * @return The matching {@link ECCurves} instance - {@code null} if no * match found */ public static ECCurves fromECKey(ECKey key) { return fromCurveParameters((key == null) ? null : key.getParams()); }
ECPublicKey publicKey = (ECPublicKey) generatedCertificate.getPublicKey(); // Bouncy Castle specific class ECNamedCurveSpec params = (ECNamedCurveSpec) publicKey.getParams(); System.out.println(params.getName());
KeyPairGenerator kpg = KeyPairGenerator.getInstance("EC"); ECGenParameterSpec kpgparams = new ECGenParameterSpec("secp256r1"); kpg.initialize(kpgparams); ECParameterSpec params = ((ECPublicKey) kpg.generateKeyPair().getPublic()).getParams();
/** * Determines the name of the domain parameters that were used for generating the key. * * @param key An EC key * @return The name of the domain parameters that were used for the EC key, * or an empty string if curve is unknown. */ public static String getNamedCurve(Key key) { if (!(key instanceof ECKey)) { throw new InvalidParameterException("Not a EC private key."); } ECKey ecKey = (ECKey) key; ECParameterSpec params = ecKey.getParams(); if (!(params instanceof ECNamedCurveSpec)) { return ""; } ECNamedCurveSpec ecPrivateKeySpec = (ECNamedCurveSpec) params; String namedCurve = ecPrivateKeySpec.getName(); return namedCurve; }
/** * Wraps the provided private key for use in the TLS/SSL stack only. Sign/decrypt operations * using the key will be delegated to the {@code Signature}/{@code Cipher} implementation of the * provider which accepts the key. */ static OpenSSLKey wrapJCAPrivateKeyForTLSStackOnly(PrivateKey privateKey, PublicKey publicKey) throws InvalidKeyException { ECParameterSpec params = null; if (privateKey instanceof ECKey) { params = ((ECKey) privateKey).getParams(); } else if (publicKey instanceof ECKey) { params = ((ECKey) publicKey).getParams(); } if (params == null) { throw new InvalidKeyException("EC parameters not available. Private: " + privateKey + ", public: " + publicKey); } return wrapJCAPrivateKeyForTLSStackOnly(privateKey, params); }
/** * Wraps the provided private key for use in the TLS/SSL stack only. Sign/decrypt operations * using the key will be delegated to the {@code Signature}/{@code Cipher} implementation of the * provider which accepts the key. */ static OpenSSLKey wrapJCAPrivateKeyForTLSStackOnly(PrivateKey privateKey, PublicKey publicKey) throws InvalidKeyException { ECParameterSpec params = null; if (privateKey instanceof ECKey) { params = ((ECKey) privateKey).getParams(); } else if (publicKey instanceof ECKey) { params = ((ECKey) publicKey).getParams(); } if (params == null) { throw new InvalidKeyException("EC parameters not available. Private: " + privateKey + ", public: " + publicKey); } return wrapJCAPrivateKeyForTLSStackOnly(privateKey, params); }
public String getCurveID(Key key) throws KeyNotSupportedException { if (key instanceof ECKey) { ECParameterSpec spec = ((ECKey) key).getParams(); if (spec instanceof ECNamedCurveSpec) { return ((ECNamedCurveSpec) spec).getName(); } else return null; } else { throw new KeyNotSupportedException("Key is not an elliptic curve key!"); } }