Archive for the ‘Ben Millionaire Java Programming Experience’ Category




Encountering Java Error: javax.crypto.BadPaddingException

Tuesday, February 23rd, 2010

I am encountering this error and I don’t know yet the fix for this:

java.lang.RuntimeException: keystore load: failed to decrypt safe contents entry: javax.crypto.BadPaddingException: Given final block not properly padded

Any idea why this error message appeared?

Java: String.getBytes method sample program

Monday, November 23rd, 2009

String.getBytes

public byte[] getBytes(String charsetName) throws UnsupportedEncodingException

Description:
Encodes this String into a sequence of bytes using the named charset, storing the result into a new byte array. This method is risky and will throw UnsupportedEncodingException if named charset is not supported.

Here’s the sample program I developed:

public class StringByte {
 public static void main(String[] args) {
  String xxx = new String("abc\u00e7");
  
  byte[] xx;
  try
  {
      xx = xxx.getBytes("UTF8");
   for(int i=0;i<xx.length;i++)
   {
    System.out.println(xx[i]);
   }
   System.out.println("Length of " + xxx + " is: " + xx.length);
  }
  catch(Exception e)
  {
   
  }

                char[] yyy = xxx.toCharArray();

                for(int i=0;i<yyy.length;i++)
                    System.out.println("Char["+i+"] = " + yyy[i]);
 }
}

 

Output:

compile and run StringByte.java

compile and run StringByte.java