Skip to content

Commit

Permalink
Better message on incorrect key password
Browse files Browse the repository at this point in the history
  • Loading branch information
fornwall committed Oct 6, 2016
1 parent a8dcf53 commit 8ac8ce1
Showing 1 changed file with 8 additions and 18 deletions.
26 changes: 8 additions & 18 deletions src/net/fornwall/apksigner/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.File;
import java.security.KeyStore;
import java.security.PrivateKey;
import java.security.UnrecoverableKeyException;
import java.security.cert.X509Certificate;
import java.util.List;

Expand All @@ -29,10 +30,6 @@ public static void main(String... args) throws Exception {
Option helpOption = new Option("h", "help", false, "Display usage information.");
options.addOption(helpOption);

// Option storePasswordOption = new Option("s", "storepass", false, "password for keystore integrity");
// storePasswordOption.setArgs(1);
// options.addOption(storePasswordOption);

Option keyPasswordOption = new Option("p", "password", false, "Password for private key (default:android).");
keyPasswordOption.setArgs(1);
options.addOption(keyPasswordOption);
Expand All @@ -58,18 +55,6 @@ public static void main(String... args) throws Exception {
String inputFile = argList.get(1);
String outputFile = argList.get(2);

// char[] storePassword;
// if (cmdLine.hasOption(storePasswordOption.getOpt())) {
// String optionValue = cmdLine.getOptionValue(storePasswordOption.getOpt());
// if (optionValue == null || optionValue.equals("")) {
// storePassword = null;
// } else {
// storePassword = optionValue.toCharArray();
// }
// } else {
// storePassword = null;
// }

char[] keyPassword;
if (cmdLine.hasOption(keyPasswordOption.getOpt())) {
String optionValue = cmdLine.getOptionValue(keyPasswordOption.getOpt());
Expand Down Expand Up @@ -99,8 +84,13 @@ public static void main(String... args) throws Exception {
String alias = keyStore.aliases().nextElement();

X509Certificate publicKey = (X509Certificate) keyStore.getCertificate(alias);
PrivateKey privateKey = (PrivateKey) keyStore.getKey(alias, keyPassword);
ZipSigner.signZip(publicKey, privateKey, "SHA1withRSA", inputFile, outputFile);
try {
PrivateKey privateKey = (PrivateKey) keyStore.getKey(alias, keyPassword);
ZipSigner.signZip(publicKey, privateKey, "SHA1withRSA", inputFile, outputFile);
} catch (UnrecoverableKeyException e) {
System.err.println("apksigner: Invalid key password.");
System.exit(1);
}
}

}

0 comments on commit 8ac8ce1

Please sign in to comment.