summaryrefslogtreecommitdiffstats
path: root/tools/signapk
diff options
context:
space:
mode:
authorYing Wang <wangying@android.com>2015-03-11 16:45:59 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2015-03-11 16:46:00 +0000
commitfafe5ac81940caaa6b222433a2fd9ef5e1239686 (patch)
tree47d57d2a1b651d80ad16939524a37c2a2bab22cb /tools/signapk
parent168357aeda0c71cd54f9bcfe72f2fca2d3baad36 (diff)
parent22717f9f9ee764e8126bcbc8c4cd9dc58b713fee (diff)
downloadbuild-fafe5ac81940caaa6b222433a2fd9ef5e1239686.zip
build-fafe5ac81940caaa6b222433a2fd9ef5e1239686.tar.gz
build-fafe5ac81940caaa6b222433a2fd9ef5e1239686.tar.bz2
Merge "Signapk.java: hide the password"
Diffstat (limited to 'tools/signapk')
-rw-r--r--tools/signapk/SignApk.java16
1 files changed, 8 insertions, 8 deletions
diff --git a/tools/signapk/SignApk.java b/tools/signapk/SignApk.java
index d020736..88f486a 100644
--- a/tools/signapk/SignApk.java
+++ b/tools/signapk/SignApk.java
@@ -35,6 +35,7 @@ import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder;
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;
@@ -166,18 +167,17 @@ class SignApk {
}
/**
- * 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;
}
}