Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • 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: 34837
369
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic