| | |
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 |
android api applet application apps array arrays automation awt bidirectional binary birt bluetooth businessintelligence busy_handler(null) card class classes client code collision columns component constructor crashcourse database designadrawingapplicationusingjavajslider draw eclipse error errors eventlistener exception expand fractal game givemetehcodez graphics gui guidancer html ide image inetaddress integer intellij j2me java javadoc javafx javamicroeditionuseofmotionsensor javaprojects jme jni jpanel jtree julia linux list loop machine map method methods mobile mobiledevelopmentcreatejar myaggfun netbeans newbie oracle physics plazmic print problem program project radio recursion scanner server set sharepoint smart sms smsspam sort sortedmaps sql string subclass support swing textfield threads tree trolltech unlimited utility webservices windows






