Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Other Java > Java Databases
| Search | Today's Posts | Mark Forums Read
Java Databases Discussion specific to working with Java Databases. For other Java topics, please see related Java forums. For database discussions not specific to Java, please see the Database category.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old March 11th, 2005, 12:12 PM
Authorized User
 
Join Date: Dec 2004
Location: , , .
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to inderjeet_79
Default Storing password using encryption from JAVA

Hi All
I have to store password in encrypted form in the database using JAVA.
i need a technique with which i should be able to enctrypt it using either key or without using key. I can not use the auto generated key. If anybody can send some code examples that would be very helpful to me.
Thanks
Inderjeet

  #2 (permalink)  
Old April 1st, 2005, 04:22 AM
Authorized User
 
Join Date: Nov 2004
Location: , , Hong Kong.
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

import java.security.MessageDigest;

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++) {
                //Convert it to positive integer and then to Hex String

                hex = Integer.toHexString(0xFF & digestBytes[i]);

                //Append "0" to the String to made it exactly 128 length (SHA-512 alogithm)
                if (hex.length() < 2)
                    sb.append("0");
                sb.append(hex);
                }
            }
        catch (Exception ex) {
            System.out.println(ex.getMessage());
            }

        return new String(sb);
    }


  #3 (permalink)  
Old October 3rd, 2007, 05:45 AM
Registered User
 
Join Date: Oct 2007
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

can I get decryption code for this...

  #4 (permalink)  
Old October 11th, 2007, 04:11 AM
Friend of Wrox
 
Join Date: Mar 2007
Location: Hyderabad, A.P., India.
Posts: 373
Thanks: 0
Thanked 1 Time in 1 Post
Default

I think the code posted is to digest the given text, i dont think you can get back the original text from digest. If you want to compare then try digesting the input and compare it with already digested text.

- Rakesh


Similar Threads
Thread Thread Starter Forum Replies Last Post
Password encryption and storage in the database. zaheerabbas.sk ASP.NET 1.0 and 1.1 Basics 4 July 30th, 2008 05:03 AM
Password encryption decryption, storage in databas zaheerabbas.sk ASP.NET 1.0 and 1.1 Professional 1 April 25th, 2007 02:15 AM
password encryption angshujit ASP.NET 2.0 Basics 1 January 4th, 2007 03:34 PM
password encryption kosla78 Classic ASP Professional 6 July 12th, 2006 03:50 PM
Login/Password Java application larry Apache Tomcat 2 December 20th, 2005 04:42 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.