[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 538
  • Last Modified:

Problem initializing javax.crypto.Cipher class in PHP...

The following Java class method runs fine in the JDK environment, however when calling the same class using a PHP script in ie, it returns the error "Warning: java.lang.ExceptionInInitializerError in c:\inetpub\wwwroot\test2.php on line 3".



This works fine in the JDK environment...

private String decrypt(String pData, java.security.Key pKey)
            throws java.security.GeneralSecurityException,java.io.UnsupportedEncodingException
    {
           javax.crypto.Cipher cipher;
            byte[] rawBytes;
            byte[] decrypted;

            rawBytes = Base64.decode(pData);
            cipher = javax.crypto.Cipher.getInstance("DES");
            cipher.init(javax.crypto.Cipher.DECRYPT_MODE, pKey);
            decrypted = cipher.doFinal(rawBytes);
            return new String(decrypted, "ASCII");
    }


This returns the above mentioned error...

<?php
           $theClass = new Java("javax.crypto.Cipher");
           echo $theClass->getInstance("DES");
?>


Calling the class method returns the same error (it bombs out at the getInstance call)...

<?php
      $theClass = new Java("decryptXML");
      echo $theClass->decodeXML("");
?>

Everything is being run on the localhost in XP using iis 5.1.
I'm thinking it might be something to do with the 'DES' algorithm thats somehow not being seen by php??
0
hralloy
Asked:
hralloy
1 Solution

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now