aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/com/juick/KeystoreManager.java25
1 files changed, 8 insertions, 17 deletions
diff --git a/src/main/java/com/juick/KeystoreManager.java b/src/main/java/com/juick/KeystoreManager.java
index e6979a5c..5a2a98c1 100644
--- a/src/main/java/com/juick/KeystoreManager.java
+++ b/src/main/java/com/juick/KeystoreManager.java
@@ -22,6 +22,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.Resource;
import org.springframework.util.Base64Utils;
+import org.tomitribe.churchkey.Key;
+import org.tomitribe.churchkey.Keys;
import javax.net.ssl.KeyManagerFactory;
import java.io.IOException;
@@ -53,7 +55,7 @@ public class KeystoreManager {
}
private KeyPair getKeyPair() {
- Key privateKey;
+ java.security.Key privateKey;
try {
privateKey = ks.getKey("1", keystorePassword.toCharArray());
Certificate certificate = ks.getCertificate("1");
@@ -69,24 +71,13 @@ public class KeystoreManager {
public PublicKey getPublicKey() {
return getKeyPair().getPublic();
}
+
public String getPublicKeyPem() {
- String[] key = Base64Utils.encodeToString(getKeyPair().getPublic().getEncoded()).split("(?<=\\G.{64})");
- return String.format("-----BEGIN PUBLIC KEY-----\n%s\n-----END PUBLIC KEY-----\n",
- String.join("\n", key));
+ return new String(Keys.of(getPublicKey()).encode(Key.Format.PEM));
}
- public static PublicKey publicKeyOf(Actor person) {
+
+ public static java.security.Key publicKeyOf(Actor person) {
String pubkeyPem = person.getPublicKey().getPublicKeyPem();
- String[] rawKey = pubkeyPem.split("\\n");
- String pubkeyData = String.join("", Arrays.asList(rawKey).subList(1, rawKey.length - 1));
- try{
- byte[] byteKey = Base64Utils.decodeFromString(pubkeyData);
- X509EncodedKeySpec X509publicKey = new X509EncodedKeySpec(byteKey);
- KeyFactory kf = KeyFactory.getInstance("RSA");
- return kf.generatePublic(X509publicKey);
- }
- catch(Exception e){
- logger.error("Public key error", e);
- }
- return null;
+ return Keys.decode(pubkeyPem.getBytes()).getKey();
}
}