| | |
Java Encryption error
![]() |
•
•
Join Date: Sep 2005
Posts: 16
Reputation:
Solved Threads: 1
Hi Everyone, i am trying to use an encryption class to encrypt pasword characters, i have modified the encryption class correctly, but i am getting an unreachable statement error and a missing return statement error. Pls could any one tell me what the problem might be with the code. Thanks
Java Syntax (Toggle Plain Text)
package datasource; import java.security.*; import javax.crypto.*; import javax.crypto.spec.*; public class Encryption { public static String encrypt (String password){ try{ //Get the key generator and create the key // System.out.println("Getting key generator ...."); KeyGenerator kgen = KeyGenerator.getInstance( "Blowfish" ); System.out.println("Getting key generator ...."); SecretKey secretKey = kgen.generateKey(); byte[] bytes = secretKey.getEncoded(); SecretKeySpec specKey = new SecretKeySpec (bytes, "Blowfish" ); // Create the cipher object // System.out.println("Creating cipher ...."); Cipher cipher = Cipher.getInstance( "Blowfish" ); System.out.println("Encrypting ..."); cipher.init( Cipher.ENCRYPT_MODE, specKey ); // String target = "Encrypt Michael"; byte[] encrypted = cipher.doFinal( password.getBytes() ); return encrypted.toString(); //System.out.println("before: " + target ); // System.out.println("after: " + new String( encrypted ) ); // Decrypt cipher.init ( Cipher.DECRYPT_MODE, specKey ); byte[] decrypted = cipher.doFinal ( encrypted); return decrypted.toString(); //System.out.println("\nafter decrypt: " + new String( decrypted ) ); } catch (Exception e) { e.printStackTrace(); } } }
![]() |
Similar Threads
- Java Encryption and Decryption (Java)
- Exception in thread "main" java.lang.NoClassDefFoundError: Invaders Error (Java)
- Error running Java (Java)
- Java Encryption (Elections System) (Java)
- java (Windows NT / 2000 / XP)
Other Threads in the Java Forum
- Previous Thread: Swing Button question
- Next Thread: Hangman classes not working at home.
| Thread Tools | Search this Thread |
6 @param affinetransform android api apple applet application arc arguments array automation binary binarytree bluetooth bold c++ chatprogramusingobjects class client code color compare component coordinates count database design detection doctype eclipse eclipsedevelopment educational encryption error file fractal froglogic game givemetehcodez graphics gridlayout gui guitesting helpwithhomework html ide ideas if_statement image ingres intersect j2me java java.xls javadesktopapplications javaexcel javaprojects jni jpanel jtextarea julia keytool keyword linux list macintosh map method methods mobile netbeans nextline object pong problem producer program project projectideas recursive replaysolutions rim scanner sell server set size sms sql swing terminal threads transforms tree ui unicode web websites windows






