RSS Forums RSS
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 2335 | Replies: 8
Reply
Join Date: Sep 2005
Location: london
Posts: 16
Reputation: bondito is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 1
bondito bondito is offline Offline
Newbie Poster

encryption

  #1  
Apr 23rd, 2006
Hi everyone, i am trying to use some java code to encrypt passwords entering a database on the system i am building, please could someone explain what the code below is doing and if it would be useful for encrypting passwords. Thanks

import java.util.StringTokenizer;
 
public class Encryption {
 
 
    public static String encrypt(String password) {
        StringBuffer sb = new StringBuffer();
 
        for (int i = 0; i<password.length(); i++) {
 
            char c = password.charAt(i);
            int j = c;
            sb.append(String.valueOf(j) + " ");
        }
        return sb.toString().trim();
    }
 
 
    public static String decrypt(String encryptedPassword) {
        StringTokenizer st = new StringTokenizer(encryptedPassword, " ");
        //A StringTokenizer takes a string as input and breaks it upto tokens, seperated by " "
        StringBuffer sb = new StringBuffer();
        while (st.hasMoreTokens()) {
            int c = Integer.parseInt(st.nextToken());
            char chr = (char) c;
            sb.append(chr);
        }
        return sb.toString();
    }
}
Last edited by cscgal : Apr 24th, 2006 at 11:46 am.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2004
Location: H4x0rville
Posts: 2,105
Reputation: server_crash is on a distinguished road 
Rep Power: 9
Solved Threads: 18
server_crash's Avatar
server_crash server_crash is offline Offline
Postaholic

Re: encryption

  #2  
Apr 24th, 2006
I don't see where you're encrypting it... You get the char value from the int value, which is from the same char value, so you're really doing nothing there. You need to get the ascii value and add least add something to it.
Reply With Quote  
Join Date: Aug 2005
Posts: 4,832
Reputation: iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light 
Rep Power: 17
Solved Threads: 324
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Industrious Poster

Re: encryption

  #3  
Apr 24th, 2006
>if it would be useful for encrypting passwords?

What, for real databases? Probably not, the encryption system looks weak.

Isn't there some java API for this anyway?

http://img476.imageshack.us/img476/5171/cut20ln.png
Piworld
[Tis simple as Pie]
Reply With Quote  
Join Date: Sep 2005
Location: london
Posts: 16
Reputation: bondito is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 1
bondito bondito is offline Offline
Newbie Poster

Re: encryption

  #4  
Apr 24th, 2006
Originally Posted by server_crash
I don't see where you're encrypting it... You get the char value from the int value, which is from the same char value, so you're really doing nothing there. You need to get the ascii value and add least add something to it.


Do you know any kind of java class i can use to encrypt passwords goin into a Mysql database.
Reply With Quote  
Join Date: Aug 2005
Posts: 4,832
Reputation: iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light 
Rep Power: 17
Solved Threads: 324
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Industrious Poster

Re: encryption

  #5  
Apr 24th, 2006
Perhaps this?

http://java.sun.com/j2se/1.4.2/docs/...ryptoSpec.html

If you're going to do this yourself, I'd plump for xor encryption. So long as the key is sufficiently long and randomised.

http://img476.imageshack.us/img476/5171/cut20ln.png
Piworld
[Tis simple as Pie]
Reply With Quote  
Join Date: Mar 2004
Posts: 733
Reputation: Phaelax is on a distinguished road 
Rep Power: 6
Solved Threads: 31
Phaelax Phaelax is offline Offline
Master Poster

Re: encryption

  #6  
Apr 24th, 2006
There's always MD5, if you never have to recover the readable password again.
Reply With Quote  
Join Date: Jun 2004
Location: H4x0rville
Posts: 2,105
Reputation: server_crash is on a distinguished road 
Rep Power: 9
Solved Threads: 18
server_crash's Avatar
server_crash server_crash is offline Offline
Postaholic

Re: encryption

  #7  
Apr 24th, 2006
Java has a crypto and security package. It will do everything for you, but probably the same amount of time will be taken because you'll need to learn it.
Reply With Quote  
Join Date: Dec 2004
Location: London or Slovakia
Posts: 2,703
Reputation: peter_budo is just really nice peter_budo is just really nice peter_budo is just really nice peter_budo is just really nice 
Rep Power: 12
Solved Threads: 320
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: encryption

  #8  
Apr 30th, 2006
Here is alink to 1.5 version if you want http://java.sun.com/j2se/1.5.0/docs/...ryptoSpec.html
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, JAVAWUG (Java Web User Group), Coding the Architecture
Reply With Quote  
Join Date: Aug 2005
Location: Socialist Republic of Boulder
Posts: 216
Reputation: hooknc is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 6
hooknc hooknc is offline Offline
Posting Whiz in Training

Re: encryption

  #9  
Apr 30th, 2006
I wouldn't recommend using java to do any encryption to the database. DBs have their own encryption built in. Just add the DBs encryption on your jdbc call.


UPDATE users SET password = AES_ENCRYPT(`users password`, `your encryption key` WHERE id=`101`;


This makes it so you don't have to have encryption in each and every java application that touches the database. Much nicer in my opinion.


The above example is for a mysql database.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 4:19 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC