Aug 13 2009

JAVA Security Provider Error

Just a quick note about a simple but annoying error I encountered when porting an app to glassfish; The code in question was as follows:

 
     ... 
    Charset charset = Charset.forName("UTF-8");
    CharsetEncoder encoder = charset.newEncoder();
    ByteBuffer bbuf = encoder.encode(CharBuffer.wrap(str));
    SecretKeySpec key = new SecretKeySpec( KEY_BASE, "DES" );

    private static Cipher ecipher = Cipher.getInstance( "DES");
    ecipher.init( Cipher.ENCRYPT_MODE, key ); 
    byte[] enc = ecipher.doFinal( bbuf.array() );
     ...
The code above just converts a string (stored as str here) to UTF-8 then encrypts it using DES. Equivalently you could use str.getBytes() for the UTF conversion. The code above worked fine on JBOSS, and worked fine stand alone. It even worked on my glassfish test server, however when deployed on glassfish enterprise I started getting the following stacktrace: Continue reading