0

i get this error message when i try to break in 2 parts (with "break point" the character "@")

  • part_fixed
  • part_user

    a secret key "final key" saved as string.

           service_codeEncrypted_key = new SecretKeySpec(service_codeEncrypted, 0, 8, "DES");
    
    
            System.out.println("");
            System.out.println("Secret code as secret key :" + service_codeEncrypted_key);
            System.out.println("");
            String final_key = "service_codeEncrypted_key";//key has the form xxx.xxx.xxx.xxx@yyyyy
            String[] parts = final_key.split("@") ;
            String part_fixed = parts[0]; // xxx.xxx.xxx.xxx
            String part_user = parts[1]; // yyyy
            System.out.println("");             
            System.out.println("Service Code decrypted : " + new String(service_codeDecrypted)); // Print the decrypted Text
            System.out.println("");
            // System.out.println("Code for the card : " + part_user); // Print the decrypted Text          
            System.out.println("Finish!!!"); // Print the decrypted Text
            System.out.println("-----------------------------------------------------------------------------------"); // Print the decrypted Text
            System.out.println("");
            System.out.println("");
    

The error as shown in the console in the following :

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 at JEncrytion.main(JEncrytion.java:182)

where line 182 is : String part_fixed = parts[0];

The acual key has the form xxx.xxx.xxxxxx.xxx@yyyyy, and i want all the x's in one part and all the y in the second one.

Any ideas?

1
  • why don't you print the length of the parts (System.out.println(parts.length);) before accessing the array elements to see how many elements are there? Commented Sep 25, 2013 at 9:45

4 Answers 4

1

String final_key = "service_codeEncrypted_key"; // here is the problem

Replace with the following

String final_key = service_codeEncrypted_key; 

and consider this one too

   String part_fixed ="";
   String part_user ="";
   if(parts!=null){
       part_fixed = parts[0]; // xxx.xxx.xxx.xxx
       part_user = parts[1]; // yyyy
   }
Sign up to request clarification or add additional context in comments.

1 Comment

Thanx mate, that was actually the problem, which of course created another one (i was silly to thing that a secret key could be saved as a string so easily). Thanx again, silly error, i know.
0

final_key (value = "service_codeEncrypted_key") string does not contain @ and hence the result of split will be an array of single element i.e the original string. So accesing the second element in that array as mentioned here:

parts[1]; 

will throw an ArrayIndexOutOfBoundsException

The logical problem in your code is that you wanted to assign the service_codeEncrypted_key variable to final_key but instead you did the string assignment. So as mentioned by Prabhakaran in his answer, replace this:

String final_key = "service_codeEncrypted_key";

with

String final_key = service_codeEncrypted_key;

1 Comment

Thanx Juned, just mentioned i save the name of the secter key as a string , and not the secret key itself!
0

That is right your key doesn't contain '@' symbol.

You need to code something like this.

if(final_key.contains("@")){
String[] parts = final_key.split("@") ;
    String part_fixed = parts[0]; // xxx.xxx.xxx.xxx
    String part_user = parts[1]; // yyyy
}

Comments

0
String final_key = "service_codeEncrypted_key";

doesn't contain the @ character and so the parts[] has no element.

Try to use

String[] parts = service_codeEncrypted_key.split("@");

1 Comment

Thanx a! Your proposal is totally in the right direction, i just get the JEncrytion.java:181: cannot find symbol symbol : method split(java.lang.String) location: interface javax.crypto.SecretKey String[] parts = service_codeEncrypted_key.split("@"); error, because (of course) this is a secret key and not a string. I will try to convert it first.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.