개인 키을 der 파일로 읽으려고합니다. 내 logcat에 다음과 같은 오류가 발생합니다. 그리고 반환 값은 비어 있습니다.안드로이드 - InvalidKeySpecException - 자바 런타임 예외 SSLInternal : TOO_LONG .der 파일을 읽을 때
java.security.spec.InvalidKeySpecException : java.lang.RuntimeException가 : 오류 : 0c0000af : ASN.1 인코딩 루틴 : OPENSSL_internal : TOO_LONG
나는이 이미 발생했지만 찾을 수있는 상황에 대한 검색 시도 없음. 이 오류의 의미와 해결 방법을 알고 싶습니다. 여기
내 코드입니다 :public static String decryptionWithFile(String encrypted,String privateFile2)throws Exception {
PrivateKey privateKey = getPrivateKey(privateFile2);
Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
cipher.init(Cipher.DECRYPT_MODE, privateKey);
byte[] bts = Hex.decodeHex(encrypted.toCharArray());
bts = cipher.doFinal(bts);
bts = getFinalBytesOfDycryptedString(bts);
String decryptedMessage = new String(cipher.doFinal(encrypted.getBytes()));
return new String(bts,"UTF-8");
}
그리고 여기 getPrivateKey이다(); 방법 :
private static PrivateKey getPrivateKey(String privateFile2)throws Exception {
File f = new File(privateFile2);
FileInputStream fis = new FileInputStream(f);
DataInputStream dis = new DataInputStream(fis);
byte[] keyBytes = new byte[(int) f.length()];
dis.readFully(keyBytes);
dis.close();
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(keyBytes);
RSAPrivateKey privKey = (RSAPrivateKey) keyFactory.generatePrivate(spec);
return privKey;
}
중요 참고 : 내 자산 폴더에 .der과 파일을 추가 한 후 경로에 액세스하기 위해 내부 저장에 파일로 저장 - 내 기능이 필요합니다. 이 과정에서 파일에 어떤 일이 일어 났을 것 같습니까? (공개 키를 사용하면 문제가 없습니다.)
파일에서 개인 키를 올바르게 가져오고 있습니까? 로그에 인쇄하여 확인 했습니까 ?? –