나는 javax.crypto를 사용하여 메시지를 암호화하고 해독하는 정적 메서드로 클래스를 수행하고 있습니다. 나는 ecipher와 dcipher를 사용하여 supossed를 수행하기 위해 정적 변수 인 일부 변수를 초기화해야하는 2 가지 정적 메소드를 가지고있다. 하지만 내가 그것을 사용하려고하면 매개 변수와 함께 InvalidKeyException을 얻는다. ecipher.init (...). 이유를 찾을 수 없습니다.Java : 암호 패키지 (암호화 및 암호 해독). 잘못된 키 오류
private static byte[] raw = {-31, 17, 7, -34, 59, -61, -60, -16,
26, 87, -35, 114, 0, -53, 99, -116,
-82, -122, 68, 47, -3, -17, -21, -82,
-50, 126, 119, -106, -119, -5, 109, 98};
private static SecretKeySpec skeySpec;
private static Cipher ecipher;
private static Cipher dcipher;
static {
try {
skeySpec = new SecretKeySpec(raw, "AES");
// Instantiate the cipher
ecipher = Cipher.getInstance("AES");
dcipher = Cipher.getInstance("AES");
ecipher.init(Cipher.ENCRYPT_MODE, skeySpec);
dcipher.init(Cipher.DECRYPT_MODE, skeySpec);
} catch (NoSuchAlgorithmException e) {
throw new UnhandledException("No existe el algoritmo deseado", e);
} catch (NoSuchPaddingException e) {
throw new UnhandledException("No existe el padding deseado", e);
} catch (InvalidKeyException e) {
throw new UnhandledException("Clave invalida", e);
}
}
스택 추적을 게시하십시오. –
Unlimited Jurisdiction Crypto Policy 파일을 설치 했습니까? –