wood burning stoves 2.0*
The moose likes Security and the fly likes encryption and decryption required Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » Security
Bookmark "encryption and decryption required " Watch "encryption and decryption required " New topic
Author

encryption and decryption required

pendse anagha
Ranch Hand

Joined: Mar 09, 2005
Posts: 44
Hello ,
I need help regarding encryption and decryption .

I need to do the following :
1 >
User will ente some text

2 >
Encrypt this text and store in database

3 >
while retrieving data - decrypt and display to user


My environment is JDK1.3 and I am using Dynamo

Could someone guide me with some examples as to how I could encrypt simple string data and store in database and conversely decrypt and display data .

My limited knowledge tells me that MD5 can be only used for encryption - not decryption

I also tried some examples from googling related to - "DES"
However when I try to run the examples - I get this error -
"java.lang.ExceptionInInitializerError: java.lang.SecurityException: Cannot set up certs for trusted CAs: java.lang.SecurityException: Cannot locate policy and/or framework files for signer restraint check!
at javax.crypto.SunJCE_b.<clinit>(DashoA6275)
at javax.crypto.KeyGenerator.getInstance(DashoA6275)"

I am sure I am missing something very very basic .

Any help would be greatly appreciated.

Thanks in advance,
-anagha
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41032
    
  43
You're right, MD5 is a hash, which is kind of a one-way encryption. There's no easy way to get the original text back out of it.

Here's an introductory article on how to encrypt/decrypt something using JCE.


Ping & DNS - my free Android networking tools app
pendse anagha
Ranch Hand

Joined: Mar 09, 2005
Posts: 44
Thanks Ulf for your suggestion .

Please bear with me since some of the questions may sound vague and inappropriate.
My lack of basics related to JCE and the need to do an implementation of JCE
is driving me nuts .

OK : here goes with a few more of my doubts :

I am using JDK1.3
I tried using the "DES" algorithm

I could get it running by adding "jce1_2_2.jar" & "sunjce_provider.jar" in my classpath
Here is a link which provided me with information about setting up JCE for 1.2.x flavour of JDK :
Security

To get it running -
1 >option 1 - add the following line :


2 >The other option is - add this line in my Java code :


Here are my observations :
If I dont do either of the above configuration ( for SunJCE Provider ) then I get a run time exception java.security.NoSuchAlgorithmException: Algorithm DES not available

So my questions / doubts / inferences are :

1 >DES is not supported by the other providers : sun.security.provider.Sunand com.sun.rsajca.Provider

2 >So what kind of algorithms are supported by either sun.security.provider.SunOR com.sun.rsajca.Provider ?

3 >I am and will be using JDK1.3
So are there any examples of algorithms that are supported by the providers mentioned above ?


4 >If I wanted to use SunJCE provider - is it better to add the provider through code or in the java.security file ?
What are the advantages or disadvantages in the above method ?


4 >Could someone point me to some examples which use the above providers ?

5 >I tried looking into JDK1.3 - I am not able to locate the classes with the correct Package structure ?
So I am not sure if these are classes that need to be implemented by some third party ?

Totally confused.

Any help is greatly appreciated .

Regards ,
-anagha
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41032
    
  43
JCE was not part of JDK 1.3, so you need to add it explicitly, but you seem to have figured that out. A good starting point for learning about JCE is this page. It is part of the JDK 1.4 docs, but I don't think anything substantial changed from the add-on versions for JDK 1.2/1.3. Appendix A in particular talks about which ciphers are available, and there are code examples as well.
[ November 24, 2005: Message edited by: Ulf Dittmer ]
Greg Burdett
Greenhorn

Joined: Jan 23, 2003
Posts: 4
I had the same issue with Java 1.5 (on Windows 2008 / 64), "Cannot locate policy and/or framework files ". I got the policy strength files from Oracle, then unzipped them into the C:\Java64\jdk1.5.0_22\jre\lib\security directory. However, the ZIP file had a path of "jce" for the policy JAR files, and so unzipping them placed them at: C:\Java64\jdk1.5.0_22\jre\lib\security\jce. Even though I put that entry in the Path environment variable, they were still not found. I copied them up one level, to C:\Java64\jdk1.5.0_22\jre\lib\security, and then my Java program worked and performed 256 bit encryption / decryption, so it obviously found the files.

Greg Burdett
greg stark
Ranch Hand

Joined: Aug 10, 2006
Posts: 220
Greg Burdett wrote:I had the same issue with Java 1.5 (on Windows 2008 / 64), "Cannot locate policy and/or framework files ". I got the policy strength files from Oracle, then unzipped them into the C:\Java64\jdk1.5.0_22\jre\lib\security directory. However, the ZIP file had a path of "jce" for the policy JAR files, and so unzipping them placed them at: C:\Java64\jdk1.5.0_22\jre\lib\security\jce. Even though I put that entry in the Path environment variable, they were still not found. I copied them up one level, to C:\Java64\jdk1.5.0_22\jre\lib\security, and then my Java program worked and performed 256 bit encryption / decryption, so it obviously found the files.

Greg Burdett


You're responding to an almost 6 year old question? Really?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: encryption and decryption required
 
Similar Threads
BadPaddingException
Need help in password Encryption and Decryption
Password encryption and decryption in java
Storing a password to encrypt/decrypt sensitive data.
Encrypt in Java / Decrypt in C++