/** * Attempt to identify the algorithm used by the given crypt string password. * * @param chars the password crypt string characters * @return the algorithm name, or {@code null} if no algorithm could be guessed */ public static String identifyAlgorithm(char[] chars) { return getAlgorithmNameString(doIdentifyAlgorithm(chars)); }
private static Password parseUnixSHA256CryptPasswordString(char[] cryptString) throws InvalidKeySpecException { assert cryptString[0] == '$'; // previously tested by doIdentifyAlgorithm assert cryptString[1] == '5'; // previously tested by doIdentifyAlgorithm assert cryptString[2] == '$'; // previously tested by doIdentifyAlgorithm return parseUnixSHACryptPassword(cryptString, SHA_256_IDX_REV, ALGORITHM_CRYPT_SHA_256); }
SunUnixMD5CryptPasswordImpl(final String algorithm, final char[] password) throws NoSuchAlgorithmException { this(algorithm, password, PasswordUtil.generateRandomSalt(DEFAULT_SALT_SIZE), DEFAULT_ITERATION_COUNT); }
/** * Decode the given string and creates a {@link Password} instance. * * @param cryptString the string representing the encoded format of the password * @return a {@link Password} instance created from the given string * @throws InvalidKeySpecException if the given password is not supported or could be decoded */ public static Password decode(String cryptString) throws InvalidKeySpecException { Assert.checkNotNullParam("cryptString", cryptString); return decode(cryptString.toCharArray()); }
/** * Encode the given {@link Password} to a string. * * @param password the password to encode * @return a string representing the encoded password * @throws InvalidKeySpecException if the given password is not supported or could be encoded */ public static String encodeAsString(Password password) throws InvalidKeySpecException { return getCryptStringToBuilder(password).toString(); }
SaltedSimpleDigestPasswordImpl(final String algorithm, final char[] password) throws InvalidKeySpecException { this(algorithm, PasswordUtil.generateRandomSalt(DEFAULT_SALT_SIZE), password); }
private static Password parseUnixSHA512CryptPasswordString(char[] cryptString) throws InvalidKeySpecException { assert cryptString[0] == '$'; // previously tested by doIdentifyAlgorithm assert cryptString[1] == '6'; // previously tested by doIdentifyAlgorithm assert cryptString[2] == '$'; // previously tested by doIdentifyAlgorithm return parseUnixSHACryptPassword(cryptString, SHA_512_IDX_REV, ALGORITHM_CRYPT_SHA_512); }
/** * Encode the given {@link Password} to a char array. * * @param password the password to encode * @return a char array representing the encoded password * @throws InvalidKeySpecException if the given password is not supported or could be encoded */ public static char[] encode(Password password) throws InvalidKeySpecException { StringBuilder b = getCryptStringToBuilder(password); char[] chars = new char[b.length()]; b.getChars(0, b.length(), chars, 0); return chars; }
UnixSHACryptPasswordImpl(final String algorithm, final char[] passwordChars) throws NoSuchAlgorithmException { this(algorithm, PasswordUtil.generateRandomSalt(SALT_SIZE), DEFAULT_ITERATION_COUNT, passwordChars); }
UnixMD5CryptPasswordImpl(final char[] password) throws NoSuchAlgorithmException { this(password, PasswordUtil.generateRandomSalt(SALT_SIZE)); }
ScramDigestPasswordImpl(final String algorithm, final char[] password) throws InvalidKeySpecException, NoSuchAlgorithmException, InvalidKeyException { this(algorithm, password, PasswordUtil.generateRandomSalt(DEFAULT_SALT_SIZE), DEFAULT_ITERATION_COUNT); }
MaskedPasswordImpl(final String algorithm, final char[] clearPassword) throws InvalidKeySpecException { this(algorithm, DEFAULT_PBE_KEY, DEFAULT_ITERATION_COUNT, PasswordUtil.generateRandomSalt(DEFAULT_SALT_SIZE), clearPassword); }
MaskedPasswordImpl(final String algorithm, final char[] clearPassword, final IteratedPasswordAlgorithmSpec parameterSpec) throws InvalidKeySpecException { this(algorithm, DEFAULT_PBE_KEY, parameterSpec.getIterationCount(), PasswordUtil.generateRandomSalt(DEFAULT_SALT_SIZE), clearPassword); }
ScramDigestPasswordImpl(final String algorithm, final ClearPasswordSpec spec) throws InvalidKeySpecException, NoSuchAlgorithmException, InvalidKeyException { this(algorithm, spec.getEncodedPassword(), PasswordUtil.generateRandomSalt(DEFAULT_SALT_SIZE), DEFAULT_ITERATION_COUNT); }
ScramDigestPasswordImpl(final String algorithm, final char[] password, final IteratedPasswordAlgorithmSpec spec) throws InvalidKeySpecException, NoSuchAlgorithmException, InvalidKeyException { this(algorithm, password, PasswordUtil.generateRandomSalt(DEFAULT_SALT_SIZE), spec.getIterationCount()); }
SunUnixMD5CryptPasswordImpl(final String algorithm, final char[] password, final IteratedPasswordAlgorithmSpec spec) throws NoSuchAlgorithmException { this(algorithm, password, PasswordUtil.generateRandomSalt(DEFAULT_SALT_SIZE), spec.getIterationCount()); }
BCryptPasswordImpl(final char[] password) throws InvalidKeySpecException { this.salt = PasswordUtil.generateRandomSalt(BCRYPT_SALT_SIZE); this.iterationCount = DEFAULT_ITERATION_COUNT; this.hash = bcrypt(this.iterationCount, this.salt, getNormalizedPasswordBytes(password)); }
BCryptPasswordImpl(final char[] password, final IteratedPasswordAlgorithmSpec spec) throws InvalidKeySpecException { this.salt = PasswordUtil.generateRandomSalt(BCRYPT_SALT_SIZE); this.iterationCount = spec.getIterationCount(); this.hash = bcrypt(this.iterationCount, this.salt, getNormalizedPasswordBytes(password)); }
UnixMD5CryptPasswordImpl(final ClearPasswordSpec spec) throws NoSuchAlgorithmException { this.salt = PasswordUtil.generateRandomSalt(SALT_SIZE); this.hash = encode(getNormalizedPasswordBytes(spec.getEncodedPassword()), this.salt); }
BCryptPasswordImpl(final ClearPasswordSpec clearPasswordSpec) { this.salt = PasswordUtil.generateRandomSalt(BCRYPT_SALT_SIZE); this.iterationCount = DEFAULT_ITERATION_COUNT; this.hash = bcrypt(this.iterationCount, this.salt, getNormalizedPasswordBytes(clearPasswordSpec.getEncodedPassword())); }