• 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
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

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: 40211
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.
    Bookmark Topic Watch Topic
  • New Topic