summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjörn Hagemeister2014-10-09 14:29:37 +0200
committerBjörn Hagemeister2014-10-09 14:29:37 +0200
commitdbc76faa9ba6906f32b786c29a0c40a8efc0430f (patch)
tree0bc429c5b056853190bc8ef533578fa6920121e0
parentSplitted Globals.java into two classes and splitted config file global.proper... (diff)
downloadsatellite-daemon-dbc76faa9ba6906f32b786c29a0c40a8efc0430f.tar.gz
satellite-daemon-dbc76faa9ba6906f32b786c29a0c40a8efc0430f.tar.xz
satellite-daemon-dbc76faa9ba6906f32b786c29a0c40a8efc0430f.zip
Create just one object of AsymKeyHolder for getting public and private Key.
-rw-r--r--src/main/java/org/openslx/satellitedaemon/Identity.java36
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();
}
}