0

I'm getting this error on a java number decoding program. My sample code is following:

import java.io.PrintStream;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import sun.misc.BASE64Decoder;
public class Decryptno
{
Cipher cipher;
static final String strPassword = "pwd1234";
public Decryptno() {}
static SecretKeySpec key = new SecretKeySpec("pwd1234".getBytes(), "AES");
public static void main(String[] paramArrayOfString) throws Exception {
String str1 = paramArrayOfString[0];
String str2 = null;
IvParameterSpec localIvParameterSpec = new IvParameterSpec("pwd1234".getBytes());

Cipher localCipher = Cipher.getInstance("AES/CBC/PKCS5Padding");

localCipher.init(2, key, localIvParameterSpec);
try {
  if ((str1 != null) && (str1.length() > 0)) {
    byte[] arrayOfByte1 = new BASE64Decoder().decodeBuffer(str1);

    byte[] arrayOfByte2 = localCipher.doFinal(arrayOfByte1);
    str2 = new String(arrayOfByte2);
  } else {
    str2 = str1;
  }
  System.out.println(str2);
} catch (Exception localException) {
  localException.printStackTrace();
}
}
}

This is giving output as:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 at Decryptno.main(Decryptno.java:17)

What may be the reasons?

Kaustubh Khare
  • 3,280
  • 2
  • 32
  • 48
Indra
  • 1
  • 2
  • 1
    There are a number of problems with this post: 1. Please search before posting. 2. Please format your code neatly. 3. Please point out what line is line 17. 4. Your debugger should have dropped you on the precise line with the error and you could have easily discovered what was causing the problem yourself. – Ken Y-N Nov 13 '17 at 07:12
  • I didn't write this code, I copied it from somewhere and it's not working. And If I knew this much like you people, then why would I come here asking for help. It's OK if you can't help to correct this code. – Indra Nov 13 '17 at 07:20

0 Answers0