diff options
author | zhang jun <jun.zhang@intel.com> | 2014-07-10 16:34:57 +0800 |
---|---|---|
committer | Mingwei Shi <mingwei.shi@intel.com> | 2014-07-17 18:13:51 +0800 |
commit | 22717f9f9ee764e8126bcbc8c4cd9dc58b713fee (patch) | |
tree | caf4cbb2643a1832673781cb8574a7168709ac0d /tools/signapk | |
parent | 979d578ee40c0a7d3e25915049350a23165f7a5a (diff) | |
download | build-22717f9f9ee764e8126bcbc8c4cd9dc58b713fee.zip build-22717f9f9ee764e8126bcbc8c4cd9dc58b713fee.tar.gz build-22717f9f9ee764e8126bcbc8c4cd9dc58b713fee.tar.bz2 |
Signapk.java: hide the password
Reads the password through console instead of stdin directly and returns it as a string.
Change-Id: I52e525680b93e9729158f4902b22f985245dbf2f
Signed-off-by: zhang jun <jun.zhang@intel.com>
Signed-off-by: Mingwei Shi <mingwei.shi@intel.com>
Diffstat (limited to 'tools/signapk')
-rw-r--r-- | tools/signapk/SignApk.java | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/tools/signapk/SignApk.java b/tools/signapk/SignApk.java index e661e50..5ed3e10 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; } } |