File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes how to store message digest for string in mysql database and retrieve it Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "how to store message digest for string in mysql database and retrieve it " Watch "how to store message digest for string in mysql database and retrieve it " New topic
Author

how to store message digest for string in mysql database and retrieve it

prasuna yegurla
Greenhorn

Joined: Aug 12, 2009
Posts: 3
[size=12]Hi every one i tried to create message digest created for string and store it into database like this
public static String encrypt(String str) {
StringBuffer encryptedResult = new StringBuffer();
String strWithSalt = salt str;

try {
MessageDigest md = MessageDigest.getInstance(encrptionAlgorithm);
md.update(strWithSalt.getBytes());
byte[] digest = md.digest();

for (byte b : digest) {
int number = b;
// Convert negative numbers
number = (number < 0) ? (number 256) : number;
encryptedResult.append(Integer.toHexString(number));
}

} catch (NoSuchAlgorithmException ex) {
System.out.println(ex.toString());
}

return encryptedResult.toString();
}

please suggest some solution abut which datatype i have to use to store and retrieve this hexadecimal value...
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30076
    
149

Prasuna,
Welcome to JavaRanch!

It would be varchar or clob depending on how big the digest is. I forgot how many characters a message digest is. (I could look it up, but I'm sure you know.) Varchar is typically used up to 255 characters. CLOB is more.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to store message digest for string in mysql database and retrieve it
 
Similar Threads
encrypt password on login form?
How to insert password in an encrypted form into a table
Saving, getting byte[ ]
Authentication/Authorization
Encryption in XML