473,466 Members | 1,377 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 getEncodedPassword 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 getEncodedPassword(String clearTextPassword)
throws
NoSuchAlgorithmException {
MessageDigest md = MessageDigest.getInstance("MD5");

md.update(clearTextPassword.getBytes());

return new String(md.digest());
}

public static boolean testPassword(String clearTextTestPassword,
String encodedActualPassword) throws
NoSuchAlgorithmException {
String encodedTestPassword = MD5Password.getEncodedPassword(
clearTextTestPassword);

return (encodedTestPassword.equals(encodedActualPassword) );
}
}
--------------------------------------------------
Jul 17 '05 #1
1 12486
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.getInstance("SHA");
md.update(clearTextPassword.getBytes());
return new sun.misc.BASE64Encoder().encode(md.digest());

Adam

Ronald Evers wrote:
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 getEncodedPassword 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 getEncodedPassword(String clearTextPassword)
throws
NoSuchAlgorithmException {
MessageDigest md = MessageDigest.getInstance("MD5");

md.update(clearTextPassword.getBytes());

return new String(md.digest());
}

public static boolean testPassword(String clearTextTestPassword,
String encodedActualPassword) throws
NoSuchAlgorithmException {
String encodedTestPassword = MD5Password.getEncodedPassword(
clearTextTestPassword);

return (encodedTestPassword.equals(encodedActualPassword) );
}
}
--------------------------------------------------

----== 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 =---
Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: joltman | last post by:
We're working on an intranet site where we will require user's to only be able to access their own page in some instances. Rather than introducing another password to the mix, we were thinking...
4
by: Tim Daneliuk | last post by:
OK, I've Googled for this and cannot seem to quite find what I need. So, I turn to the Gentle Geniuses here for help. Here is what I need to do from within a script: Given a username and a...
6
by: Ian Davies | last post by:
Hello I would like to query the user table of the mysql database from my VB application to check that a user's password entered in a text field on a form corresponds to that users password in the...
5
by: Guadala Harry | last post by:
What are my options for *securely* storing/retrieving the ID and password used by an ASP.NET application for accessing a SQL Server (using SQL Server authentication)? Please note that this ID and...
12
by: Cecil | last post by:
Does this make sense for a logon table: CREATE TABLE Logon ( ID INT NOT NULL IDENTITY PRIMARY KEY, name VARCHAR(15) NOT NULL, password VARCHAR(15) NOT NULL ) GO CREATE UNIQUE INDEX...
5
by: Skeleton Man | last post by:
Hi, I came across the basic algorithmfor decrypting WS_FTP Pro 6 passwords as follows, and I'm trying to reverse it to make an encryption function: function ws_dec() { var str =...
4
by: Gilles Ganault | last post by:
Hello I'd like to encrypt a customer's organization name to use this as their password to launch our application, and decrypt it within our VB5 application. We will then use this information...
9
by: Betikci Boris | last post by:
I get bored last night and wrote a script that uses xor for encrypt- decrypt, however it woks fine under linux 2.6.25, text and documents are ok, but fails on compressed files *.jpg, *.pdf , etc ....
0
by: Jon.Hakkinen | last post by:
Hi all, I'm on DB2 9.5 fp 0 on Windows. I have a simple SQL stored procedure which uses the Encrypt() function to insert data in a table. I do not set the encryption password inside the...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.