RSS Forums RSS
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 1976 | Replies: 1
Reply
Join Date: Sep 2005
Location: london
Posts: 16
Reputation: bondito is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 1
bondito bondito is offline Offline
Newbie Poster

Java Encryption error

  #1  
Apr 26th, 2006
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

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();
 
            }
                }
    }
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2004
Location: H4x0rville
Posts: 2,105
Reputation: server_crash is on a distinguished road 
Rep Power: 9
Solved Threads: 18
server_crash's Avatar
server_crash server_crash is offline Offline
Postaholic

Re: Java Encryption error

  #2  
Apr 27th, 2006
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.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
All times are GMT -4. The time now is 9:21 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC