/** * Attempt to determine if the two keys have the same parameters. This method returns {@code true} if the keys * definitely have the same parameters, or {@code false} if they do not or if parameter equivalency cannot be determined. * * @param key1 the first key (must not be {@code null}) * @param key2 the second key (must not be {@code null}) * @return {@code true} if the parameters are definitely equal, {@code false} otherwise */ public static boolean hasSameParameters(final Key key1, final Key key2) { Assert.checkNotNullParam("key1", key1); Assert.checkNotNullParam("key2", key2); final AlgorithmParameterSpec param1 = getParameters(key1, AlgorithmParameterSpec.class); final AlgorithmParameterSpec param2 = getParameters(key2, AlgorithmParameterSpec.class); return param1 == null && param2 == null || param1 != null && param2 != null && parametersEqual(param1, param2); }
ParamKey(final AlgorithmParameterSpec parameterSpec) { this.parameterSpec = parameterSpec; this.hashCode = KeyUtil.parametersHashCode(parameterSpec); }
public SecretKeyCredential clone() { final SecretKey secretKey = this.secretKey; final SecretKey clone = KeyUtil.cloneKey(SecretKey.class, secretKey); return clone == secretKey ? this : new SecretKeyCredential(clone); }
/** * Attempt to acquire parameters from the given key. * * @param key the key (must not be {@code null}) * @return the parameters, or {@code null} if no known parameters are available */ public static AlgorithmParameterSpec getParameters(Key key) { return getParameters(key, AlgorithmParameterSpec.class); }
private boolean isUnsupported(final Class<? extends Credential> testCredentialType, final String testAlgorithmName, final AlgorithmParameterSpec testParameterSpec) { return credentialType.isAssignableFrom(testCredentialType) && (algorithmName == null || algorithmName.equals(testAlgorithmName)) && (parameterSpec == null || KeyUtil.parametersEqual(parameterSpec, testParameterSpec)); }
public boolean impliesSameParameters(final AlgorithmCredential other) { return KeyUtil.hasParameters(secretKey, other.getParameters()); }
/** * Construct a new instance. * * @param keyPair the key pair (may not be {@code null}) */ public KeyPairCredential(final KeyPair keyPair) { Assert.checkNotNullParam("keyPair", keyPair); final PublicKey publicKey = keyPair.getPublic(); if (publicKey == null) { throw ElytronMessages.log.publicKeyIsNull(); } final PrivateKey privateKey = keyPair.getPrivate(); if (privateKey == null) { throw ElytronMessages.log.privateKeyIsNull(); } if (! publicKey.getAlgorithm().equals(privateKey.getAlgorithm())) { throw ElytronMessages.log.mismatchedPublicPrivateKeyAlgorithms(); } if (! KeyUtil.hasSameParameters(publicKey, privateKey)) { throw ElytronMessages.log.mismatchedPublicPrivateKeyParameters(); } this.keyPair = keyPair; }
public <P extends AlgorithmParameterSpec> P getParameters(final Class<P> paramSpecClass) { return KeyUtil.getParameters(secretKey, paramSpecClass); }
/** * Acquire a credential of the given type and algorithm name. Realms which support more than one credential of a * given type and algorithm must override this method. * * @param credentialType the credential type class (must not be {@code null}) * @param algorithmName the algorithm name, or {@code null} if any algorithm is acceptable or the credential type * does not support algorithm names * @param parameterSpec the algorithm parameters to match, or {@code null} if any parameters are acceptable or the credential type * does not support algorithm parameters * @param <C> the credential type * * @return the credential, or {@code null} if no such credential exists * * @throws RealmUnavailableException if the realm is not able to handle requests for any reason */ default <C extends Credential> C getCredential(Class<C> credentialType, String algorithmName, AlgorithmParameterSpec parameterSpec) throws RealmUnavailableException { final C credential = getCredential(credentialType, algorithmName); if (parameterSpec != null) { if (! (credential instanceof AlgorithmCredential)) { return null; } return KeyUtil.parametersEqual(parameterSpec, ((AlgorithmCredential) credential).getParameters()) ? credential : null; } else { return credential; } }
public boolean impliesSameParameters(final AlgorithmCredential other) { return KeyUtil.hasParameters(keyPair.getPublic(), other.getParameters()); }
/** * Construct a new instance. * * @param keyPair the key pair (may not be {@code null}) */ public KeyPairCredential(final KeyPair keyPair) { Assert.checkNotNullParam("keyPair", keyPair); final PublicKey publicKey = keyPair.getPublic(); if (publicKey == null) { throw ElytronMessages.log.publicKeyIsNull(); } final PrivateKey privateKey = keyPair.getPrivate(); if (privateKey == null) { throw ElytronMessages.log.privateKeyIsNull(); } if (! publicKey.getAlgorithm().equals(privateKey.getAlgorithm())) { throw ElytronMessages.log.mismatchedPublicPrivateKeyAlgorithms(); } if (! KeyUtil.hasSameParameters(publicKey, privateKey)) { throw ElytronMessages.log.mismatchedPublicPrivateKeyParameters(); } this.keyPair = keyPair; }
/** * Determine if the given key has parameters which match the given parameters. * * @param key the key (must not be {@code null}) * @param parameters the parameters (must not be {@code null}) * @return {@code true} if the parameters match, {@code false} otherwise */ public static boolean hasParameters(final Key key, final AlgorithmParameterSpec parameters) { Assert.checkNotNullParam("key", key); Assert.checkNotNullParam("parameters", parameters); final AlgorithmParameterSpec keyParameters = getParameters(key, AlgorithmParameterSpec.class); return keyParameters != null && parametersEqual(keyParameters, parameters); }
public boolean supportsParameters(final Class<? extends AlgorithmParameterSpec> paramSpecClass) { return KeyUtil.getParameters(publicKey, paramSpecClass) != null; }
final AlgorithmParameterSpec param1 = pbe1.getParameterSpec(); final AlgorithmParameterSpec param2 = pbe2.getParameterSpec(); return pbe1.getIterationCount() == pbe2.getIterationCount() && Arrays.equals(pbe1.getSalt(), pbe2.getSalt()) && (param1 == null ? param2 == null : param2 != null && parametersEqual(param1, param2)); } else if (p1 instanceof IvParameterSpec && p2 instanceof IvParameterSpec) { final IvParameterSpec iv1 = (IvParameterSpec) p1;
public boolean impliesSameParameters(final AlgorithmCredential other) { return KeyUtil.hasParameters(publicKey, other.getParameters()); }
final PBEParameterSpec pbeSpec = (PBEParameterSpec) param; final AlgorithmParameterSpec parameterSpec = pbeSpec.getParameterSpec(); return (pbeSpec.getIterationCount() * 31 + Arrays.hashCode(pbeSpec.getSalt())) * 31 + parametersHashCode(parameterSpec); } else if (param instanceof IvParameterSpec) { return Arrays.hashCode(((IvParameterSpec) param).getIV());
public KeyPairCredential clone() { final PrivateKey privateKey = keyPair.getPrivate(); final PrivateKey clone = KeyUtil.cloneKey(PrivateKey.class, privateKey); return privateKey == clone ? this : new KeyPairCredential(new KeyPair(keyPair.getPublic(), clone)); }
/** * Construct a new instance. * * @param keyPair the key pair (may not be {@code null}) */ public KeyPairCredential(final KeyPair keyPair) { Assert.checkNotNullParam("keyPair", keyPair); final PublicKey publicKey = keyPair.getPublic(); if (publicKey == null) { throw ElytronMessages.log.publicKeyIsNull(); } final PrivateKey privateKey = keyPair.getPrivate(); if (privateKey == null) { throw ElytronMessages.log.privateKeyIsNull(); } if (! publicKey.getAlgorithm().equals(privateKey.getAlgorithm())) { throw ElytronMessages.log.mismatchedPublicPrivateKeyAlgorithms(); } if (! KeyUtil.hasSameParameters(publicKey, privateKey)) { throw ElytronMessages.log.mismatchedPublicPrivateKeyParameters(); } this.keyPair = keyPair; }
/** * Attempt to determine if the two keys have the same parameters. This method returns {@code true} if the keys * definitely have the same parameters, or {@code false} if they do not or if parameter equivalency cannot be determined. * * @param key1 the first key (must not be {@code null}) * @param key2 the second key (must not be {@code null}) * @return {@code true} if the parameters are definitely equal, {@code false} otherwise */ public static boolean hasSameParameters(final Key key1, final Key key2) { Assert.checkNotNullParam("key1", key1); Assert.checkNotNullParam("key2", key2); final AlgorithmParameterSpec param1 = getParameters(key1, AlgorithmParameterSpec.class); final AlgorithmParameterSpec param2 = getParameters(key2, AlgorithmParameterSpec.class); return param1 == null && param2 == null || param1 != null && param2 != null && parametersEqual(param1, param2); }
public boolean supportsParameters(final Class<? extends AlgorithmParameterSpec> paramSpecClass) { return KeyUtil.getParameters(secretKey, paramSpecClass) != null; }