Module io.github.mmm.crypto
Class AbstractAsymmetricKeyCreator<PR extends PrivateKey,PU extends PublicKey,PAIR extends AbstractAsymmetricKeyPair<PR,PU>>
- java.lang.Object
-
- io.github.mmm.crypto.algorithm.AbstractSecurityAlgorithm
-
- io.github.mmm.crypto.algorithm.AbstractCryptoAlgorithmWithProvider
-
- io.github.mmm.crypto.algorithm.CryptoAlgorithmImpl
-
- io.github.mmm.crypto.algorithm.CryptoAlgorithmImplWithRandom
-
- io.github.mmm.crypto.asymmetric.key.AbstractAsymmetricKeyCreator<PR,PU,PAIR>
-
- Type Parameters:
PR- type of wrappedPrivateKey.PU- type of wrappedPublicKey.PAIR- type ofAsymmetricKeyPair.
- All Implemented Interfaces:
CryptoAlgorithm,AsymmetricKeyCreator<PR,PU,PAIR>,AsymmetricKeyPairFactory<PR,PU,PAIR>,AsymmetricKeyPairFactorySimple<PR,PU,PAIR>,PrivateKeyFactory<PR>,PublicKeyFactory<PU>,KeyCreator
- Direct Known Subclasses:
AsymmetricKeyCreatorEcBc,AsymmetricKeyCreatorImpl,AsymmetricKeyCreatorRsa
public abstract class AbstractAsymmetricKeyCreator<PR extends PrivateKey,PU extends PublicKey,PAIR extends AbstractAsymmetricKeyPair<PR,PU>> extends CryptoAlgorithmImplWithRandom implements AsymmetricKeyCreator<PR,PU,PAIR>
Abstract base implementation ofKeyCreator.- Since:
- 1.0.0
-
-
Field Summary
-
Fields inherited from class io.github.mmm.crypto.algorithm.AbstractCryptoAlgorithmWithProvider
provider
-
-
Constructor Summary
Constructors Constructor Description AbstractAsymmetricKeyCreator(KeyFactory keyFactory, int keyLength, SecurityProvider provider, RandomFactory randomFactory)The constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description byte[]asData(PAIR keyPair, String format)byte[]asData(PR privateKey, String format)byte[]asData(PU publicKey, String format)PAIRcreateKeyPair(byte[] data, String format)PRcreatePrivateKey(byte[] data, String format)PUcreatePublicKey(byte[] data, String format)PAIRgenerateKeyPair()intgetKeyLength()protected voidinit(KeyPairGenerator keyPairGenerator)protected voidregister(AsymmetricKeyPairFactory<PR,PU,PAIR> factory)Please register in proper order of trials for auto-detection.protected voidregister(AsymmetricKeyPairFactory<PR,PU,PAIR> factory, String format)Please register in proper order of trials for auto-detection.-
Methods inherited from class io.github.mmm.crypto.algorithm.CryptoAlgorithmImplWithRandom
createSecureRandom, getRandomFactory
-
Methods inherited from class io.github.mmm.crypto.algorithm.CryptoAlgorithmImpl
getAlgorithm
-
Methods inherited from class io.github.mmm.crypto.algorithm.AbstractCryptoAlgorithmWithProvider
getProvider
-
Methods inherited from class io.github.mmm.crypto.algorithm.AbstractSecurityAlgorithm
creationFailedException, creationFailedException, creationFailedException, creationFailedException, getAlgorithm, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface io.github.mmm.crypto.asymmetric.key.AsymmetricKeyCreator
asBinary, asBinary, asBinary, asData, asData, asData, createKeyPair, createPrivateKey, createPublicKey, getKeyLength, getKeyLength, verifyKey, verifyKey
-
Methods inherited from interface io.github.mmm.crypto.asymmetric.key.AsymmetricKeyPairFactory
asBinary
-
Methods inherited from interface io.github.mmm.crypto.asymmetric.key.AsymmetricKeyPairFactorySimple
createKeyPair
-
Methods inherited from interface io.github.mmm.crypto.algorithm.CryptoAlgorithm
getAlgorithm
-
Methods inherited from interface io.github.mmm.crypto.asymmetric.key.PrivateKeyFactory
asBinary
-
Methods inherited from interface io.github.mmm.crypto.asymmetric.key.PublicKeyFactory
asBinary
-
-
-
-
Constructor Detail
-
AbstractAsymmetricKeyCreator
public AbstractAsymmetricKeyCreator(KeyFactory keyFactory, int keyLength, SecurityProvider provider, RandomFactory randomFactory)
The constructor.- Parameters:
keyFactory- theKeyFactory.keyLength- thekey length.provider- the securityProvider.randomFactory- theRandomFactory.
-
-
Method Detail
-
getKeyLength
public int getKeyLength()
- Specified by:
getKeyLengthin interfaceKeyCreator- Returns:
- the length of the key in bits. The bigger the key length the stronger and more secure the encryption but
also the more computation power is required. Reasonable values depend on the
algorithm: A recent value for RSA is 4096 bits while for PBKDF2 256 may be sufficient.
-
register
protected void register(AsymmetricKeyPairFactory<PR,PU,PAIR> factory)
Please register in proper order of trials for auto-detection.- Parameters:
factory- theAsymmetricKeyPairFactoryto register.
-
register
protected void register(AsymmetricKeyPairFactory<PR,PU,PAIR> factory, String format)
Please register in proper order of trials for auto-detection.- Parameters:
factory- theAsymmetricKeyPairFactoryto register.format- the format to register as.
-
createPrivateKey
public PR createPrivateKey(byte[] data, String format)
- Specified by:
createPrivateKeyin interfaceAsymmetricKeyCreator<PR extends PrivateKey,PU extends PublicKey,PAIR extends AbstractAsymmetricKeyPair<PR,PU>>- Parameters:
data- thePrivateKeyas rawbytearray.format- theCryptoBinaryFormatto use.- Returns:
- the deserialized
PrivateKey.
-
asData
public byte[] asData(PR privateKey, String format)
- Specified by:
asDatain interfaceAsymmetricKeyCreator<PR extends PrivateKey,PU extends PublicKey,PAIR extends AbstractAsymmetricKeyPair<PR,PU>>- Parameters:
privateKey- thePrivateKeyto serialize.format- the theCryptoBinaryFormatto use.- Returns:
- the binary data.
-
createPublicKey
public PU createPublicKey(byte[] data, String format)
- Specified by:
createPublicKeyin interfaceAsymmetricKeyCreator<PR extends PrivateKey,PU extends PublicKey,PAIR extends AbstractAsymmetricKeyPair<PR,PU>>- Parameters:
data- thePublicKeyas rawbytearray.format- the theCryptoBinaryFormatto use.- Returns:
- the deserialized
PublicKey.
-
asData
public byte[] asData(PU publicKey, String format)
- Specified by:
asDatain interfaceAsymmetricKeyCreator<PR extends PrivateKey,PU extends PublicKey,PAIR extends AbstractAsymmetricKeyPair<PR,PU>>- Parameters:
publicKey- thePublicKeyto serialize.format- the theCryptoBinaryFormatto use.- Returns:
- the binary data.
-
createKeyPair
public PAIR createKeyPair(byte[] data, String format)
- Specified by:
createKeyPairin interfaceAsymmetricKeyCreator<PR extends PrivateKey,PU extends PublicKey,PAIR extends AbstractAsymmetricKeyPair<PR,PU>>- Parameters:
data- theAsymmetricKeyPairas raw byte array.format- the theCryptoBinaryFormatto use.- Returns:
- the deserialized
AsymmetricKeyPair.
-
asData
public byte[] asData(PAIR keyPair, String format)
- Specified by:
asDatain interfaceAsymmetricKeyCreator<PR extends PrivateKey,PU extends PublicKey,PAIR extends AbstractAsymmetricKeyPair<PR,PU>>- Parameters:
keyPair- theAsymmetricKeyPairto serialize.format- the theCryptoBinaryFormatto use.- Returns:
- the serialized binary data.
-
generateKeyPair
public PAIR generateKeyPair()
- Specified by:
generateKeyPairin interfaceAsymmetricKeyCreator<PR extends PrivateKey,PU extends PublicKey,PAIR extends AbstractAsymmetricKeyPair<PR,PU>>- Returns:
- a new
AsymmetricKeyPairwith a generatedprivateandpublickey for the underlying cryptography.
-
init
protected void init(KeyPairGenerator keyPairGenerator) throws Exception
- Parameters:
keyPairGenerator- theKeyPairGeneratortoinitialize.- Throws:
Exception- on error.
-
-