| | |
encryption
![]() |
•
•
Join Date: Sep 2005
Posts: 16
Reputation:
Solved Threads: 1
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
Java Syntax (Toggle Plain Text)
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.
>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]
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]
•
•
Join Date: Sep 2005
Posts: 16
Reputation:
Solved Threads: 1
•
•
•
•
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.
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]
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]
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
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
•
•
Join Date: Aug 2005
Posts: 216
Reputation:
Solved Threads: 8
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.
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.
![]() |
Similar Threads
- How to create SHA1 Encryption program (VB.NET)
- help with/removing window's encryption on my data (Windows NT / 2000 / XP)
- 128 bit encryption (Viruses, Spyware and other Nasties)
- AIM encryption (Viruses, Spyware and other Nasties)
- Storing passwords using reversible encryption in Active Directory (Windows NT / 2000 / XP)
- c++ windows program to demonstrate encryption (C++)
- No Encryption in IE 6.0/XP Home (Web Browsers)
Other Threads in the Java Forum
- Previous Thread: java multithreading
- Next Thread: Converting Java to C
| Thread Tools | Search this Thread |
911 actionlistener addressbook android api append applet application array arrays automation binary block bluetooth character chat class client code component consumer csv database desktop developmenthelp eclipse error fractal ftp game givemetehcodez graphics gui html ide image input integer j2me j2seprojects japplet java javaarraylist javac javaee javaprojects jni jpanel julia lego linked linux list loop mac map method methods mobile netbeans newbie number objects online oriented panel printf problem program programming project projects properties recursion replaydirector reporting researchinmotion rotatetext rsa scanner se server set singleton sms sort sql string swing test textfields threads time title tree tutorial-sample ubuntu update windows working






