[그 외] public key, private key file로부터 가져오기
2024. 5. 3. 22:53ㆍ그 외
private PublicKey getPublicKey() {
File publicKeyFile = new File("src/main/resources/public.key");
PublicKey publicKey = null;
try {
byte[] publicKeyBytes = Files.readAllBytes(publicKeyFile.toPath());
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(publicKeyBytes);
publicKey = keyFactory.generatePublic(publicKeySpec);
} catch (IOException | InvalidKeySpecException | NoSuchAlgorithmException e) {
log.info("an error occured obtaining key");
log.info(e.getMessage());
}
return publicKey;
}
private PrivateKey getPrivateKey() {
File privateKeyFile = new File("src/main/resources/private.key");
PrivateKey privateKey = null;
try {
byte[] privateKeyBytes = Files.readAllBytes(privateKeyFile.toPath());
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
EncodedKeySpec privateKeySpec = new PKCS8EncodedKeySpec(privateKeyBytes);
privateKey = keyFactory.generatePrivate(privateKeySpec);
} catch (IOException | InvalidKeySpecException | NoSuchAlgorithmException e) {
log.info("an error occured obtaining key");
log.info(e.getMessage());
}
return privateKey;
}
'그 외' 카테고리의 다른 글
[그 외] 맥 M1 파워포인트 저장 오류 복구 방법 (1) | 2024.09.21 |
---|---|
[그 외] 2024-05-02 (0) | 2024.05.02 |
[그 외] 2024-04-25 (0) | 2024.04.25 |
[그 외] 이클립스에서 java EE 주의사항 (0) | 2024.03.19 |
[그 외] alias 설정할 때 주의해야할 점 (0) | 2024.02.11 |