summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSimon Rettberg2014-10-14 18:37:37 +0200
committerSimon Rettberg2014-10-14 18:37:37 +0200
commit0e1584ef7ba54283e8dee6cd39ca78cdd81dcb1b (patch)
tree91e5b8ba445c92a8b29a937bed8f8a6786e7d586 /src
parentStarted implementing parsing command line arguments. (diff)
downloadsatellite-daemon-0e1584ef7ba54283e8dee6cd39ca78cdd81dcb1b.tar.gz
satellite-daemon-0e1584ef7ba54283e8dee6cd39ca78cdd81dcb1b.tar.xz
satellite-daemon-0e1584ef7ba54283e8dee6cd39ca78cdd81dcb1b.zip
Move AsymKeyHolder to master-sync-shared
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/openslx/satellitedaemon/AsymKeyHolder.java106
1 files changed, 0 insertions, 106 deletions
diff --git a/src/main/java/org/openslx/satellitedaemon/AsymKeyHolder.java b/src/main/java/org/openslx/satellitedaemon/AsymKeyHolder.java
deleted file mode 100644
index d6ee625..0000000
--- a/src/main/java/org/openslx/satellitedaemon/AsymKeyHolder.java
+++ /dev/null
@@ -1,106 +0,0 @@
-package org.openslx.satellitedaemon;
-
-import java.math.BigInteger;
-import java.security.KeyFactory;
-import java.security.KeyPair;
-import java.security.KeyPairGenerator;
-import java.security.NoSuchAlgorithmException;
-import java.security.PrivateKey;
-import java.security.PublicKey;
-import java.security.interfaces.RSAPrivateKey;
-import java.security.interfaces.RSAPublicKey;
-import java.security.spec.InvalidKeySpecException;
-import java.security.spec.RSAPrivateKeySpec;
-import java.security.spec.RSAPublicKeySpec;
-
-import org.apache.log4j.Logger;
-
-public class AsymKeyHolder
-{
- private static final Logger LOG = Logger.getLogger( AsymKeyHolder.class );
-
- private static RSAPrivateKey privKey = null;
- private static RSAPublicKey pubKey = null;
-
- public AsymKeyHolder( BigInteger privExp, BigInteger pubExp, BigInteger mod )
- throws NoSuchAlgorithmException, InvalidKeySpecException
- {
- if ( mod == null )
- throw new InvalidKeySpecException( "No modulus given!" );
- final KeyFactory keyFact;
- keyFact = KeyFactory.getInstance( "RSA" );
- if ( pubExp != null ) {
- RSAPublicKeySpec keySpec = new RSAPublicKeySpec( mod, pubExp );
- pubKey = (RSAPublicKey)keyFact.generatePublic( keySpec );
- }
- if ( privExp != null ) {
- RSAPrivateKeySpec keySpec = new RSAPrivateKeySpec( mod, privExp );
- privKey = (RSAPrivateKey)keyFact.generatePrivate( keySpec );
- }
- }
-
- public AsymKeyHolder()
- {
- generateKey();
- }
-
- /**
- * Get private key.
- *
- * @return
- */
- public PrivateKey getPrivateKey()
- {
- return privKey;
- }
-
- public PublicKey getPublicKey()
- {
- return pubKey;
- }
-
- private boolean generateKey()
- {
- KeyPairGenerator kpg;
- try {
- kpg = KeyPairGenerator.getInstance( "RSA" );
- } catch ( NoSuchAlgorithmException e ) {
- LOG.error( "NoSuchAlgorithmException", e );
- return false;
- }
-
- kpg.initialize( 4096 );
- KeyPair kp = kpg.generateKeyPair();
- privKey = (RSAPrivateKey)kp.getPrivate();
- pubKey = (RSAPublicKey)kp.getPublic();
-
- BigInteger pubMod = pubKey.getModulus();
- BigInteger privMod = privKey.getModulus();
- assert ( pubMod.equals( privMod ) );
- return true;
- }
-
- public BigInteger getModulus()
- {
- if ( privKey != null )
- return privKey.getModulus();
- if ( pubKey != null )
- return pubKey.getModulus();
- return null; // Should never happen
- }
-
- public BigInteger getPrivateExponent()
- {
- if ( privKey == null )
- return null;
- return privKey.getPrivateExponent();
- }
-
- public BigInteger getPublicExponent()
- {
- if ( pubKey == null )
- return null;
- return pubKey.getPublicExponent();
- }
-
-}