Women in Technology

Hear us Roar



Article:
  Programmatically Signing JAR Files
Subject:   missing SignatureFile class in JDK 1.5
Date:   2007-10-16 04:02:44
From:   craty
has anyone found the workout for the missing class sun.security.util.SignatureFile in JDK 1.5? If so please share the solution
Main Topics Oldest First

Showing messages 1 through 1 of 1.

  • missing SignatureFile class in JDK 1.5
    2009-06-27 22:46:40  ybiri [View]

    try to add the JRE 1.4 rt.jar. that should solve you the problem.

    I have added the missing lines (as described in below comments) and then added the main :
    try
    {
    FileInputStream fileIn = new FileInputStream("c:/temp/mv/mykeyStore");
    KeyStore keyStore = KeyStore.getInstance("JKS");
    String KSpassword="keyStorePass";
    char[] KSpss=KSpassword.toCharArray();
    String KeyPassword="keyPass";
    char[] Keypss=KeyPassword.toCharArray();
    keyStore.load(fileIn, KSpss);
    Certificate[] chain=keyStore.getCertificateChain("myKey");
    X509Certificate certChain[] = new X509Certificate[chain.length];

    CertificateFactory cf = CertificateFactory.getInstance("X.509");
    for (int count = 0; count < chain.length; count++)
    {
    ByteArrayInputStream certIn = new ByteArrayInputStream(chain[0].getEncoded());
    X509Certificate cert = (X509Certificate)cf.generateCertificate(certIn);
    certChain[count] = cert;
    }

    Key key = keyStore.getKey("localactionskey",Keypss);
    KeyFactory keyFactory = KeyFactory.getInstance(key.getAlgorithm());
    KeySpec keySpec = keyFactory.getKeySpec(key, DSAPrivateKeySpec.class);
    PrivateKey privateKey = keyFactory.generatePrivate(keySpec);
    JarSigner jarSigner = new JarSigner("myKey", privateKey, certChain);

    JarFile jarFile = new JarFile("c:/temp/mv/LE.jar");
    OutputStream outStream = new FileOutputStream("c:/temp/mv/LE_sgn.jar");
    jarSigner.signJarFile(jarFile, outStream);
    fileIn.close();
    }
    catch(Throwable ex)
    {
    ex.printStackTrace();
    }
    }