• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Joe Ess
  • salvin francis
  • fred rosenberger

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

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);
byte[] digest = md.digest();

for (byte b : digest) {
int number = b;
// Convert negative numbers
number = (number < 0) ? (number 256) : number;

} catch (NoSuchAlgorithmException ex) {

return encryptedResult.toString();

please suggest some solution abut which datatype i have to use to store and retrieve this hexadecimal value...
author & internet detective
Posts: 39789
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 will give me the powers of the gods. Not bad for a tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!