Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Commit

Permalink
Merge "Signapk.java: hide the password"
Browse files Browse the repository at this point in the history
  • Loading branch information
Ying Wang authored and Gerrit Code Review committed Mar 11, 2015
2 parents 168357a + 22717f9 commit fafe5ac
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions tools/signapk/SignApk.java
Expand Up @@ -35,6 +35,7 @@
import org.bouncycastle.operator.jcajce.JcaDigestCalculatorProviderBuilder;
import org.bouncycastle.util.encoders.Base64;

import java.io.Console;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
Expand Down Expand Up @@ -166,18 +167,17 @@ private static X509Certificate readPublicKey(File file)
}

/**
* Reads the password from stdin and returns it as a string.
* Reads the password from console and returns it as a string.
*
* @param keyFile The file containing the private key. Used to prompt the user.
*/
private static String readPassword(File keyFile) {
// TODO: use Console.readPassword() when it's available.
System.out.print("Enter password for " + keyFile + " (password will not be hidden): ");
System.out.flush();
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
try {
return stdin.readLine();
} catch (IOException ex) {
Console console;
char[] pwd;
if((console = System.console()) != null &&
(pwd = console.readPassword("[%s]", "Enter password for " + keyFile)) != null){
return String.valueOf(pwd);
} else {
return null;
}
}
Expand Down

0 comments on commit fafe5ac

Please sign in to comment.