public static String passwordEncode ( String decoded_string , String crypto_algorithm ) { /* * check input: * * -- decoded_string: any string, any length, cannot be null, * may start with valid (supported) crypto algorithm tag * * -- crypto_algorithm: any string, any length, cannot be null, * must be valid (supported) crypto algorithm */ if ( decoded_string == null ) { // don't accept null password return null ; } String current_crypto_algorithm = getCryptoAlgorithm ( decoded_string ) ; if ( current_crypto_algorithm != null && current_crypto_algorithm . equals ( crypto_algorithm ) ) { // Return the decoded_string if it is tagged with a valid crypto algorithm. if ( isValidCryptoAlgorithm ( current_crypto_algorithm ) ) return decoded_string . trim ( ) ; return null ; } else if ( current_crypto_algorithm != null ) { decoded_string = passwordDecode ( decoded_string ) ; } // valid input ... encode password return encode_password ( decoded_string . trim ( ) , crypto_algorithm . trim ( ) , null ) ; // TODO check this }
Encode the provided password with the algorithm . If another algorithm is already applied it will be removed and replaced with the new algorithm .