AES SecretKeyFactory not available
967785Oct 11 2012 — edited Oct 12 2012Hi,
I found that there is a bug in using SecretKeyFactory keyFactory with reference to http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7022467
I tried implementing with KeySpec too,but found one or the other error.
I'm posting here my code.Please help me out to decrypt.
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.SecretKeySpec;
import org.apache.commons.codec.binary.Hex;
public class DecryptTest {
public static void main(String[] args) throws Exception {
String keyStr = "6a6b663472346c38736873346569727538346234333534376635333962353666";
String eid = "bf940165bcc3bca12321a5cc4c753220129337b48ad129d880f718d147a2cd1bfa79de92239ef1bc06c2f05886b0cd5d";
String rid = "00028e7353d9c4eca480a57a1ca9ba9b";
int keysize = 256;
// decode the key string into bytes (using Apache Commons)
byte[] keyBytes = Hex.decodeHex(keyStr.toCharArray());
// create a representation of the key
SecretKeySpec spec = new SecretKeySpec(keyBytes, "AES");
// turn the key spec into a usable key
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("AES");
SecretKey key = keyFactory.generateSecret(spec);
// use a cipher to decrypt the eid
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.DECRYPT_MODE, key);
byte[] plainText = cipher.doFinal(Hex.decodeHex(eid.toCharArray())); // decode from Hex again
String Eid = new String(plainText, "ASCII");
System.out.println(Eid);
}
}