private static PasswordDetails getCryptCredentials( byte[] credentials, int algoLength, LdapSecurityConstants algorithm ) { // The password is associated with a salt. Decompose it // in two parts, no decoding required. // The salt length is dynamic, between the 2nd and 3rd '$'. // The algorithm, salt, and password will be stored into the PasswordDetails structure. // skip {crypt}$x$ int pos = algoLength; while ( pos < credentials.length ) { if ( credentials[pos] == '$' ) { break; } pos++; } byte[] salt = Arrays.copyOfRange( credentials, algoLength, pos ); byte[] password = Arrays.copyOfRange( credentials, pos + 1, credentials.length ); return new PasswordDetails( algorithm, salt, password ); }
byte[] userPassword = PasswordUtil.encryptPassword( receivedCredentials, passwordDetails.getAlgorithm(), passwordDetails.getSalt() ); return compareBytes( userPassword, passwordDetails.getPassword() );
byte[] userPassword = PasswordUtil.encryptPassword( receivedCredentials, passwordDetails.getAlgorithm(), passwordDetails.getSalt() ); return compareBytes( userPassword, passwordDetails.getPassword() );
byte[] userPassword = PasswordUtil.encryptPassword( receivedCredentials, passwordDetails.getAlgorithm(), passwordDetails.getSalt() ); return compareBytes( userPassword, passwordDetails.getPassword() );
private static PasswordDetails getCryptCredentials( byte[] credentials, int algoLength, LdapSecurityConstants algorithm ) { // The password is associated with a salt. Decompose it // in two parts, no decoding required. // The salt length is dynamic, between the 2nd and 3rd '$'. // The algorithm, salt, and password will be stored into the PasswordDetails structure. // skip {crypt}$x$ int pos = algoLength; while ( pos < credentials.length ) { if ( credentials[pos] == '$' ) { break; } pos++; } byte[] salt = Arrays.copyOfRange( credentials, algoLength, pos ); byte[] password = Arrays.copyOfRange( credentials, pos + 1, credentials.length ); return new PasswordDetails( algorithm, salt, password ); }
private static PasswordDetails getCryptCredentials( byte[] credentials, int algoLength, LdapSecurityConstants algorithm ) { // The password is associated with a salt. Decompose it // in two parts, no decoding required. // The salt length is dynamic, between the 2nd and 3rd '$'. // The algorithm, salt, and password will be stored into the PasswordDetails structure. // skip {crypt}$x$ int pos = algoLength; while ( pos < credentials.length ) { if ( credentials[pos] == '$' ) { break; } pos++; } byte[] salt = Arrays.copyOfRange( credentials, algoLength, pos ); byte[] password = Arrays.copyOfRange( credentials, pos + 1, credentials.length ); return new PasswordDetails( algorithm, salt, password ); }
/** * Gets the credentials from a PKCS5S2 hash. * The salt for PKCS5S2 hash is prepended to the password * * @param credentials The password * @param algoLength The length of the algorithm part * @param algorithm The algorithm in use * @return The split credentials, containing the algorithm, the salt and the password */ private static PasswordDetails getPbkdf2Credentials( byte[] credentials, int algoLength, LdapSecurityConstants algorithm ) { // The password is associated with a salt. Decompose it // in two parts, after having decoded the password. // The salt is at the *beginning* of the credentials, and is 16 bytes long // The algorithm, salt, and password will be stored into the PasswordDetails structure. byte[] passwordAndSalt = Base64 .decode( Strings.utf8ToString( credentials, algoLength, credentials.length - algoLength ).toCharArray() ); int saltLength = passwordAndSalt.length - PKCS5S2_LENGTH; byte[] salt = new byte[saltLength]; byte[] password = new byte[PKCS5S2_LENGTH]; split( passwordAndSalt, 0, salt, password ); return new PasswordDetails( algorithm, salt, password ); }
/** * Compute the credentials * * @param credentials the credentials * @param algoLength The algorithm length * @param hashLen The hash length * @param algorithm the algorithm to use * @return The split password string, containing the credentials, the salt and the password */ private static PasswordDetails getCredentials( byte[] credentials, int algoLength, int hashLen, LdapSecurityConstants algorithm ) { // The password is associated with a salt. Decompose it // in two parts, after having decoded the password. // The salt is at the end of the credentials. // The algorithm, salt, and password will be stored into the PasswordDetails structure. byte[] passwordAndSalt = Base64 .decode( Strings.utf8ToString( credentials, algoLength, credentials.length - algoLength ).toCharArray() ); int saltLength = passwordAndSalt.length - hashLen; byte[] salt = saltLength == 0 ? null : new byte[saltLength]; byte[] password = new byte[hashLen]; split( passwordAndSalt, 0, password, salt ); return new PasswordDetails( algorithm, salt, password ); }
/** * Gets the credentials from a PKCS5S2 hash. * The salt for PKCS5S2 hash is prepended to the password * * @param credentials The password * @param algoLength The length of the algorithm part * @param algorithm The algorithm in use * @return The split credentials, containing the algorithm, the salt and the password */ private static PasswordDetails getPbkdf2Credentials( byte[] credentials, int algoLength, LdapSecurityConstants algorithm ) { // The password is associated with a salt. Decompose it // in two parts, after having decoded the password. // The salt is at the *beginning* of the credentials, and is 16 bytes long // The algorithm, salt, and password will be stored into the PasswordDetails structure. byte[] passwordAndSalt = Base64 .decode( Strings.utf8ToString( credentials, algoLength, credentials.length - algoLength ).toCharArray() ); int saltLength = passwordAndSalt.length - PKCS5S2_LENGTH; byte[] salt = new byte[saltLength]; byte[] password = new byte[PKCS5S2_LENGTH]; split( passwordAndSalt, 0, salt, password ); return new PasswordDetails( algorithm, salt, password ); }
/** * Gets the credentials from a PKCS5S2 hash. * The salt for PKCS5S2 hash is prepended to the password * * @param credentials The password * @param algoLength The length of the algorithm part * @param algorithm The algorithm in use * @return The split credentials, containing the algorithm, the salt and the password */ private static PasswordDetails getPbkdf2Credentials( byte[] credentials, int algoLength, LdapSecurityConstants algorithm ) { // The password is associated with a salt. Decompose it // in two parts, after having decoded the password. // The salt is at the *beginning* of the credentials, and is 16 bytes long // The algorithm, salt, and password will be stored into the PasswordDetails structure. byte[] passwordAndSalt = Base64 .decode( Strings.utf8ToString( credentials, algoLength, credentials.length - algoLength ).toCharArray() ); int saltLength = passwordAndSalt.length - PKCS5S2_LENGTH; byte[] salt = new byte[saltLength]; byte[] password = new byte[PKCS5S2_LENGTH]; split( passwordAndSalt, 0, salt, password ); return new PasswordDetails( algorithm, salt, password ); }
/** * Compute the credentials * * @param credentials the credentials * @param algoLength The algorithm length * @param hashLen The hash length * @param algorithm the algorithm to use * @return The split password string, containing the credentials, the salt and the password */ private static PasswordDetails getCredentials( byte[] credentials, int algoLength, int hashLen, LdapSecurityConstants algorithm ) { // The password is associated with a salt. Decompose it // in two parts, after having decoded the password. // The salt is at the end of the credentials. // The algorithm, salt, and password will be stored into the PasswordDetails structure. byte[] passwordAndSalt = Base64 .decode( Strings.utf8ToString( credentials, algoLength, credentials.length - algoLength ).toCharArray() ); int saltLength = passwordAndSalt.length - hashLen; byte[] salt = saltLength == 0 ? null : new byte[saltLength]; byte[] password = new byte[hashLen]; split( passwordAndSalt, 0, password, salt ); return new PasswordDetails( algorithm, salt, password ); }
/** * Compute the credentials * * @param credentials the credentials * @param algoLength The algorithm length * @param hashLen The hash length * @param algorithm the algorithm to use * @return The split password string, containing the credentials, the salt and the password */ private static PasswordDetails getCredentials( byte[] credentials, int algoLength, int hashLen, LdapSecurityConstants algorithm ) { // The password is associated with a salt. Decompose it // in two parts, after having decoded the password. // The salt is at the end of the credentials. // The algorithm, salt, and password will be stored into the PasswordDetails structure. byte[] passwordAndSalt = Base64 .decode( Strings.utf8ToString( credentials, algoLength, credentials.length - algoLength ).toCharArray() ); int saltLength = passwordAndSalt.length - hashLen; byte[] salt = saltLength == 0 ? null : new byte[saltLength]; byte[] password = new byte[hashLen]; split( passwordAndSalt, 0, password, salt ); return new PasswordDetails( algorithm, salt, password ); }
return new PasswordDetails( null, null, credentials ); password = new byte[credentials.length - salt.length - algoLength]; split( credentials, algoLength, salt, password ); return new PasswordDetails( algorithm, salt, password ); password = Arrays.copyOfRange( credentials, credentials.length - 31, credentials.length ); return new PasswordDetails( algorithm, salt, password );
return new PasswordDetails( null, null, credentials ); password = new byte[credentials.length - salt.length - algoLength]; split( credentials, algoLength, salt, password ); return new PasswordDetails( algorithm, salt, password ); password = Arrays.copyOfRange( credentials, credentials.length - 31, credentials.length ); return new PasswordDetails( algorithm, salt, password );
return new PasswordDetails( null, null, credentials ); password = new byte[credentials.length - salt.length - algoLength]; split( credentials, algoLength, salt, password ); return new PasswordDetails( algorithm, salt, password ); password = Arrays.copyOfRange( credentials, credentials.length - 31, credentials.length ); return new PasswordDetails( algorithm, salt, password );