Update crypto

This commit is contained in:
topjohnwu 2018-01-23 05:06:34 +08:00
parent e8302dfbe2
commit 97cf15007f
3 changed files with 9 additions and 11 deletions

2
app

@ -1 +1 @@
Subproject commit 759e905c3c61018ae736e313d0272e215086f6e2
Subproject commit 00d655f346fe6182d508d76d6b75d8e7357fcb9d

View File

@ -70,9 +70,8 @@ public class SignAPK {
}
public static void signZip(InputStream publicIn, InputStream privateIn,
JarMap input, File output, boolean minSign) throws Exception {
JarMap input, OutputStream output, boolean minSign) throws Exception {
int alignment = 4;
BufferedOutputStream outputFile;
int hashes = 0;
X509Certificate publicKey = CryptoUtils.readPublicKey(publicIn);
hashes |= getDigestAlgorithm(publicKey);
@ -83,11 +82,10 @@ public class SignAPK {
long timestamp = publicKey.getNotBefore().getTime() + 3600L * 1000;
PrivateKey privateKey = CryptoUtils.readPrivateKey(privateIn);
outputFile = new BufferedOutputStream(new FileOutputStream(output));
if (minSign) {
signWholeFile(input.getFile(), publicKey, privateKey, outputFile);
signWholeFile(input.getFile(), publicKey, privateKey, output);
} else {
JarOutputStream outputJar = new JarOutputStream(outputFile);
JarOutputStream outputJar = new JarOutputStream(output);
// For signing .apks, use the maximum compression to make
// them as small as possible (since they live forever on
// the system partition). For OTA packages, use the
@ -98,10 +96,7 @@ public class SignAPK {
Manifest manifest = addDigestsToManifest(input, hashes);
copyFiles(manifest, input, outputJar, timestamp, alignment);
signFile(manifest, input, publicKey, privateKey, outputJar);
outputJar.close();
}
input.close();
outputFile.close();
}
/**

View File

@ -2,8 +2,10 @@ package com.topjohnwu.crypto;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.security.Security;
@ -32,8 +34,9 @@ public class ZipSigner {
try (InputStream pub = new FileInputStream(pubKey);
InputStream priv = new FileInputStream(privKey);
JarMap jar = new JarMap(input, false)) {
SignAPK.signZip(pub, priv, jar, output, minSign);
JarMap jar = new JarMap(input, false);
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(output))) {
SignAPK.signZip(pub, priv, jar, out, minSign);
} catch (Exception e) {
e.printStackTrace();
System.exit(1);