1 Reply Latest reply on Sep 29, 2012 2:38 AM by xin.zhang.song

    Some question about bouncycastle in AS7

    xin.zhang.song

      Hi All,

       

      Good afternoon

       

      There are some question about bouncycastle in AS7,

      and here are the error message in the log:

       

      14:04:57,405 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/bvmc].[action]] (http-0.0.0.0-0.0.0.0-7110-1) Servlet.service() for servlet action threw exception: java.lang.ClassCastException: org.bouncycastle.jce.provider.JCEBlockCipher$RC2CBC cannot be cast to javax.crypto.CipherSpi

              at javax.crypto.Cipher.a(DashoA13*..) [jce.jar:1.6]

              at javax.crypto.Cipher.init(DashoA13*..) [jce.jar:1.6]

              at javax.crypto.Cipher.init(DashoA13*..) [jce.jar:1.6]

              at com.broadvision.basic.evaluation.DataChecker2.getChecker(DataChecker2.java:705) [bv_svc_clt.jar:]

              at com.broadvision.basic.evaluation.DataChecker2.interpretData(DataChecker2.java:759) [bv_svc_clt.jar:]

       

      this is my code:

       

          private static

          Cipher getChecker(int mode, byte rawKey[], String prov, String algo)

          throws GeneralSecurityException

          {

              AlgorithmParameterSpec param = null;

              final byte RC2IV[] = { 'b', 'r', 'd', 'v', 's', 'i', 'o', 'n' };

              final byte AESIV[] = { 'b', 'r', 'o', 'a', 'd', 'v', 'i', 's', 'i', 'o', 'n', 'c', 'r', 'y', 'p', 't' };

              final byte AES256IV[] = { 'b', 'r', 'o', 'a', 'd', 'v', 'i', 's', 'i', 'o', 'n', 'e', 'n', 'c', 'r', 'y' };

       

       

              final Cipher cipher = getChecker(prov, algo);

              //final String alg = cipher.getAlgorithm();

              String algorithm = "";

              if (algo.equals(AES_BC) || algo.equals(AES_BC_CODE)) {

                

                  final byte iv[] = AESIV;

                  param = new IvParameterSpec(iv);

                  // For SunJCE JVM 1.4.2

                  algorithm = "AES";

       

       

              } else if (algo.equals(RC2_BC) || algo.equals(RC2_BC_CODE)) {

       

       

                  final byte iv[] = RC2IV;

                  final int effectiveBits = rawKey.length > MAX_OLD_KEY ? 128 : 80;

                  param = new RC2ParameterSpec(effectiveBits, iv);

                 

                  // For SunJCE JVM 1.4.2

                  algorithm = "RC2";

              }

              else if (algo.equals(AES256_BC) || algo.equals(AES256_BC_CODE)) {

                  final byte iv[] = AES256IV;

                  param = new IvParameterSpec(iv);

       

                  // use same transformation string as AES_BC for boncy castle

                  algorithm = "AES";

              }

       

       

              final SecretKeySpec key = new SecretKeySpec(rawKey, algorithm);

              // the line that post error message in the console

              cipher.init(mode, key, param);

              return cipher;

          }

       

      Does someone have any advice for this

       

      Thank you

       

      Xin