encryption

Reply

Join Date: Sep 2005
Posts: 16
Reputation: bondito is an unknown quantity at this point 
Solved Threads: 1
bondito bondito is offline Offline
Newbie Poster

encryption

 
0
  #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

  1. import java.util.StringTokenizer;
  2.  
  3. public class Encryption {
  4.  
  5.  
  6. public static String encrypt(String password) {
  7. StringBuffer sb = new StringBuffer();
  8.  
  9. for (int i = 0; i<password.length(); i++) {
  10.  
  11. char c = password.charAt(i);
  12. int j = c;
  13. sb.append(String.valueOf(j) + " ");
  14. }
  15. return sb.toString().trim();
  16. }
  17.  
  18.  
  19. public static String decrypt(String encryptedPassword) {
  20. StringTokenizer st = new StringTokenizer(encryptedPassword, " ");
  21. //A StringTokenizer takes a string as input and breaks it upto tokens, seperated by " "
  22. StringBuffer sb = new StringBuffer();
  23. while (st.hasMoreTokens()) {
  24. int c = Integer.parseInt(st.nextToken());
  25. char chr = (char) c;
  26. sb.append(chr);
  27. }
  28. return sb.toString();
  29. }
  30. }
Last edited by cscgal; Apr 24th, 2006 at 11:46 am.
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: encryption

 
0
  #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 Quick reply to this message  
Join Date: Aug 2005
Posts: 5,264
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: encryption

 
0
  #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 Quick reply to this message  
Join Date: Sep 2005
Posts: 16
Reputation: bondito is an unknown quantity at this point 
Solved Threads: 1
bondito bondito is offline Offline
Newbie Poster

Re: encryption

 
0
  #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 Quick reply to this message  
Join Date: Aug 2005
Posts: 5,264
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: encryption

 
0
  #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 Quick reply to this message  
Join Date: Mar 2004
Posts: 763
Reputation: Phaelax is on a distinguished road 
Solved Threads: 38
Phaelax Phaelax is offline Offline
Master Poster

Re: encryption

 
0
  #6
Apr 24th, 2006
There's always MD5, if you never have to recover the readable password again.
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: encryption

 
0
  #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 Quick reply to this message  
Join Date: Dec 2004
Posts: 4,191
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: 485
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: encryption

 
0
  #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, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 216
Reputation: hooknc is an unknown quantity at this point 
Solved Threads: 8
hooknc hooknc is offline Offline
Posting Whiz in Training

Re: encryption

 
0
  #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 Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC