• 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

Is It Possible to Reverse String.hashCode()?

 
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I'm hoping I can get at least one authority to weigh in on this one. I'm writing an app that sends HTML email, and I attach some small images (a logo and such) to the email. Each of these attachments has to be uniquely named so I can link the image from the body of the email, and I was just using the URL where that image was located (removing illegal characters like slashes and colons, of course).
The problem: it is a serious security risk to identify the machine hosting these images, and there's an expectation the email will be public. So now I'm thinking, I can just name the attachments with the hashCode() of the URL.
The question: given a hash code, is it possible to reverse the hashing algorithm used by String.hashCode() to get the original String, or is hashing a one-way algorithm in which information is lost (and therefore safe for this usage)?
Thanks!
sev
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's a one-way, potentially lossy algorithm; more than one String may have the same hashCode. That's not to say that it's necessarily cryptographically strong; I might be more comfortable using an MD5 checksum, for example.
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by sever oon:
The problem: it is a serious security risk to identify the machine hosting these images

I must mention the fact that this is exactly what the security circles call Security Through Obscurity, and it's far from being secure.
Assuming that no-one will come knocking on your public IP address just because you haven't marketed your web site anywhere is nonsense. It's only a matter of time.
 
sever oon
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the quick (!) and useful responses.
To Lasse: I think you may have misunderstood the situation. The machine I'm referring to is meant to be deployed behind a corporate firewall and serve content within that intranet. It can provide various content in the form of emails, though, and the emails can travel anywhere.
So in and of itself, it's not risky to expose the name/IP of the machine outside the corporate network...assuming the company's firewall thwarts any attackers. As we're selling to a wide range of customers, though, we try not to make any assumptions...some of our customers no doubt rely on the principle you aptly broached, Security through Obscurity. It's not my company's place to tell them how to run their network, and if that's the choice, I simply want to make sure I'm not aiding and abetting the enemy.
So, I definitely don't want to drag another library into the mix like MD5 just to generate cryptographically strong unique names. I'll just use a two-step route instead...when I actually do the attachments I can easily iterate and simply name them "1", "2", etc. (Don't know why I didn't think of that before.)
Thanks again!
sev
 
Today's lesson is that you can't wear a jetpack AND a cape. I should have read this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic