
I have this code in my scriptlet, when I use the Encryption code to encrypt my data it executes successfully, now when I get my encrypted data from my DB, specifically MSSQL.. I traced where the program stopped working and it stopped in the decryption part and I get this error.. "Given Final Block not properly padded".. can anyway help me here? Thanks in Advance.. Here's the code..
byte[] encryptKey = "This is a test DESede key".getBytes();
DESedeKeySpec spec = new DESedeKeySpec(encryptKey);
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DESede");
SecretKey theKey = keyFactory.generateSecret(spec);
Cipher cipher = Cipher.getInstance("DESede/CBC/PKCS5Padding");
IvParameterSpec ivParameters = new IvParameterSpec(new byte[] { 12, 34, 56, 78, 90, 87, 65, 43 } );
cipher.init(Cipher.DECRYPT_MODE, theKey, ivParameters);
System.out.println("Get Encrypted Data from db");
String fName = (String)session.getAttribute("first_name");
String lName = (String)session.getAttribute("last_name");
System.out.println("Convert Encrypted Data to Byte Format");
byte[] FirstName = new byte[(int)fName.length()];
byte[] LastName = new byte[(int)lName.length()];
// Decrypt the data
System.out.println("Decrypt Byte Converted Data");
byte[] DecryptedFirstName = cipher.doFinal(FirstName);
byte[] DecryptedLastName = cipher.doFinal(LastName);
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.