I'm having some trouble decrypting strings. The error I am recieving is:
"javax.crypto.IllegalBlockSizeException: Input length must be multiple of 16 when decrypting with padded cipher"
Here is what I am trying to achieve.
-The user sets a password when creating an account. In this case Taylor.
-This password manager class will translate this string into Gibberish (This is what it produces : "I^ÇÔµoü|& ÄŠóÁ").
-Im then storing this gibberish in a text file.
-From there when the password Taylor is entered this stored gibberish gets decrypted and then compared to the string entered. if its correct the user can access the application.
Thank you for helping.
As a side note i'm not sure if I've initialized the key correctly either :/ This is also my first time playing around with encryption. Im not sure if its really really cool or really really frustrating.
public static void Decrypt(String encryptedText) {
try
{
//we are using the same key to decrypt the string as we used to encrypt it.
String key = "AbCd1234aBcD4321";
// Here we are taking the 128 bit key we just created and expanding it
Key aesKey = new SecretKeySpec(key.getBytes(), "AES");
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.DECRYPT_MODE, aesKey);
//decrypt the text
byte[] encrypted = cipher.doFinal(encryptedText.getBytes());
String decrypted = new String(cipher.doFinal(encrypted));
System.out.println(decrypted);
}
catch(Exception e)
{
e.printStackTrace();
}