2014-02-20 2 views
0

다음 코드는 test.cer 파일 (X509 인증서)을 메모리에로드합니다. 현재 메모리에있을 때 필드를 수정할 수 있습니까? 예를 들어 load.getPublicKey()과 같은 필드를 쉽게 출력 할 수 있지만 공개 키의 첫 번째 바이트를 변경하고 변경 후 다시 출력하려고합니다. 내가 어떻게 그럴 수 있니?.cer 파일을 메모리에로드하고 수정하는 방법

File f= new File("Users/Desktop/JavaFolder/test.cer");  
CertificateFactory cf = CertificateFactory.getInstance("X.509"); 
BufferedInputStream in = new BufferedInputStream(new FileInputStream(f)); 
while (in.available() > 0) { 
    Certificate load = cf.generateCertificate(in); 
} 
in.close(); 
+3

인증서가 무엇인지 생각해 보면 이는 이상한 것 같습니다. 유스 케이스를 설명 할 수 있습니까? – Henry

+0

주요 사용 사례는 메모리에 업로드 한 후 인증서 내용을 수정하는 방법을 알고 공개 키 예제를 생각해 냈습니다. 나는 서명 확인과 비슷한 것을 보여줄 필요가 있기 때문에 이것을 알고 싶다. 인증서의 변경으로 인해 검증이 불리해질 때 – user3334067

+0

가능한 복제본 : http://stackoverflow.com/questions/21917034/modifying-x509- 인증서 – Henry

답변

0

당신이 가진 후 Certificate :

Certificate cert = .... 
PublicKey publicKey = cert.getPublicKey(); 
byte[] originalPublicKey = publicKey.getEncoded(); 
byte[] modifiedPublicKey = java.util.Arrays.copyOf(originalPublicKey , originalPublicKey .length);// make a copy 
modifiedPublicKey[0] = !modifiedPublicKey[0]; // modify something 
print(originalPublicKey); // your "print" method - implement it how you like it e.g., Arrays.toString(originalPublicKey) 
print(modifiedPublicKey); // your "print" method - implement it how you like it e.g., Arrays.toString(modifiedPublicKey) 

는 javadoc의 참조를 참조하십시오

관련 문제