올바른 암호로 작업중인 문자열의 암호를 해독하고 싶습니다. 나는 if(decrypt(Password, encryptedKey).contains(Key)){
과 암호를 확인하려하지만 PW가 잘못되면 나는 다음과 같은 예외를 얻을 :암호 해독 전에 암호 확인
javax.crypto.BadPaddingException: pad block corrupted
그래서 암호를 확인하는 또 다른 방법은 무엇입니까?
public static String decrypt(String seed, String encrypted) throws Exception {
byte[] rawKey = getRawKey(seed.getBytes());
byte[] enc = toByte(encrypted);
SecretKeySpec Spec = new SecretKeySpec(rawKey, "AES");
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.DECRYPT_MODE, Spec);
byte[] result = cipher.doFinal(enc);
return new String(result);
}
잘못된 암호를 사용하여 암호를 해독하지 않고 예외를 throw하지 않지만 올바른 암호를 사용하여 암호를 해독하는 경우 문제가 생깁니 까? 실제로 암호를 해독하는 것보다 암호를 확인하는 "쉬운"방법은 없습니다 (또는 * 적어도 * 사용하지 않아야 함). – Piskvor
당신은 시도하고 잡을 사용해야한다는 뜻 ?? – Droider