DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Java (http://www.daniweb.com/forums/forum9.html)
-   -   Java Encryption error (http://www.daniweb.com/forums/thread44217.html)

bondito Apr 26th, 2006 11:07 pm
Java Encryption error
 
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 :sad:

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();
 
            }
                }
    }

server_crash Apr 27th, 2006 7:29 am
Re: Java Encryption error
 
There's no return statement at the end of the string method. The unreachable statements are anything after your first return statement, because there's no case statement involved... It will always execute making anything below that not execute.


All times are GMT -4. The time now is 11:47 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC