Package org.europa.together.application
Class JavaCryptoTools
java.lang.Object
org.europa.together.application.JavaCryptoTools
- All Implemented Interfaces:
Serializable
,CryptoTools
Implementation of Java cryptography.
- See Also:
-
Field Summary
Fields inherited from interface org.europa.together.business.CryptoTools
FEATURE_ID
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptioncalculateHash
(String plainText, HashAlgorithm algorithm) Calculates from a given String an hash.generateCipherKeyPair
(CipherAlgorithm cipher) Generate a public / private key pair.int
getMaxKeySize
(CipherAlgorithm cipher) Detect the maximum length is able to use for the supported cryptographic algorithms.loadPrivateKeyFile
(String keyFile, CipherAlgorithm algorithm) Load a private key in a binary format from a file to use for cryptography.loadPublicKeyFile
(String keyFile, CipherAlgorithm algorithm) Load a public key in a binary format from a file to use for cryptography.void
saveKeyPairToFile
(String path, KeyPair keyRing) Writes the public / private keys as binary format to a given destination.
-
Constructor Details
-
JavaCryptoTools
public JavaCryptoTools()Constructor.
-
-
Method Details
-
calculateHash
Description copied from interface:CryptoTools
Calculates from a given String an hash.- Specified by:
calculateHash
in interfaceCryptoTools
- Parameters:
plainText
- as Stringalgorithm
- as HashAlgorithm- Returns:
- the calculated hash as String
-
getMaxKeySize
Description copied from interface:CryptoTools
Detect the maximum length is able to use for the supported cryptographic algorithms.- Specified by:
getMaxKeySize
in interfaceCryptoTools
- Parameters:
cipher
- as CipherAlgorithm- Returns:
- length as int
- Throws:
NoSuchAlgorithmException
-
generateCipherKeyPair
Description copied from interface:CryptoTools
Generate a public / private key pair. Usage:
KeyPair pair = generateCipherKeyPair(CipherAlgorithm.RSA); Key publicKey = pair.getPublic(); Key privateKey= pair.getPrivate();
- Specified by:
generateCipherKeyPair
in interfaceCryptoTools
- Parameters:
cipher
- as CipherAlgorithm- Returns:
- public & private Key as KeyPair
-
saveKeyPairToFile
Description copied from interface:CryptoTools
Writes the public / private keys as binary format to a given destination. If the path is empty the USER HOME directory is used as default destination. If the directory don't exist it will created.- public : publicKey.pub
- private: private.key
- Specified by:
saveKeyPairToFile
in interfaceCryptoTools
- Parameters:
path
- as StringkeyRing
- as KeyPair
-
loadPrivateKeyFile
Description copied from interface:CryptoTools
Load a private key in a binary format from a file to use for cryptography.- Specified by:
loadPrivateKeyFile
in interfaceCryptoTools
- Parameters:
keyFile
- as Stringalgorithm
- as CipherAlgorithm- Returns:
- the PrivateKey
-
loadPublicKeyFile
Description copied from interface:CryptoTools
Load a public key in a binary format from a file to use for cryptography.- Specified by:
loadPublicKeyFile
in interfaceCryptoTools
- Parameters:
keyFile
- as Stringalgorithm
- as CipherAlgorithm- Returns:
- publicKey as PublicKey
-