MD5 Password encryption across linux and windows

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ronald Evers

    #1

    MD5 Password encryption across linux and windows

    Hey all,

    I want to store passwords in a postgresql database. Currently I use the
    MD5Password class below and I've been developing on windows. I ran into
    problems when running my application on linux.

    Linux and Windows, with same JDK's (1.5.0), create different encrypted
    password strings. So when testing a password created on one platform on
    the other, it will fail :(

    Is there a way to make the getEncodedPassw ord method behave the same
    regardless of the application being run on windows or linux? And if not,
    how could I facilitate platform-independent, easy, not necesarily strong
    password encryption?


    Thanks in advance for any suggestions,

    Ronald

    --------------------------------------------------
    import java.security.* ;

    public class MD5Password {
    public static String getEncodedPassw ord(String clearTextPasswo rd)
    throws
    NoSuchAlgorithm Exception {
    MessageDigest md = MessageDigest.g etInstance("MD5 ");

    md.update(clear TextPassword.ge tBytes());

    return new String(md.diges t());
    }

    public static boolean testPassword(St ring clearTextTestPa ssword,
    String encodedActualPa ssword) throws
    NoSuchAlgorithm Exception {
    String encodedTestPass word = MD5Password.get EncodedPassword (
    clearTextTestPa ssword);

    return (encodedTestPas sword.equals(en codedActualPass word));
    }
    }
    --------------------------------------------------
  • Adam Ramadan

    #2
    Re: MD5 Password encryption across linux and windows

    Hi,

    It's possible that the default character encoding is different on your
    two platforms, so creating a String using the bytes output by the
    MessageDigest could result in different Strings on different platforms.

    To avoid this, and the possibility that whitespace at the ends of the
    String could be trimmed when storing in a varchar column, I Base64
    encode the bytes:

    MessageDigest md = MessageDigest.g etInstance("SHA ");
    md.update(clear TextPassword.ge tBytes());
    return new sun.misc.BASE64 Encoder().encod e(md.digest());

    Adam

    Ronald Evers wrote:
    [color=blue]
    > Hey all,
    >
    > I want to store passwords in a postgresql database. Currently I use the
    > MD5Password class below and I've been developing on windows. I ran into
    > problems when running my application on linux.
    >
    > Linux and Windows, with same JDK's (1.5.0), create different encrypted
    > password strings. So when testing a password created on one platform on
    > the other, it will fail :(
    >
    > Is there a way to make the getEncodedPassw ord method behave the same
    > regardless of the application being run on windows or linux? And if not,
    > how could I facilitate platform-independent, easy, not necesarily strong
    > password encryption?
    >
    >
    > Thanks in advance for any suggestions,
    >
    > Ronald
    >
    > --------------------------------------------------
    > import java.security.* ;
    >
    > public class MD5Password {
    > public static String getEncodedPassw ord(String clearTextPasswo rd)
    > throws
    > NoSuchAlgorithm Exception {
    > MessageDigest md = MessageDigest.g etInstance("MD5 ");
    >
    > md.update(clear TextPassword.ge tBytes());
    >
    > return new String(md.diges t());
    > }
    >
    > public static boolean testPassword(St ring clearTextTestPa ssword,
    > String encodedActualPa ssword) throws
    > NoSuchAlgorithm Exception {
    > String encodedTestPass word = MD5Password.get EncodedPassword (
    > clearTextTestPa ssword);
    >
    > return (encodedTestPas sword.equals(en codedActualPass word));
    > }
    > }
    > --------------------------------------------------[/color]


    ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
    http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
    ---= East/West-Coast Server Farms - Total Privacy via Encryption =---

    Comment

    Working...