Search in sources :

Example 1 with Base64

use of aQute.lib.base64.Base64 in project bnd by bndtools.

the class Signer method doManifest.

private void doManifest(Jar jar, String[] digestNames, MessageDigest[] algorithms, OutputStream out) throws Exception {
    Writer w = IO.writer(out, UTF_8);
    try {
        for (Map.Entry<String, Resource> entry : jar.getResources().entrySet()) {
            String name = entry.getKey();
            if (!METAINFDIR.matcher(name).matches()) {
                w.write("\r\n");
                w.write("Name: ");
                w.write(name);
                w.write("\r\n");
                digest(algorithms, entry.getValue());
                for (int a = 0; a < algorithms.length; a++) {
                    if (algorithms[a] != null) {
                        byte[] digest = algorithms[a].digest();
                        String header = digestNames[a] + "-Digest: " + new Base64(digest) + "\r\n";
                        w.write(header);
                    }
                }
            }
        }
    } finally {
        w.flush();
    }
}
Also used : Base64(aQute.lib.base64.Base64) EmbeddedResource(aQute.bnd.osgi.EmbeddedResource) Resource(aQute.bnd.osgi.Resource) Map(java.util.Map) PrintWriter(java.io.PrintWriter) Writer(java.io.Writer)

Example 2 with Base64

use of aQute.lib.base64.Base64 in project bnd by bndtools.

the class Signer method doSignatureFile.

private byte[] doSignatureFile(String[] digestNames, MessageDigest[] algorithms, byte[] manbytes) throws IOException {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    PrintWriter ps = IO.writer(out);
    ps.print("Signature-Version: 1.0\r\n");
    for (int a = 0; a < algorithms.length; a++) {
        if (algorithms[a] != null) {
            byte[] digest = algorithms[a].digest(manbytes);
            ps.print(digestNames[a] + "-Digest-Manifest: ");
            ps.print(new Base64(digest));
            ps.print("\r\n");
        }
    }
    return out.toByteArray();
}
Also used : Base64(aQute.lib.base64.Base64) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PrintWriter(java.io.PrintWriter)

Aggregations

Base64 (aQute.lib.base64.Base64)2 PrintWriter (java.io.PrintWriter)2 EmbeddedResource (aQute.bnd.osgi.EmbeddedResource)1 Resource (aQute.bnd.osgi.Resource)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 Writer (java.io.Writer)1 Map (java.util.Map)1