• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic