Hi all,
I have a .jar file to be call the in my perl module. Which is used to calculate 3DES/RSA encryption of password.
The .jar file (ChunghwaPost.jar) was archived like this.
url: https://ipost.post.gov.tw/web/ChunghwaPost.jar
file: MainApplet.class
file: MainApplet.html
Directory and files: PaySecure.*

MainApplet.class is the integrated interface of class PaySecure.
MainApplet.html is the demo of how to use MainApplet.class

So here is the java code which embedded in the MainApplet.html.
The order of function execution to encrypt password is GenTDES()->EncryptTDES()->RSAEncryptTDES();.
In other words, the actual calling order which mapped into .jar file is
Generate3DES()->getEncryptPINcode()->getRsaEncrypt3DES();.



Here is the unzipped jar file ChunghwaPost_jarunzipped.zip
The completed MainApplet.html has been included.
------ Java Script of MainApplet.html -------
function GenTDES() // Generate3DES() can be direct accessed in MainApp +let.class { if(document.app.Generate3DES()) { document.form1.GetGenTDESVle.value= "Success"; } else { document.form1.GetGenTDESVle.value=document.app.getErrorString(); } } // getEncryptPINcode() can be direct accessed in MainApplet.class function EncryptTDES() { if(document.app.EncryptPINcode(document.form1.UserPin.value)) { document.form1.GetEncryptTDESVle.value= document.app.getEn +cryptPINcode(); } else { document.form1.GetEncryptTDESVle.value=document.app.getErr +orString(); } } // RsaEncrypt3DES() can be direct accessed in MainApplet.class however + it will call into PaySecure.* classes. function RSAEncryptTDES() { if(document.app.RsaEncrypt3DES()) { document.form1.GetRSAEncryptTDESVle.value= document.app.getRsaEn +crypt3DES(); } else { document.form1.GetRSAEncryptTDESVle.value= document.app.getError +String(); } }

--------------------------------------------------------
Then I wrote "POST_iCrypt.pm" and a perl script "jartest.pl" in perl
to do the same thing which has been done in the html.
--------------- POST_iCrypt.pm --------------------------
package POST_jCRYPT; use strict; use warnings; use Inline::Java; BEGIN { $ENV{CLASSPATH} .= "./ChunghwaPost.jar"; } use Inline Java => 'STUDY', STUDY => [ 'MainApplet' ], AUTOSTUDY => '1', DEBUG => '1'; sub new { my $MainApplet = shift; return POST_jCRYPT->new(@_); } 1;

-----------------------------------------------------

------------------- jartest.pl ----------------------
#!/usr/bin/perl #use strict; use warnings; use Inline::Java; use Data::Dumper; use lib '/home/macpaul/perl'; use POST_jCRYPT; my $pwd ="12345678"; my $usercode ="example1"; my $javaobj = POST_jCRYPT::MainApplet->new(); # ePin print $javaobj->Generate3DES(), "\n"; $javaobj->EncryptPINcode($pwd); my $ePIN = $javaobj->getEncryptPINcode(); print $ePIN, "\n"; $javaobj->RsaEncrypt3DES(); my $eKey = $javaobj->getRsaEncrypt3DES(); print $eKey, "\n";

----------------------------------------------------



However, when I execute jartest.pl, I can get correct result when I called "Generate3DES()" and "getEncryptPINcode()", but fail when "getRsaEncrypt3DES" and I get "method RsaEncrypt3DES in class MainApplet threw exception java.lang.NullPointerException: null".

Any misteak I have made so that I couldn't get the same result when I do this encryption by opening the demo html in browser?

Thanks for help.


In reply to Problem about NullPointerException when using Inline::Java and Jar file by macpaul

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.