• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
prasuna yegurla
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[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
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic