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)
PAIR
createKeyPair(byte[] data, String format)
PR
createPrivateKey(byte[] data, String format)
PU
createPublicKey(byte[] data, String format)
PAIR
generateKeyPair()
int
getKeyLength()
protected void
init(KeyPairGenerator keyPairGenerator)
protected void
register(AsymmetricKeyPairFactory<PR,PU,PAIR> factory)
Please register in proper order of trials for auto-detection.protected void
register(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:
getKeyLength
in 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
- theAsymmetricKeyPairFactory
to register.
-
register
protected void register(AsymmetricKeyPairFactory<PR,PU,PAIR> factory, String format)
Please register in proper order of trials for auto-detection.- Parameters:
factory
- theAsymmetricKeyPairFactory
to register.format
- the format to register as.
-
createPrivateKey
public PR createPrivateKey(byte[] data, String format)
- Specified by:
createPrivateKey
in interfaceAsymmetricKeyCreator<PR extends PrivateKey,PU extends PublicKey,PAIR extends AbstractAsymmetricKeyPair<PR,PU>>
- Parameters:
data
- thePrivateKey
as rawbyte
array.format
- theCryptoBinaryFormat
to use.- Returns:
- the deserialized
PrivateKey
.
-
asData
public byte[] asData(PR privateKey, String format)
- Specified by:
asData
in interfaceAsymmetricKeyCreator<PR extends PrivateKey,PU extends PublicKey,PAIR extends AbstractAsymmetricKeyPair<PR,PU>>
- Parameters:
privateKey
- thePrivateKey
to serialize.format
- the theCryptoBinaryFormat
to use.- Returns:
- the binary data.
-
createPublicKey
public PU createPublicKey(byte[] data, String format)
- Specified by:
createPublicKey
in interfaceAsymmetricKeyCreator<PR extends PrivateKey,PU extends PublicKey,PAIR extends AbstractAsymmetricKeyPair<PR,PU>>
- Parameters:
data
- thePublicKey
as rawbyte
array.format
- the theCryptoBinaryFormat
to use.- Returns:
- the deserialized
PublicKey
.
-
asData
public byte[] asData(PU publicKey, String format)
- Specified by:
asData
in interfaceAsymmetricKeyCreator<PR extends PrivateKey,PU extends PublicKey,PAIR extends AbstractAsymmetricKeyPair<PR,PU>>
- Parameters:
publicKey
- thePublicKey
to serialize.format
- the theCryptoBinaryFormat
to use.- Returns:
- the binary data.
-
createKeyPair
public PAIR createKeyPair(byte[] data, String format)
- Specified by:
createKeyPair
in interfaceAsymmetricKeyCreator<PR extends PrivateKey,PU extends PublicKey,PAIR extends AbstractAsymmetricKeyPair<PR,PU>>
- Parameters:
data
- theAsymmetricKeyPair
as raw byte array.format
- the theCryptoBinaryFormat
to use.- Returns:
- the deserialized
AsymmetricKeyPair
.
-
asData
public byte[] asData(PAIR keyPair, String format)
- Specified by:
asData
in interfaceAsymmetricKeyCreator<PR extends PrivateKey,PU extends PublicKey,PAIR extends AbstractAsymmetricKeyPair<PR,PU>>
- Parameters:
keyPair
- theAsymmetricKeyPair
to serialize.format
- the theCryptoBinaryFormat
to use.- Returns:
- the serialized binary data.
-
generateKeyPair
public PAIR generateKeyPair()
- Specified by:
generateKeyPair
in interfaceAsymmetricKeyCreator<PR extends PrivateKey,PU extends PublicKey,PAIR extends AbstractAsymmetricKeyPair<PR,PU>>
- Returns:
- a new
AsymmetricKeyPair
with a generatedprivate
andpublic
key for the underlying cryptography.
-
init
protected void init(KeyPairGenerator keyPairGenerator) throws Exception
- Parameters:
keyPairGenerator
- theKeyPairGenerator
toinitialize
.- Throws:
Exception
- on error.
-
-