DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Java (http://www.daniweb.com/forums/forum9.html)
-   -   Java Encryption and Decryption (http://www.daniweb.com/forums/thread79138.html)

ttamilvanan81 May 24th, 2007 1:00 am
Java Encryption and Decryption
 
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

peter_budo May 24th, 2007 1:02 pm
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

ttamilvanan81 May 25th, 2007 12:57 am
Re: Java Encryption and Decryption
 
Quote:

Originally Posted by peter_budo (Post 372690)
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

peter_budo May 25th, 2007 6:53 am
Re: Java Encryption and Decryption
 
Quote:

Originally Posted by ttamilvanan81 (Post 372392)
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...

callsreenu Mar 12th, 2008 3:19 am
Re: Java Encryption and Decryption
 
any one plz give source code in java for
encrypted and decrypted password

stultuske Mar 12th, 2008 7:42 am
Re: Java Encryption and Decryption
 
Quote:

Originally Posted by callsreenu (Post 558622)
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.

rahulkashyap82 Jun 22nd, 2009 3:35 am
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

GuiBuilder Jul 22nd, 2009 11:05 am
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 :)


All times are GMT -4. The time now is 2:09 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC