Programmatically Signing JAR Files
Subject:   missing SignatureFile class in JDK 1.5
Date:   2009-06-27 22:46:40
From:   ybiri
Response to: missing SignatureFile class in JDK 1.5

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 :
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);
catch(Throwable ex)