try {
Vector classNames = new Vector();
ZipEntry ze;
// In 1.2 beta 4, these methods have all changed signature
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
char c[] = new char[args[1].length()];
args[1].getChars(0, c.length, c, 0);
ks.load(new FileInputStream(System.getProperty("user.home") + File.separator + ".keystore"), c);
Certificate certs[] = ks.getCertificateChain(args[0]);
PrivateKey pk = (PrivateKey) ks.getKey(args[0], c);
Signature sig = Signature.getInstance("DSA");
sig.initSign(pk);
ZipFile zf = new ZipFile(args[2]);
ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(args[2] + ".sig"));
for (Enumeration e = zf.entries(); e.hasMoreElements(); ) {
ze = (ZipEntry) e.nextElement();
System.out.println("processing " + ze.getName());
InputStream zipBuf = zf.getInputStream(ze);
ByteArrayOutputStream zipOut = new ByteArrayOutputStream();
int n;
while ((n = zipBuf.read()) != -1) {
zipOut.write(n);
}
byte data[] = zipOut.toByteArray();
if (ze.getName().endsWith(".class")) {
classNames.addElement(ze.getName());
sig.update(data);
}
zos.putNextEntry(ze);
zos.write(data, 0, data.length);
zos.closeEntry();
}
ze = new ZipEntry("SIGNATURE");
zos.putNextEntry(ze);
byte signature[] = sig.sign();
ObjectOutputStream oos = new ObjectOutputStream(zos);
oos.writeObject(signature);
zos.closeEntry();
ze = new ZipEntry("CERTIFICATE");
zos.putNextEntry(ze);
oos = new ObjectOutputStream(zos);
oos.writeObject(certs[0].getEncoded());
zos.closeEntry();
ze = new ZipEntry("CLASSNAMES");
zos.putNextEntry(ze);
oos = new ObjectOutputStream(zos);
String classNameArray[] = new String[classNames.size()];
classNames.copyInto(classNameArray);
oos.writeObject(classNameArray);
zos.closeEntry();
} catch (Exception e) {
e.printStackTrace();
}