From dbc76faa9ba6906f32b786c29a0c40a8efc0430f Mon Sep 17 00:00:00 2001 From: Björn Hagemeister Date: Thu, 9 Oct 2014 14:29:37 +0200 Subject: Create just one object of AsymKeyHolder for getting public and private Key. --- .../java/org/openslx/satellitedaemon/Identity.java | 36 +++++++++++++--------- 1 file changed, 22 insertions(+), 14 deletions(-) (limited to 'src') 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(); } } -- cgit v1.2.3-55-g7522