Class AbstractKeyConverter
- java.lang.Object
-
- com.github.toolarium.security.pki.impl.AbstractKeyConverter
-
- All Implemented Interfaces:
IKeyConverter
- Direct Known Subclasses:
DSAKeyConverter,ECKeyConverter,RSAKeyConverter
public abstract class AbstractKeyConverter extends java.lang.Object implements IKeyConverter
This key converter base class
-
-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.StringNL
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractKeyConverter(java.lang.String provider, java.lang.String type, int defaultSize)Constructor for AbstractKeyConverter
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringformatPrivateKey(java.security.PrivateKey privateKey)Formats a private key to a well formed private key, which is bounded at the beginning by-----BEGIN ...java.security.KeyPairgenerateKeyPair()Generates a KeyPair containing a Private- and PublicKeyjava.security.KeyPairgenerateKeyPair(java.lang.String algorithm, int keySize)Generates a KeyPair containing a Private- and PublicKeyjava.security.PrivateKeygetPrivateKey(byte[] content)Reads PKCS#8 formated private key from a buffer, which are each bounded at the beginning by-----BEGIN ...java.security.PrivateKeygetPrivateKey(java.io.File file)Reads PKCS#8 formated private key from a file, which are each bounded at the beginning by-----BEGIN ...java.security.PrivateKeygetPrivateKey(java.lang.String content)Reads PKCS#8 formated private key from a buffer, which are each bounded at the beginning by-----BEGIN ...java.lang.StringgetProvider()Get the providerjava.security.PublicKeygetPublicKey(java.io.File file)Reads PKCS#8 formated public key from a file, which are each bounded at the beginning by-----BEGIN ...java.security.PublicKeygetPublicKey(java.lang.String content)Reads PKCS#8 formated public key from a buffer which are each bounded at the beginning by-----BEGIN PUBLIC KEY-----, and bounded at the end by-----END PUBLIC KEY-----.java.lang.StringgetType()Get the type, e.g.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.github.toolarium.security.pki.IKeyConverter
formatPKCS8, formatPublicKey, getPublicKey, normalizePKCS8
-
-
-
-
Field Detail
-
NL
protected static final java.lang.String NL
- See Also:
- Constant Field Values
-
-
Method Detail
-
getProvider
public java.lang.String getProvider()
Description copied from interface:IKeyConverterGet the provider- Specified by:
getProviderin interfaceIKeyConverter- Returns:
- the provider or null
- See Also:
IKeyConverter.getProvider()
-
getType
public java.lang.String getType()
Description copied from interface:IKeyConverterGet the type, e.g. RSA, DSA or EC- Specified by:
getTypein interfaceIKeyConverter- Returns:
- the type as string
- See Also:
IKeyConverter.getType()
-
generateKeyPair
public java.security.KeyPair generateKeyPair() throws java.security.GeneralSecurityExceptionDescription copied from interface:IKeyConverterGenerates a KeyPair containing a Private- and PublicKey- Specified by:
generateKeyPairin interfaceIKeyConverter- Returns:
- the created KeyPair
- Throws:
java.security.GeneralSecurityException- in case of error- See Also:
IKeyConverter.generateKeyPair()
-
generateKeyPair
public java.security.KeyPair generateKeyPair(java.lang.String algorithm, int keySize) throws java.security.GeneralSecurityExceptionDescription copied from interface:IKeyConverterGenerates a KeyPair containing a Private- and PublicKey- Specified by:
generateKeyPairin interfaceIKeyConverter- Parameters:
algorithm- the algorithm like: SHA1withRSA, SHA1withDSA, RSA...keySize- the size of the key- Returns:
- the created KeyPair
- Throws:
java.security.GeneralSecurityException- in case of error- See Also:
IKeyConverter.generateKeyPair(java.lang.String, int)
-
getPublicKey
public java.security.PublicKey getPublicKey(java.lang.String content) throws java.io.IOException, java.security.GeneralSecurityExceptionDescription copied from interface:IKeyConverterReads PKCS#8 formated public key from a buffer which are each bounded at the beginning by-----BEGIN PUBLIC KEY-----, and bounded at the end by-----END PUBLIC KEY-----.- Specified by:
getPublicKeyin interfaceIKeyConverter- Parameters:
content- the content- Returns:
- the public key
- Throws:
java.io.IOException- in case of errorjava.security.GeneralSecurityException- in case of error- See Also:
IKeyConverter.getPublicKey(java.lang.String)
-
getPublicKey
public java.security.PublicKey getPublicKey(java.io.File file) throws java.io.IOException, java.security.GeneralSecurityExceptionDescription copied from interface:IKeyConverterReads PKCS#8 formated public key from a file, which are each bounded at the beginning by-----BEGIN ... PUBLIC KEY-----, and bounded at the end by-----END ... PUBLIC KEY-----.- Specified by:
getPublicKeyin interfaceIKeyConverter- Parameters:
file- the file to read- Returns:
- the private key
- Throws:
java.io.IOException- in case of errorjava.security.GeneralSecurityException- in case of error- See Also:
IKeyConverter.getPublicKey(java.io.File)
-
getPrivateKey
public java.security.PrivateKey getPrivateKey(byte[] content) throws java.io.IOException, java.security.GeneralSecurityExceptionDescription copied from interface:IKeyConverterReads PKCS#8 formated private key from a buffer, which are each bounded at the beginning by-----BEGIN ... PRIVATE KEY-----, and bounded at the end by-----END ... PRIVATE KEY-----.- Specified by:
getPrivateKeyin interfaceIKeyConverter- Parameters:
content- the private key to encode- Returns:
- the private key
- Throws:
java.io.IOException- in case of errorjava.security.GeneralSecurityException- in case of error- See Also:
IKeyConverter.getPrivateKey(byte[])
-
getPrivateKey
public java.security.PrivateKey getPrivateKey(java.lang.String content) throws java.security.GeneralSecurityExceptionDescription copied from interface:IKeyConverterReads PKCS#8 formated private key from a buffer, which are each bounded at the beginning by-----BEGIN ... PRIVATE KEY-----, and bounded at the end by-----END ... PRIVATE KEY-----.- Specified by:
getPrivateKeyin interfaceIKeyConverter- Parameters:
content- the private key to encode- Returns:
- the private key
- Throws:
java.security.GeneralSecurityException- in case of error- See Also:
IKeyConverter.getPrivateKey(java.lang.String)
-
getPrivateKey
public java.security.PrivateKey getPrivateKey(java.io.File file) throws java.io.IOException, java.security.GeneralSecurityExceptionDescription copied from interface:IKeyConverterReads PKCS#8 formated private key from a file, which are each bounded at the beginning by-----BEGIN ... PRIVATE KEY-----, and bounded at the end by-----END ... PRIVATE KEY-----.- Specified by:
getPrivateKeyin interfaceIKeyConverter- Parameters:
file- the file to read- Returns:
- the private key
- Throws:
java.io.IOException- in case of errorjava.security.GeneralSecurityException- in case of error- See Also:
IKeyConverter.getPrivateKey(java.io.File)
-
formatPrivateKey
public java.lang.String formatPrivateKey(java.security.PrivateKey privateKey)
Description copied from interface:IKeyConverterFormats a private key to a well formed private key, which is bounded at the beginning by-----BEGIN ... PRIVATE KEY-----, and bounded at the end by-----END ... PRIVATE KEY-----.- Specified by:
formatPrivateKeyin interfaceIKeyConverter- Parameters:
privateKey- the private key to format- Returns:
- the well formed certificate
- See Also:
IKeyConverter.formatPrivateKey(java.security.PrivateKey)
-
-