943,794 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Marked Solved
  • Views: 49001
  • Java RSS
You are currently viewing page 1 of this multi-page discussion thread
May 24th, 2007
0

Java Encryption and Decryption

Expand Post »
Hai,
I am new java developer. Now i am doing one struts application.
In my application, at the User registration time, i need to Encrypt the password field and then i like to store into the database.

After that the same user will be logging, at the moment the database password will decrypt and it will be compare to the User entering password.

If both password's are equal, then only the User will allow the logging.

can anybody know or have any sample code for Encrypt and Decrypt.

If yes, kindly post me my mail id is <email snipped>

I am expecting anyone's reply.

Thanks

Tamilvanan
Last edited by ~s.o.s~; May 26th, 2007 at 2:29 pm. Reason: Keep it on site.
Similar Threads
Reputation Points: 30
Solved Threads: 0
Newbie Poster
ttamilvanan81 is offline Offline
24 posts
since Apr 2007
May 24th, 2007
0

Re: Java Encryption and Decryption

Maybe you should read forum rules regarding homeworks http://www.daniweb.com/techtalkforum...cement9-2.html
and daniweb policies http://www.daniweb.com/techtalkforum...niweb_policies
Moderator
Featured Poster
Reputation Points: 2786
Solved Threads: 873
Code tags enforcer
peter_budo is offline Offline
6,656 posts
since Dec 2004
May 25th, 2007
0

Re: Java Encryption and Decryption

Click to Expand / Collapse  Quote originally posted by peter_budo ...
Maybe you should read forum rules regarding homeworks http://www.daniweb.com/techtalkforum...cement9-2.html
and daniweb policies http://www.daniweb.com/techtalkforum...niweb_policies

Hai, Thanks for your suggestion.
This is the good way of improving programming knowledge.
I appreciate this rules.
I have already don e for Encryption, but i don't know how to decrypt the encrypted string.

I am using the following code for encryption.

Java Syntax (Toggle Plain Text)
  1. package com.pmp.actions;
  2. import java.security.MessageDigest;
  3. import java.math.BigInteger.*;
  4. public class Encryption {
  5.  
  6. public static String Password(String data) {
  7. StringBuffer sb = new StringBuffer();
  8. try {
  9. MessageDigest messageDigest = MessageDigest.getInstance("SHA-512");
  10. messageDigest.update(data.getBytes("UTF-8"));
  11. byte[] digestBytes = messageDigest.digest();
  12.  
  13. String hex = null;
  14. for (int i = 0; i < digestBytes.length; i++) {
  15. hex = Integer.toHexString(0xFF & digestBytes[i]);
  16. if (hex.length() < 2)
  17. sb.append("0");
  18. sb.append(hex);
  19. }
  20. String psw = sb.toString();
  21. }
  22. catch (Exception ex) {
  23. System.out.println(ex.getMessage());
  24. }
  25. return new String(sb);
  26. }
  27. }


How to decrypt this. Please help me. I am also trying.

Thanks

Tamilvanan
Last edited by peter_budo; Jan 14th, 2010 at 3:35 am. Reason: Adding code tags
Reputation Points: 30
Solved Threads: 0
Newbie Poster
ttamilvanan81 is offline Offline
24 posts
since Apr 2007
May 25th, 2007
0

Re: Java Encryption and Decryption

In my application, at the User registration time, i need to Encrypt the password field and then i like to store into the database.

After that the same user will be logging, at the moment the database password will decrypt and it will be compare to the User entering password.
Just highlighed the keywords you used it. I'm not into encryption/decryption but as Java reference state
Message digests are secure one-way hash functions that take arbitrary-sized data and output a fixed-length hash value.. So you can only encrypt, no reverse process. However there is no need for decryption as MessageDigest class provide public static boolean isEqual(byte[] digesta, byte[] digestb). Compares two digests for equality. Does a simple byte compare.
In login process take user entered password, encrypt it and compare with data from database. Problem solved...
Last edited by peter_budo; May 25th, 2007 at 6:54 am.
Moderator
Featured Poster
Reputation Points: 2786
Solved Threads: 873
Code tags enforcer
peter_budo is offline Offline
6,656 posts
since Dec 2004
Mar 12th, 2008
0

Re: Java Encryption and Decryption

any one plz give source code in java for
encrypted and decrypted password
Reputation Points: 10
Solved Threads: 0
Newbie Poster
callsreenu is offline Offline
1 posts
since Mar 2008
Mar 12th, 2008
0

Re: Java Encryption and Decryption

Click to Expand / Collapse  Quote originally posted by callsreenu ...
any one plz give source code in java for
encrypted and decrypted password
first of all, if you have a question, create a new thread instead of reviving a year old one.
secondly, the answer is no. maybe we can, but we won't.
you wouldn't be learning anything. just read the answers earlier given in this thread, or go ask Google, you might be surprised what difference a bit of effort can make, but do not expect us to:
a. do your homework
b. do your job
without any effort from your side.
Reputation Points: 935
Solved Threads: 356
Nearly a Posting Maven
stultuske is offline Offline
2,493 posts
since Jan 2007
Jun 22nd, 2009
0

Re: Java Encryption and Decryption

Hi,
I am saving the password in the database using SHA-1 encyption. On forgetting the password i have to email the user his old password. But i am not able to decrypt the password saved in the database. Can anybody help me in creating a decryption code in java for the same.
Thanks
Rahul
Reputation Points: 10
Solved Threads: 0
Newbie Poster
rahulkashyap82 is offline Offline
4 posts
since Jun 2009
Jul 22nd, 2009
0

Re: Java Encryption and Decryption

SHA-1 can not be decrypted since it is a one way hash function! I believe it would be a better solution to generate a new password for the user and send it to him
Reputation Points: 10
Solved Threads: 0
Newbie Poster
GuiBuilder is offline Offline
1 posts
since Jul 2009
Jan 13th, 2010
0
Re: Java Encryption and Decryption
please give me the executable complete code for encryption and also decryption of a file.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
karthidino is offline Offline
1 posts
since Jan 2010
Jan 14th, 2010
0
Re: Java Encryption and Decryption
Click to Expand / Collapse  Quote originally posted by karthidino ...
please give me the executable complete code for encryption and also decryption of a file.
nope ...
Reputation Points: 935
Solved Threads: 356
Nearly a Posting Maven
stultuske is offline Offline
2,493 posts
since Jan 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
This thread is currently closed and is not accepting any new replies.
Previous Thread in Java Forum Timeline: Using frame.pack() for resizing JFrame
Next Thread in Java Forum Timeline: Help Needed: ( get TextField source and Write in a txt file by the button click





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC