I have Stored the key in the database and fetching the key for encryption, I get exception
Exception
java.security.InvalidKeyException: Unsupported key Note: Key is not in encrypted format.
Fetched Key from DB de.flexiprovider.core.rijndael.RijndaelKey@c4ef71c9
invalid Key javax.crypto.spec.SecretKeySpec@97d5a10e // we can see here key is changed
Program
StringBuffer sbselect1=new StringBuffer();
sbselect1.append("SELECT Keyforkey FROM ");
sbselect1.append(UserConstants.USER_DETAILS_TABLE_NAME2);
sbselect1.append(" where ID=2");
ps1=conn.prepareStatement(sbselect1.toString());
ResultSet rs =ps1.executeQuery();
rs.next();
String keyskey = rs.getString("KeyforKey");
System.out.println("Fetched Key from DB "+keyskey);
Security.addProvider(new FlexiCoreProvider());
Cipher cipher2 = Cipher.getInstance("AES128_CBC", "FlexiCore");
// byte[] encodedKey =keyskey.getBytes();
SecretKey key2 = new SecretKeySpec(keyskey.getBytes(), 0, keyskey.length(), "AES");
System.out.println("invalid Key "+ key2);
rs.close();
I have gone wrong at this piece of code
SecretKey key2 = new SecretKeySpec(keyskey.getBytes(), 0, keyskey.length(), "AES");
And also at byte[] encodedKey =keyskey.getBytes();output is [B@117e4ff
Please help me to troubleshoot the problem.