totpgenerator

TOTP code generator
git clone git://git.wimdupont.com/totpgenerator.git
Log | Files | Refs | README | LICENSE

commit ad16e2414da96b66fac6d99d277c18031b5491e0
parent 5f30cd45174a868f2f146b43a247ce1227b6ccde
Author: WimDupont <WimDupont@users.noreply.gitlab.com>
Date:   Mon, 27 Dec 2021 19:07:51 +0100

package to runnable jar and hide pwd input if possible

Diffstat:
Mpom.xml | 39+++++++++++++++++++++++++++++++++++++++
Msrc/main/java/service/GpgUtil.java | 10+++++++++-
2 files changed, 48 insertions(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml @@ -32,4 +32,43 @@ <maven.compiler.target>17</maven.compiler.target> </properties> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-dependency-plugin</artifactId> + <executions> + <execution> + <id>copy-dependencies</id> + <phase>prepare-package</phase> + <goals> + <goal>copy-dependencies</goal> + </goals> + <configuration> + <outputDirectory>${project.build.directory}/lib</outputDirectory> + <overWriteReleases>false</overWriteReleases> + <overWriteSnapshots>false</overWriteSnapshots> + <overWriteIfNewer>true</overWriteIfNewer> + </configuration> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-jar-plugin</artifactId> + <configuration> + <archive> + <manifest> + <addClasspath>true</addClasspath> + <classpathPrefix>lib/</classpathPrefix> + <mainClass> + Main + </mainClass> + </manifest> + </archive> + </configuration> + </plugin> + </plugins> + </build> + </project> diff --git a/src/main/java/service/GpgUtil.java b/src/main/java/service/GpgUtil.java @@ -19,6 +19,7 @@ import org.bouncycastle.openpgp.operator.bc.BcPGPDigestCalculatorProvider; import org.bouncycastle.openpgp.operator.bc.BcPublicKeyDataDecryptorFactory; import java.io.ByteArrayOutputStream; +import java.io.Console; import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -64,7 +65,14 @@ public class GpgUtil { if (file.isEmpty()) throw new RuntimeException("File not found"); System.out.println("Type in GPG password."); - String pwd = scanner.nextLine(); + Console cons = System.console(); + String pwd; + if (cons != null) { + pwd = new String(cons.readPassword()); + } else { + System.out.println("Careful, input is not hidden"); + pwd = scanner.nextLine(); + } try { return Optional.ofNullable(decryptFile(new FileInputStream(file.get().getAbsolutePath()), pwd.toCharArray())); } catch (IOException | PGPException e) {