Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 1976 | Replies: 1
![]() |
•
•
Join Date: Sep 2005
Location: london
Posts: 16
Reputation:
Rep Power: 4
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
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();
}
}
}•
•
Join Date: Jun 2004
Location: H4x0rville
Posts: 2,105
Reputation:
Rep Power: 9
Solved Threads: 18
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.
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)






Linear Mode