JAVA MD5 und base64

pooner

Grünschnabel
Hallo,

ich suche verzweifelt Hilfe.

Mein Problem ist folgendes:

Ich habe ien Programm welches Benutzer und Passwörter in einer HSQL-DB ablegt. ich bin nun gezwungen ein anderes Programm gegen diese DB zu authentifizieren. Also lese ich mir die daten aus der db aus. Die Passwörter sind angeblich laut hersteller md5 und dann base64 verschlüsselt. Lese ich die Passwörter jedoch aus und versuche diese mit base64 zu netschlüsseln kommt immer nichts vernünftiges bei raus. Kann es sein das Bei näherem Java aus dem MD5 gar keinen String machen, sondern die Byte-Darstellung mit base64 kodiert ? Wenn ja wie kann ich das decodieren ? Als Beispiels ist der string root verschlüsselt und das Ergebnis lautet Z++/ve+/ve+/vWFoUCTvv73vv73vv71V77+977+9e++/vQ==

Auszüge aus dem Programm Source -Code:
Code:
public class DBFunctions {

    /**
     * Tests whether a string matches a supplied regular expression and returns
     * the text if it does.
     * 
     * @param text text to match
     * @param regex regular expression
     * @return text
     */
    public static String matches(String text, String regex) {
        Pattern pattern = ReplacementEngine.getPatternPool().getPattern(regex, false, false);
        try {
            Matcher matcher = pattern.matcher(text);
            return matcher.find() ? text : "";
        } finally {
            ReplacementEngine.getPatternPool().releasePattern(pattern);
        }
    }

    /*
     * This is required to make fresh installs work correctly. As of 0.1.4,
     * passwords became BASE64 encoded and now use the ENCPASSWORD function.
     */
    public static String password(String text) throws UnsupportedEncodingException, NoSuchAlgorithmException {
        return digest(text);
    }

    /**
     * Encode a password one-way by first by producing an MD5 hash of the password
     * then encoding that in BASE64.
     * 
     * @param password password to encode
     * @return encoded password
     * @throws UnsupportedEncodingException
     * @throws NoSuchAlgorithmException
     */
    public static String encPassword(String password) throws UnsupportedEncodingException, NoSuchAlgorithmException {
        String encoded = encode(digest(password));
        return encoded;
    }

    /**
     * Encode a string as BASE64.
     * 
     * @param string string to encode
     * @return encoded string
     */
    public static String encode(String string) {
        return new String(Base64.encode(string.getBytes()));
    }

    /**
     * Decode a string from BASE64 to its original form.
     * 
     * @param string string to decode
     * @return decoded string
     */
    public static String decode(String string) {
        return new String(Base64.decode(string.getBytes()));
    }

    /**
     * Create an MD5 hash of the provided string
     * 
     * @param string string to hash
     * @return hashed string
     */
    public static String digest(String string) throws NoSuchAlgorithmException, UnsupportedEncodingException {
        byte[] b = string.getBytes();
        MessageDigest md = MessageDigest.getInstance("MD5");
        md.update(b);
        byte[] digest = md.digest();
        return new String(digest);
    }

}

Ich hoffe jemand kann mir helfen
 

Neue Beiträge

Zurück