/** * Get the parameter specification for a one-time password generated using the given algorithm, seed, and sequence number. * * @param algorithm the algorithm * @param seed the seed * @param sequenceNumber the sequence number * @return the parameter specification for a one-time password generated using the given algorithm, seed, and sequence number */ public static OneTimePasswordAlgorithmSpec getOTPParameterSpec(final String algorithm, final String seed, final int sequenceNumber) { return new OneTimePasswordAlgorithmSpec(algorithm, seed, sequenceNumber); }
/** * Encode the given {@link Password} to a byte array. * * @param password the password to encode * @return a byte array representing the encoded password or null if no encoder was capable to encode the given password */ public static byte[] encode(Password password) throws NoSuchAlgorithmException, InvalidKeySpecException { return encode(password, INSTALLED_PROVIDERS); }
ScramDigestPasswordImpl(final String algorithm, final char[] password, final IteratedSaltedPasswordAlgorithmSpec spec) throws InvalidKeySpecException, NoSuchAlgorithmException, InvalidKeyException { this(algorithm, password, spec.getSalt(), spec.getIterationCount()); }
default boolean impliesParameters(AlgorithmParameterSpec parameterSpec) { Assert.checkNotNullParam("parameterSpec", parameterSpec); if (parameterSpec instanceof IteratedSaltedPasswordAlgorithmSpec) { final IteratedSaltedPasswordAlgorithmSpec spec = (IteratedSaltedPasswordAlgorithmSpec) parameterSpec; return getIterationCount() <= spec.getIterationCount() && Arrays.equals(getParameterSpec().getSalt(), spec.getSalt()); } else if (parameterSpec instanceof SaltedPasswordAlgorithmSpec) { return Arrays.equals(getParameterSpec().getSalt(), ((SaltedPasswordAlgorithmSpec) parameterSpec).getSalt()); } else if (parameterSpec instanceof IteratedPasswordAlgorithmSpec) { return getIterationCount() <= ((IteratedPasswordAlgorithmSpec) parameterSpec).getIterationCount(); } else { return false; } }
private static byte[] encodeIteratedSaltedHashSpec(IteratedSaltedHashPasswordSpec keySpec) throws InvalidKeySpecException { byte[] salt = keySpec.getSalt(); return new ByteStringBuilder().append(ITERATED_SALTED_HASH_SPEC_ID) .appendPackedUnsignedBE(keySpec.getIterationCount()).appendPackedUnsignedBE(salt.length).append(salt).append(keySpec.getHash()).toArray(); }
protected void engineEncode(final ASN1Encoder encoder, final DigestPasswordAlgorithmSpec parameterSpec) { encoder.startSequence(); encoder.encodeOctetString(parameterSpec.getUsername()); encoder.encodeOctetString(parameterSpec.getRealm()); encoder.endSequence(); }
UnixSHACryptPasswordImpl(final String algorithm, final ClearPasswordSpec spec) throws NoSuchAlgorithmException { this(algorithm, spec.getEncodedPassword()); }
DigestPasswordImpl(final String algorithm, final EncryptablePasswordSpec spec) throws InvalidKeySpecException { this(algorithm, spec.getPassword(), (DigestPasswordAlgorithmSpec) spec.getAlgorithmParameterSpec()); }
protected DigestPasswordAlgorithmSpec engineDecode(final ASN1Decoder decoder) { decoder.startSequence(); final String username = decoder.decodeOctetStringAsString(); final String realm = decoder.decodeOctetStringAsString(); decoder.endSequence(); return new DigestPasswordAlgorithmSpec(username, realm); } }
default SaltedPasswordAlgorithmSpec getParameterSpec() { final int salt = getSalt(); byte[] saltBytes = new byte[2]; // Big-endian format saltBytes[0] = (byte) (salt >>> 8 & 0xff); saltBytes[1] = (byte) (salt & 0xff); return new SaltedPasswordAlgorithmSpec(saltBytes); }
private static PasswordSpec decodeIteratedSaltedHashPasswordSpec(ByteIterator iterator) { int iterationCount = iterator.getPackedBE32(); byte[] salt = iterator.drain(iterator.getPackedBE32()); byte[] hash = iterator.drain(); return new IteratedSaltedHashPasswordSpec(hash, salt, iterationCount); }
ScramDigestPasswordImpl(final String algorithm, final char[] password, final SaltedPasswordAlgorithmSpec spec) throws InvalidKeySpecException, NoSuchAlgorithmException, InvalidKeyException { this(algorithm, password, spec.getSalt(), DEFAULT_ITERATION_COUNT); }
default boolean impliesParameters(AlgorithmParameterSpec parameterSpec) { Assert.checkNotNullParam("parameterSpec", parameterSpec); if (parameterSpec instanceof IteratedSaltedPasswordAlgorithmSpec) { final IteratedSaltedPasswordAlgorithmSpec spec = (IteratedSaltedPasswordAlgorithmSpec) parameterSpec; return getIterationCount() <= spec.getIterationCount() && Arrays.equals(getSalt(), spec.getSalt()); } else if (parameterSpec instanceof SaltedPasswordAlgorithmSpec) { return Arrays.equals(getSalt(), ((SaltedPasswordAlgorithmSpec) parameterSpec).getSalt()); } else if (parameterSpec instanceof IteratedPasswordAlgorithmSpec) { return getIterationCount() <= ((IteratedPasswordAlgorithmSpec) parameterSpec).getIterationCount(); } else { return false; } }
MaskedPasswordImpl(final String algorithm, final ClearPasswordSpec keySpec) throws InvalidKeySpecException { this(algorithm, keySpec.getEncodedPassword()); }
protected void engineEncode(final ASN1Encoder encoder, final IteratedSaltedPasswordAlgorithmSpec parameterSpec) { encoder.startSequence(); encoder.encodeInteger(parameterSpec.getIterationCount()); encoder.encodeOctetString(parameterSpec.getSalt()); encoder.endSequence(); }
protected SaltedPasswordAlgorithmSpec engineDecode(final ASN1Decoder decoder) { final byte[] salt = decoder.decodeOctetString(); return new SaltedPasswordAlgorithmSpec(salt); } }
UnixDESCryptPasswordImpl(final char[] passwordChars, SaltedPasswordAlgorithmSpec algorithmSpec) throws InvalidParameterSpecException, InvalidKeyException { this(algorithmSpec.getSalt(), passwordChars); }
default boolean impliesParameters(AlgorithmParameterSpec parameterSpec) { Assert.checkNotNullParam("parameterSpec", parameterSpec); if (parameterSpec instanceof IteratedSaltedPasswordAlgorithmSpec) { final IteratedSaltedPasswordAlgorithmSpec spec = (IteratedSaltedPasswordAlgorithmSpec) parameterSpec; return getIterationCount() <= spec.getIterationCount() && Arrays.equals(getSalt(), spec.getSalt()); } else if (parameterSpec instanceof SaltedPasswordAlgorithmSpec) { return Arrays.equals(getSalt(), ((SaltedPasswordAlgorithmSpec) parameterSpec).getSalt()); } else if (parameterSpec instanceof IteratedPasswordAlgorithmSpec) { return getIterationCount() <= ((IteratedPasswordAlgorithmSpec) parameterSpec).getIterationCount(); } else { return false; } }
default boolean impliesParameters(AlgorithmParameterSpec parameterSpec) { Assert.checkNotNullParam("parameterSpec", parameterSpec); if (parameterSpec instanceof IteratedSaltedPasswordAlgorithmSpec) { final IteratedSaltedPasswordAlgorithmSpec spec = (IteratedSaltedPasswordAlgorithmSpec) parameterSpec; return getIterationCount() <= spec.getIterationCount() && Arrays.equals(getSalt(), spec.getSalt()); } else if (parameterSpec instanceof SaltedPasswordAlgorithmSpec) { return Arrays.equals(getSalt(), ((SaltedPasswordAlgorithmSpec) parameterSpec).getSalt()); } else if (parameterSpec instanceof IteratedPasswordAlgorithmSpec) { return getIterationCount() <= ((IteratedPasswordAlgorithmSpec) parameterSpec).getIterationCount(); } else { return false; } }
default boolean impliesParameters(AlgorithmParameterSpec parameterSpec) { Assert.checkNotNullParam("parameterSpec", parameterSpec); if (parameterSpec instanceof IteratedSaltedPasswordAlgorithmSpec) { final IteratedSaltedPasswordAlgorithmSpec spec = (IteratedSaltedPasswordAlgorithmSpec) parameterSpec; return getIterationCount() <= spec.getIterationCount() && Arrays.equals(getSalt(), spec.getSalt()); } else if (parameterSpec instanceof SaltedPasswordAlgorithmSpec) { return Arrays.equals(getSalt(), ((SaltedPasswordAlgorithmSpec) parameterSpec).getSalt()); } else if (parameterSpec instanceof IteratedPasswordAlgorithmSpec) { return getIterationCount() <= ((IteratedPasswordAlgorithmSpec) parameterSpec).getIterationCount(); } else { return false; } }