Java Encryption and Decryption

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Apr 2007
Posts: 24
Reputation: ttamilvanan81 is an unknown quantity at this point 
Solved Threads: 0
ttamilvanan81 ttamilvanan81 is offline Offline
Newbie Poster

Java Encryption and Decryption

 
0
  #1
May 24th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,210
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 489
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: Java Encryption and Decryption

 
0
  #2
May 24th, 2007
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
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 24
Reputation: ttamilvanan81 is an unknown quantity at this point 
Solved Threads: 0
ttamilvanan81 ttamilvanan81 is offline Offline
Newbie Poster

Re: Java Encryption and Decryption

 
0
  #3
May 25th, 2007
Originally Posted by peter_budo View Post
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.

package com.pmp.actions;
import java.security.MessageDigest;
import java.math.BigInteger.*;
public class Encryption {

public static String Password(String data) {
StringBuffer sb = new StringBuffer();
try {
MessageDigest messageDigest = MessageDigest.getInstance("SHA-512");
messageDigest.update(data.getBytes("UTF-8"));
byte[] digestBytes = messageDigest.digest();

String hex = null;
for (int i = 0; i < digestBytes.length; i++) {
hex = Integer.toHexString(0xFF & digestBytes[i]);
if (hex.length() < 2)
sb.append("0");
sb.append(hex);
}
String psw = sb.toString();
}
catch (Exception ex) {
System.out.println(ex.getMessage());
}
return new String(sb);
}
}


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

Thanks

Tamilvanan
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,210
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 489
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: Java Encryption and Decryption

 
0
  #4
May 25th, 2007
Originally Posted by ttamilvanan81 View Post
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.
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 1
Reputation: callsreenu is an unknown quantity at this point 
Solved Threads: 0
callsreenu callsreenu is offline Offline
Newbie Poster

Re: Java Encryption and Decryption

 
0
  #5
Mar 12th, 2008
any one plz give source code in java for
encrypted and decrypted password
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 706
Reputation: stultuske is a jewel in the rough stultuske is a jewel in the rough stultuske is a jewel in the rough 
Solved Threads: 84
stultuske's Avatar
stultuske stultuske is offline Offline
Master Poster

Re: Java Encryption and Decryption

 
0
  #6
Mar 12th, 2008
Originally Posted by callsreenu View Post
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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 4
Reputation: rahulkashyap82 is an unknown quantity at this point 
Solved Threads: 0
rahulkashyap82 rahulkashyap82 is offline Offline
Newbie Poster

Re: Java Encryption and Decryption

 
0
  #7
Jun 22nd, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 1
Reputation: GuiBuilder is an unknown quantity at this point 
Solved Threads: 0
GuiBuilder GuiBuilder is offline Offline
Newbie Poster

Re: Java Encryption and Decryption

 
0
  #8
Jul 22nd, 2009
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
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC