This week's giveaway is in the JDBC forum.
We're giving away four copies of Java Database Connections & Transactions (e-book only) and have Marco Behler on-line!
See this thread for details.
Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!
  • 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 ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Hiow to unencrypt a string which was encrypted to hex ?  RSS feed

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I am using a Security class to encrypt a String. My class is as follows
public class Security {
public static final String getDigest(String digest_data)
throws java.security.NoSuchAlgorithmException
{
MessageDigest digest = MessageDigest.getInstance("md5");
byte [] data_bytes = digest.digest(digest_data.getBytes());
//convert to hexstring
StringBuffer hexString = new StringBuffer();
String hex = null;
for (int i=0; i < data_bytes.length;i++) {
hex = Integer.toHexString(0xFF & data_bytes[i]);
if (hex.length() < 2){
hexString.append("0");
hexString.append(hex);
}
hexString.append(hex);
}
return hexString.toString();
}
public static final boolean match(String digest_data,String enc_data)
throws java.security.NoSuchAlgorithmException
{
return getDigest(digest_data).equals(enc_data);
}
}
I want to add a new method to unencrypt my encrypted string. I'm not really sure as to how to create this method as don't really understand how the message digest works. if you have any suggestions then that would be great.
Cheers in advance.
 
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to be able of decrypt your string, you can not use a digest(MD5), you need a symetric algorithm(blowfish, DES,...) for encryption.
If you are using MD5 and want to validate a second string you can just md5-digest it and check if the hash is the same.
But you can NOT reverse a MD5 hash(except you have the biggest computational power of the universe ), that is the purpose of a message digest.
HTH
 
Fergus Red
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, Thank you for your help on this.
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Juanjo Bazan:
But you can NOT reverse a MD5 hash (except you have the biggest computational power of the universe )

You can't even if you have the biggest computational power in the universe. A digest is lossy. There are infinitely many inputs that give the same hash.
- Peter
 
Juanjo Bazan
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Peter den Haan:
You can't even if you have the biggest computational power in the universe. A digest is lossy. There are infinitely many inputs that give the same hash.
- Peter


You're right, but what if I have the biggest computational power of infinitely many parallel universes, eeh?
 
Peter den Haan
author
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, but how would you choose between the multiversed answers you're getting back? What universe to go to? The dilemmas of a interdimensional traveller are manifold. Riemannian manifold, to be precise -- you wouldn't survive in anything else, so I can simply invoke the anthropic principle here.
- Peter
[ December 19, 2002: Message edited by: Peter den Haan ]
 
Juanjo Bazan
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My answer was more general, I dont mind i can not go to the right universe, the important issue is that the correct solution to the my MD5 reverse hash EXISTS in some universe.
Interdimensional traveller problems are out of my scope. for now...
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Juanjo,
NEVER try to argue with a guy that has a PhD in Physics, even IF he is certified .
(Unless of course you are his wife ).

Dr Peter can make my head spin .
.
 
F is for finger. Can you stick your finger in your nose? Doesn't that feel nice? Now try this tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!