|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnl.nikhef.slcshttps.crypto.CryptoStore
public class CryptoStore
This class is a holder for the different cryptographic objects: keypair
(PrivateKey
/PublicKey
), certificate signing request
(CSR
) and a KeyStore
containg the signed X509Certificate
.
The private key cannot be obtained directly, only indirectly by getting a
KeyManager
for the certificate. The keypair is created at
construction time, or imported when using
importPKCS12(KeyStore,char[])
.
Field Summary | |
---|---|
private static String |
CERT_ALIAS
default alias for entry in keyStore containing the privatekey
and certificate. |
private CSR |
csr
Contains the CSR, initialized using CSRinit() or CSRinit(String) , can be obtained using getCSR() . |
protected static int |
KEYLENGTH
default keylength is 1024. |
private KeyStore |
keyStore
Keystore containing the signed X509Certificate and corresponding
PrivateKey . |
private char[] |
password
Password for entry in keyStore , initialized in constructor to a
random value. |
private static int |
PASSWORD_LENGTH
default length for keystore-entry random password is 16. |
private PrivateKey |
privateKey
Contains private key, will be initialized in constructor. |
private PublicKey |
publicKey
Contains public key, will be initialized in constructor. |
Constructor Summary | |
---|---|
CryptoStore()
Constructs a new CryptoStore , using a default RSA keylength
1024. |
|
CryptoStore(int keyLen)
Constructs a new CryptoStore , using a RSA keylength
keyLen . |
Method Summary | |
---|---|
void |
CSRinit()
Initializes a new certificate signing request ( CSR ) with a default DN. |
void |
CSRinit(String DN)
Initializes a new certificate signing Request ( CSR ) for the given
DN. |
void |
deleteCertificate()
Removes the entry in the internal KeyStore which was stored with
the default alias CERT_ALIAS . |
void |
deleteCertificate(String alias)
Removes the entry in the internal KeyStore which was stored with
the given alias. |
X509Certificate |
getCertificate()
Returns the X509Certificate which was stored using the default
CERT_ALIAS alias, if this alias is for a KeyEntry (which comes with a certificate
chain), the first certificate in the chain is returned. |
X509Certificate |
getCertificate(String alias)
Returns the X509Certificate which was stored with given
alias, if this alias is for a KeyEntry (which comes with a certificate chain), the first certificate
in the chain is returned. |
CSR |
getCSR()
Returns the current CSR . |
(package private) KeyManager[] |
getKeyManagers()
Returns a KeyManager [] array which can be used for, for example,
setting up SSL connections. |
private char[] |
getPassword(int length)
Creates a random password of length length from the set
[a-zA-Z0-9]. |
X509Certificate |
importPKCS12(KeyStore pkcs12Store,
char[] password)
Imports a X509Certificate and keypair from an existing PKCS12
KeyStore protected with password . |
void |
storeCertificate(X509Certificate x509Cert)
Stores X509Certificate x509Cert in the internal
keyStore , using the constant alias CERT_ALIAS and
random password password . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private PrivateKey privateKey
private PublicKey publicKey
private CSR csr
CSRinit()
or CSRinit(String)
, can be obtained using getCSR()
.
private KeyStore keyStore
X509Certificate
and corresponding
PrivateKey
.
private char[] password
keyStore
, initialized in constructor to a
random value.
private static final String CERT_ALIAS
keyStore
containing the privatekey
and certificate.
private static final int PASSWORD_LENGTH
password
is 16.
protected static final int KEYLENGTH
Constructor Detail |
---|
public CryptoStore(int keyLen) throws NoSuchProviderException, KeyStoreException
CryptoStore
, using a RSA keylength
keyLen
. This initializes the BouncyCastleProvider
if
necessary, creates the keypair, initializes the internal PKCS12 KeyStore
and creates the random password
with length PASSWORD_LENGTH
=16.
keyLen
- the key length used for the keypair
NoSuchProviderException
- if adding the BouncyCastleProvider
fails.
KeyStoreException
- for other errors relating to key creation.CryptoStore()
public CryptoStore() throws NoSuchProviderException, KeyStoreException
CryptoStore
, using a default RSA keylength
1024. This initializes the BouncyCastleProvider
if
necessary, creates the keypair, initializes the internal PKCS12 KeyStore
and creates the random password
with length 16.
NoSuchProviderException
- if adding the BouncyCastleProvider
fails.
KeyStoreException
- for other errors relating to key creation.CryptoStore(int)
Method Detail |
---|
public void CSRinit(String DN) throws SignatureException
CSR
) for the given
DN.
DN
- String
describing the DN to use in the
CSR
.
SignatureException
- upon error.CSR.CSR(String,PublicKey,PrivateKey)
public void CSRinit() throws SignatureException
CSR
) with a default DN.
SignatureException
CSRinit(String)
,
CSR.CSR(PublicKey,PrivateKey)
public CSR getCSR()
CSR
.
public void storeCertificate(X509Certificate x509Cert) throws KeyStoreException
X509Certificate
x509Cert
in the internal
keyStore
, using the constant alias CERT_ALIAS
and
random password password
.
x509Cert
- the certificate to be stored.
KeyStoreException
- upon error.public X509Certificate importPKCS12(KeyStore pkcs12Store, char[] password) throws CertificateException, KeyStoreException
X509Certificate
and keypair from an existing PKCS12
KeyStore
protected with password
.
Only the first entry in the KeyStore
will be used and this
should be a KeyEntry with the certificate and private key. The public key
is derived from the certificate itself. The password should be the same
for keystore and entry inside it.
pkcs12Store
- PKCS12 KeyStore
.password
- PKCS12 KeyStore
password, also password for
getting the private key
KeyStore
.
KeyStoreException
- in case the KeyStore
could not be read,
is not PKCS12, is empty etc.
CertificateException
- in case the certificate/key cannot be
retrieved from the KeyStore
, if there is no key etc.KeyStore.isKeyEntry(String)
public X509Certificate getCertificate(String alias) throws KeyStoreException
X509Certificate
which was stored with given
alias, if this alias is for a KeyEntry
(which comes with a certificate chain), the first certificate
in the chain is returned.
alias
- alias for the KeyStore
entry
KeyStoreException
KeyStore.getCertificate(java.lang.String)
public X509Certificate getCertificate() throws KeyStoreException
X509Certificate
which was stored using the default
CERT_ALIAS
alias, if this alias is for a KeyEntry
(which comes with a certificate
chain), the first certificate in the chain is returned.
CERT_ALIAS
.
KeyStoreException
getCertificate(String)
public void deleteCertificate(String alias) throws KeyStoreException
KeyStore
which was stored with
the given alias.
alias
- alias for the KeyStore
entry
KeyStoreException
public void deleteCertificate() throws KeyStoreException
KeyStore
which was stored with
the default alias CERT_ALIAS
.
KeyStoreException
deleteCertificate(String)
KeyManager[] getKeyManagers() throws KeyStoreException
KeyManager
[] array which can be used for, for example,
setting up SSL connections. Note that a KeyManager
gives
public access to its private key, hence this method is package private.
KeyStoreException
- in case of errorprivate char[] getPassword(int length) throws KeyStoreException
length
from the set
[a-zA-Z0-9].
length
- length of password.
KeyStoreException
- upon error
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
nl.nikhef.slcshttps | Mischa Sallé - msalle(AT)nikhef.nl |