Package alpine.crypto
Class KeyManager
- java.lang.Object
-
- alpine.crypto.KeyManager
-
public final class KeyManager extends Object
Class that manages Alpine-generated default private, public, and secret keys.- Since:
- 1.0.0
- Author:
- Steve Springett
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Objectclone()KeyPairgenerateKeyPair()Generates a key pair.SecretKeygenerateSecretKey()Generates a secret key.static KeyManagergetInstance()Returns an INSTANCE of the KeyManager.KeyPairgetKeyPair()Returns the keypair.PrivateKeygetPrivateKey()Returns only the private key.PublicKeygetPublicKey()Returns only the public key.SecretKeygetSecretKey()Returns the secret key.booleankeyPairExists()Checks to see if the key pair exists.voidsave(KeyPair keyPair)Saves a key pair.voidsave(SecretKey key)Saves a secret key.booleansecretKeyExists()Checks to see if the secret key exists.
-
-
-
Method Detail
-
getInstance
public static KeyManager getInstance()
Returns an INSTANCE of the KeyManager.- Returns:
- an instance of the KeyManager
- Since:
- 1.0.0
-
generateKeyPair
public KeyPair generateKeyPair() throws NoSuchAlgorithmException
Generates a key pair.- Returns:
- a KeyPair (public / private keys)
- Throws:
NoSuchAlgorithmException- if the algorithm cannot be found- Since:
- 1.0.0
-
generateSecretKey
public SecretKey generateSecretKey() throws NoSuchAlgorithmException
Generates a secret key.- Returns:
- a SecretKey
- Throws:
NoSuchAlgorithmException- if the algorithm cannot be found- Since:
- 1.0.0
-
save
public void save(KeyPair keyPair) throws IOException
Saves a key pair.- Parameters:
keyPair- the key pair to save- Throws:
IOException- if the files cannot be written- Since:
- 1.0.0
-
save
public void save(SecretKey key) throws IOException
Saves a secret key.- Parameters:
key- the SecretKey to save- Throws:
IOException- if the file cannot be written- Since:
- 1.0.0
-
keyPairExists
public boolean keyPairExists()
Checks to see if the key pair exists. Both (public and private) need to exist to return true.- Returns:
- true if keypair exists, false if not
- Since:
- 1.0.0
-
secretKeyExists
public boolean secretKeyExists()
Checks to see if the secret key exists.- Returns:
- true if secret key exists, false if not
- Since:
- 1.0.0
-
getKeyPair
public KeyPair getKeyPair()
Returns the keypair.- Returns:
- the KeyPair
- Since:
- 1.0.0
-
getPublicKey
public PublicKey getPublicKey()
Returns only the public key.- Returns:
- the PublicKey
- Since:
- 1.0.0
-
getPrivateKey
public PrivateKey getPrivateKey()
Returns only the private key.- Returns:
- the PrivateKey
- Since:
- 1.0.0
-
getSecretKey
public SecretKey getSecretKey()
Returns the secret key.- Returns:
- the SecretKey
- Since:
- 1.0.0
-
clone
public Object clone() throws CloneNotSupportedException
- Overrides:
clonein classObject- Throws:
CloneNotSupportedException
-
-