Win a copy of Functional Design and Architecture this week in the Functional programming 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Decryption fails on Mac

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I encrypt a string using some algorithm and javax.crypto API, I cannot decrypt it on Mac. I guess it has something to do with the encoding.
Any solution for this?

Thanks.

Code:
 
Sudhanshu Umalkar
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It works fine only on Windows platform, but not on others.
 
Ranch Hand
Posts: 220
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sud Umm wrote:It works fine only on Windows platform, but not on others.



You can't use SecureRandom in the way you are doing it. SecureRandom does NOT only use your seed to initialize itself, it also may seek to use other sources of entropy. This should be made clear in the Javadocs for SecureRandom; unfortunately it is not.

You should use a proper Password-based encryption (PBE) scheme.
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
About the exception handling: use BadPaddingException and then GeneralSecurityException - and convert at least the last one into a InvalidStateException. You can avoid the encoding exceptions by using Charset.forName() in later VM's. Note that any encoding is accepted by default, the exception normally only gets thrown if the encoding is not available; but Java specifies that "UTF-8" is ALWAYS available, so that's a bit of a moot point.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic