diff options
-rw-r--r-- | src/main/java/org/openslx/satellitedaemon/Identity.java | 36 |
1 files changed, 22 insertions, 14 deletions
diff --git a/src/main/java/org/openslx/satellitedaemon/Identity.java b/src/main/java/org/openslx/satellitedaemon/Identity.java index b8ed1ee..ae28def 100644 --- a/src/main/java/org/openslx/satellitedaemon/Identity.java +++ b/src/main/java/org/openslx/satellitedaemon/Identity.java @@ -22,6 +22,8 @@ public class Identity private static BigInteger mod = null; private static BigInteger privExp = null; private static BigInteger pubExp = null; + + private static AsymKeyHolder akh = null; public static String getOrganizationName() { @@ -65,6 +67,13 @@ public class Identity } Util.notNullOrEmptyFatal( getOrganizationName(), "Organiziation Name must not be empty!" ); + try { + akh = new AsymKeyHolder( privExp, pubExp, mod ); + } catch ( InvalidKeySpecException e ) { + log.error( "InvalidKeySpecException", e); + } catch ( NoSuchAlgorithmException e ) { + log.error( "NoSuchAlgorithmException", e ); + } } /** @@ -74,16 +83,16 @@ public class Identity */ public static PrivateKey getPrivateKey() { - AsymKeyHolder akh; - try { - akh = new AsymKeyHolder( privExp, null, mod ); + if (akh != null) { return akh.getPrivateKey(); - } catch ( InvalidKeySpecException e ) { - log.error( "InvalidKeySpecException", e ); + } + try { + akh = new AsymKeyHolder(); } catch ( NoSuchAlgorithmException e ) { log.error( "NoSuchAlgorithmException", e ); + return null; } - return null; + return akh.getPrivateKey(); } /** @@ -93,15 +102,14 @@ public class Identity */ public static PublicKey getPublicKey() { - AsymKeyHolder akh; - try { - akh = new AsymKeyHolder( null, pubExp, mod ); + if (akh != null) return akh.getPublicKey(); - } catch ( InvalidKeySpecException e ) { - log.error( "InvalidKeySpecException", e ); - } catch ( NoSuchAlgorithmException e ) { - log.error( "NoSuchAlgorithmException", e ); + try { + akh = new AsymKeyHolder(); + } catch ( NoSuchAlgorithmException e) { + log.error("NoSuchAlgorithmException", e); + return null; } - return null; + return akh.getPublicKey(); } } |