Reputation: 131
I would like to create a installer for a Java app, and have found some great apps that do it. The problem is I am using Jasypt to encrypt a password used in the properties file. Currently the user has to use the Jasypt command line to encrypt their password, then enter the encrypted password in the properties file. They then have to include the encryption key in the Java which ,means editing and re-compiling. Obviously there is an easier way to do this. I would ultimately like to have an installer that asks for the password, encrypts it, stores the key, and then installs the app. I am not a Java programmer :( more of a hacker. :) Thanks!
Upvotes: 0
Views: 217
Reputation: 34367
Use Cipher
classes to encrypt/decrypt the password.
Before saving the file, use ENCRYPT_MODE
to encrypt:
String passwordToEncrypt = ....//user entered
byte[] passwordToEncryptBytes = passwordToEncrypt.getBytes();
KeyGenerator keyGen = KeyGenerator.getInstance("AES");
SecretKey mySecretKey = keyGen.generateKey();
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, mySecretKey);
IvParameterSpec ivParameter =
cipher.getParameters().getParameterSpec(IvParameterSpec.class);
byte[] encryptedPasswordData = cipher.doFinal(passwordToEncryptBytes);
Use the encryptedPasswordData
to encrypt the file.
While opening the file, prompt the password, encrypt again and try to open the file. If right password, it should go through.
Upvotes: 1