2013-12-13 2 views
0

나는 탄력성을 사용하여 해독하고 DataLengthException이 발생하는 것을 잡으려고합니다. 그러나 어떤 이유로 인해 JVM은 Exception을 DataLengthException으로 인식하지 못합니다. 다른 사람이이 문제를 겪었습니까?Bouncy Castle DataLengthException이 (가) catch되지 않았습니다.

코드 : 당신이 코멘트에서 볼 수 있듯이

for (int i = 0; i < transformations.length; i++) { 
    try { 
     cipher = Cipher.getInstance(transformations[i], "BC"); 
     cipher.init(Cipher.DECRYPT_MODE, certificate); 
     return cipher.doFinal(bytesTimestampEncrypted); 
    } 
    catch (ArrayIndexOutOfBoundsException e1) { 
     // try the next transformation 
    } 
    catch (BadPaddingException e1) { 
     // try the next transformation 
    } 
    catch (IllegalBlockSizeException e1) { 
     // try the next transformation 
    } 
    catch (NoSuchPaddingException e) { 
     // try the next transformation 
    } 
    catch (NoSuchAlgorithmException e) { 
     // try the next transformation 
    } 
    catch (InvalidKeyException e) { 
     // try the next transformation 
    } 
    catch (NoSuchProviderException e) { 
     // try the next transformation 
    } 
    catch (DataLengthException e) { 
     // This is the one I am trying to catch 
     Log.debug("Input too large for RSA cipher, trans=" + transformations[i], e); 
    } 
    catch (RuntimeException e) { 
     // This is the one that actually ends up catching it. 
     throw e; 
    } 
} 

예외 내가 테스트 이유로 단순히 추가 catch(RuntimeException)까지 잡았되지 않습니다. 예외를 디버깅하고 RuntimeException에 중단 점을 설정했습니다. 예외는 : org.bouncycastle.crypto.DataLengthException: input too large for RSA cipher 그러나, 내가 e instance of org.bouncastle.crypto.DataLengthException을 테스트 할 때 나는 틀리게된다.

여기에 어떤 아이디어라도 도움이 될 것입니다.

+1

제쳐두고, 여기서 뭔가 이상한 행동을하는 것처럼 보입니다. 실제 응용 프로그램을위한 것입니까, 아니면 Java 암호화를 사용하는 방법을 알아 내려고하고 있습니까? – erickson

답변

0

동일한 클래스 파일이 두 개의 다른 클래스 로더에 의해로드되는 경우 클래스 ID가 클래스 로더와 전체 클래스 이름에 의해 만들어지기 때문에 절대로 동일한 클래스로 간주되지 않습니다.

동일한 전체 이름을 가진 클래스의 개체가 테스트 인스턴스에 실패한다는 것을 알 수있는 유일한 방법입니다. 작업 공간/런타임에서 bouncycastle jars가 여러 개 있는지 확인하십시오.

+0

e.getClass.getName() = "org.bouncycastle.crypto.DataLengthException" –

+0

아니요. 나에게 여전히 DataLengthException처럼 보입니다. 다른 유형의 예외를 어떻게 알 수 있습니까? –

+0

e.getClass(). getClassLoader()를 시도하고 this.getClass(). getClassLoader()와 출력을 비교하여 클래스 로더가 동일한 지 확인하십시오. 두 개의 서로 다른 클래스 로더에 탄력이있는 두 개의 항아리가있을 수 있습니다. getClass(). getClassLoader(). getResources ("org/bouncycastle/crypto/DataLengthException.class")를 사용하여 두 개의 항목이 있고 해당 항아리의 위치를 ​​확인하십시오. –

관련 문제