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

Maybe you should read forum rules regarding homeworks http://www.daniweb.com/techtalkforums/announcement9-2.html
and daniweb policies http://www.daniweb.com/techtalkforums/faq.php?faq=daniweb_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

Edited 6 Years Ago by peter_budo: Adding code tags

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...

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.

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

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 :)

please give me the executable complete code for encryption and also decryption of a file.

what i thought your problem was to encrypt username and password and to store it in a database..you can either use substitution cipher or transposition cipher.i recommend u to use substitution method in which replacing the value with another value.(for exampe: if u want to store a value 'a' you can add 3 letters with 'a' that is 'd' or
you can use transposition cipher in which you are only just changing the order of the letters.

Comments
Don't you think that problem will be either solved or given up after 3 years. Please do not open old threads
This question has already been answered. Start a new discussion instead.