code: private byte[] getSignature(final Manifest forManifest) throws IOException, GeneralSecurityException {
  
  		final ByteArrayOutputStream bos = new ByteArrayOutputStream();
  		final Manifest signatureFile    = new Manifest();
  		final Attributes main           = signatureFile.getMainAttributes();
  		final MessageDigest md          = MessageDigest.getInstance("SHA1");
  		final PrintStream print         = new PrintStream(new DigestOutputStream(new ByteArrayOutputStream(), md), true, "UTF-8");
  
  		main.putValue("Signature-Version", "1.0");
  
  		// Digest of the entire manifest
  		forManifest.write(print);
  		print.flush();
  
  		main.putValue("SHA1-Digest-Manifest", new String(Base64.encode(md.digest()), "ASCII"));
  
  		final Map<String, Attributes> entries = forManifest.getEntries();
  
  		for (Map.Entry<String, Attributes> entry : entries.entrySet()) {
  
  			// Digest of the manifest stanza for this entry.
  			print.print("Name: " + entry.getKey() + "\r\n");
  
  			for (Map.Entry<Object, Object> att : entry.getValue().entrySet()) {
  				print.print(att.getKey() + ": " + att.getValue() + "\r\n");
  			}
  
  			print.print("\r\n");
  			print.flush();
  
  			final Attributes sfAttr = new Attributes();
  			sfAttr.putValue("SHA1-Digest", new String(Base64.encode(md.digest()), "ASCII"));
  
  			signatureFile.getEntries().put(entry.getKey(), sfAttr);
  		}
  
  		signatureFile.write(bos);
  
  		return bos.toByteArray();
  	}
docs: Writes a .SF file with a digest to the manifest.