Skip to content

Commit

Permalink
Add encryption/decryption capabilities for Hibernate PW
Browse files Browse the repository at this point in the history
  • Loading branch information
GenieTim committed Mar 13, 2021
1 parent d605527 commit 7313131
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,12 @@
<artifactId>json</artifactId>
<version>20200518</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.jasypt/jasypt -->
<dependency>
<groupId>org.jasypt</groupId>
<artifactId>jasypt</artifactId>
<version>1.9.3</version>
</dependency>
<dependency>
<groupId>org.jxmapviewer</groupId>
<artifactId>jxmapviewer2</artifactId>
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/edu/harvard/mcz/imagecapture/EncryptPassword.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package edu.harvard.mcz.imagecapture;

import org.jasypt.util.text.AES256TextEncryptor;

import java.util.Scanner;

public class EncryptPassword {

/**
*
* @param args
*/
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Please enter the password you want to encrypt");
String passwordToEncrypt = in.nextLine();
System.out.println("Please enter the password for the encryption");
String encryptPassword = in.nextLine();
AES256TextEncryptor textEncryptor = new AES256TextEncryptor();
textEncryptor.setPassword(encryptPassword);
System.out.println(textEncryptor.encrypt(passwordToEncrypt));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import edu.harvard.mcz.imagecapture.Singleton;
import edu.harvard.mcz.imagecapture.utility.HashUtility;
import net.miginfocom.swing.MigLayout;
import org.jasypt.util.text.AES256TextEncryptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -38,6 +39,7 @@ public class LoginDialog extends JDialog {
public static final int RESULT_CANCEL = 0;
public static final int RESULT_LOGIN = 1;
private static final long serialVersionUID = -2016769537635603794L;
public static final String encryptPassword = "tmpPW-13.3.2021";
private static final Logger log = LoggerFactory.getLogger(LoginDialog.class);
private JDialog self = null;
private int result = RESULT_LOGIN;
Expand Down Expand Up @@ -282,7 +284,10 @@ public void setDBUserName(String aDBSchemaName) {
}

public String getDBPassword() {
return String.valueOf(jPasswordFieldDB.getPassword());
AES256TextEncryptor textEncryptor = new AES256TextEncryptor();
textEncryptor.setPassword(encryptPassword);
String passwordValue = String.valueOf(jPasswordFieldDB.getPassword());
return textEncryptor.decrypt(passwordValue);
}

public void setDBPassword(String aDBPassword) {
Expand Down

0 comments on commit 7313131

Please sign in to comment.