Pessoal,
Estou usando essa classe para criptografar e descriptografar alguns dados:
public class Encrypter {
private static final String METODO_ENCRIPTACAO = "AES";
public static final byte[] CHAVE = {71, -75, -63, 101, -21, 64, -12, 50, -27, -44, 13, -87, 49, -58, -44, -4, -4, -69, -7, 113, -68, 28, 74, -114, 89, -104, 103, -106, -67, 21, -103, -107};
public static String encriptar(byte[] key, String value)
throws SegurancaException {
try {
SecretKeySpec skeySpec = new SecretKeySpec(key, METODO_ENCRIPTACAO);
Cipher cipher = Cipher.getInstance(METODO_ENCRIPTACAO);
cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
byte[] encrypted = cipher.doFinal(value.getBytes());
return new BASE64Encoder().encode(encrypted);
}
catch (Exception e) {
throw new SegurancaException("Erro ao criptografar informações " + e.getMessage());
}
}
public static String decriptar(byte[] key, String encrypted)
throws SegurancaException {
byte[] decrypted = null;
try {
SecretKeySpec skeySpec = new SecretKeySpec(key, METODO_ENCRIPTACAO);
byte[] decoded = new BASE64Decoder().decodeBuffer(encrypted);
Cipher cipher = Cipher.getInstance(METODO_ENCRIPTACAO);
cipher.init(Cipher.DECRYPT_MODE, skeySpec);
decrypted = cipher.doFinal(decoded);
}
catch (Exception e) {
throw new SegurancaException("Erro ao descriptografar informações " + e.getMessage());
}
return new String(decrypted);
}
}
E usando essa para o teste:
public class MainClass {
public static void main(String[] args) {
try {
String value = Encrypter.encriptar(Encrypter.CHAVE, "robson");
System.out.println(value);
value = Encrypter.decriptar(Encrypter.CHAVE, value);
System.out.println(value);
}catch (Exception e) {
e.printStackTrace();
}
}
}
Só que está dando o seguinte erro:
[color=red] Erro ao criptografar informações Illegal key size or default parameters[/color]
Alguém pode me ajudar?