Java Exception when using getObject("java:myclass"

Results 1 to 2 of 2

Thread: Java Exception when using getObject("java:myclass"

  1. #1
    David Lam Guest

    Default Java Exception when using getObject("java:myclass"

    Hello All,<BR>I have tried to make use of the Java example in Sun&#039s tutorial<BR>which is about security.The class GenSig is to generate a signature for a file,which is an argument when running in DOS prompt: <BR><BR>java GenSig filename<BR><BR>It works fine there,so I try to adapt it in ASP,using the<BR>getObject("java:GenSig") command.I changed the java program <BR>a bit at the same time in order to input the filename as a parameter of a public fucntion instead of the program argument.<BR><BR>However,when I run the program,there is such error message:<BR>java.lang.NoClassDefFoundError: java/security/SecureRandom.<BR>Why will this happen?Please give me a hand!<BR><BR>Thank you very much!<BR><BR>This is the ASP:<BR>&#060;%<BR>set f = getObject( "java:GenSig" )<BR>f.gen("c:javaAspjava.txt")<BR>%&#062;<BR><BR> Below is my code of JAVA :<BR>import*;<BR>import*;<BR><BR>public class GenSig {<BR><BR>public GenSig(){}<BR><BR>public String gen(String para1) {<BR><BR>/* Generate a DSA signature */<BR><BR>try{<BR><BR>/* Generate a key pair */<BR><BR>KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA", "SUN");<BR>SecureRandom random = SecureRandom.getInstance("SHA1PRNG", "SUN");<BR><BR>keyGen.initialize(1024, random);<BR>KeyPair pair = keyGen.generateKeyPair();<BR>PrivateKey priv = pair.getPrivate();<BR>PublicKey pub = pair.getPublic();<BR><BR><BR>/* Create a Signature object and initialize it with the private key */<BR><BR>Signature dsa = Signature.getInstance("SHA1withDSA", "SUN"); <BR><BR>dsa.initSign(priv);<BR><BR>/* Update and sign the data */<BR><BR>FileInputStream fis = new FileInputStream(para1);<BR>BufferedInputStream bufin = new BufferedInputStream(fis);<BR>byte[] buffer = new byte[1024];<BR>int len;<BR>while (bufin.available() != 0) {<BR>len =;<BR>dsa.update(buffer, 0, len);<BR>};<BR><BR>bufin.close();<BR><BR>/* Now that all the data to be signed has been read in, <BR>generate a signature for it */<BR><BR>byte[] realSig = dsa.sign();<BR><BR><BR>/* Save the signature in a file */<BR>FileOutputStream sigfos = new FileOutputStream("sig");<BR>sigfos.write(realSig); <BR><BR>sigfos.close();<BR><BR><BR>/* Save the public key in a file */<BR>byte[] key = pub.getEncoded();<BR>FileOutputStream keyfos = new FileOutputStream("suepk");<BR>keyfos.write(key);<B R><BR>keyfos.close();<BR><BR><BR>} catch (Exception e) {<BR>System.err.println("Caught exception " + e.toString());<BR>}<BR>return "success";<BR>};<BR><BR>}<BR><BR>Thank you very much!!

  2. #2
    Join Date
    Dec 1969

    Default RE: Java Exception when using getObject(

    I seem to remember hitting a similar problem when I was trying to write my own key generator / file signer in Java. I&#039m pretty sure that is caused by the fact that Java under COM is handled by the MS JVM, which isn&#039t really Java in the strict sense. In particular the way MS implements Security Providers seems to be incompatible with Sun&#039s implementation - at least it was on my machine the last time I checked (about a year ago...)<BR><BR>You&#039d almost think they deliberately made the class libraries incompatible... Not that MS would ever pull such a low-down dirty trick ;-)<BR><BR>If you&#039re wanting to generate signatures (or do other encryption-type operations) under ASP, have a look at ASPEncrypt from Persits Software -<BR><BR>Dunc

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts