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
Constructors -
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.doublegenerateRandomNumber(RNGAlgorithm algortihm) Generate a secure DOUBLE random value.intgetMaxKeySize(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.voidsaveKeyPairToFile(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:CryptoToolsCalculates from a given String an hash.- Specified by:
calculateHashin interfaceCryptoTools- Parameters:
plainText- as Stringalgorithm- as HashAlgorithm- Returns:
- the calculated hash as String
-
getMaxKeySize
Description copied from interface:CryptoToolsDetect the maximum length is able to use for the supported cryptographic algorithms.- Specified by:
getMaxKeySizein interfaceCryptoTools- Parameters:
cipher- as CipherAlgorithm- Returns:
- length as int
- Throws:
NoSuchAlgorithmException- in case of error
-
generateCipherKeyPair
Description copied from interface:CryptoToolsGenerate a public / private key pair. Usage:
KeyPair pair = generateCipherKeyPair(CipherAlgorithm.RSA); Key publicKey = pair.getPublic(); Key privateKey= pair.getPrivate();- Specified by:
generateCipherKeyPairin interfaceCryptoTools- Parameters:
cipher- as CipherAlgorithm- Returns:
- public & private Key as KeyPair
-
saveKeyPairToFile
Description copied from interface:CryptoToolsWrites 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:
saveKeyPairToFilein interfaceCryptoTools- Parameters:
path- as StringkeyRing- as KeyPair
-
loadPrivateKeyFile
Description copied from interface:CryptoToolsLoad a private key in a binary format from a file to use for cryptography.- Specified by:
loadPrivateKeyFilein interfaceCryptoTools- Parameters:
keyFile- as Stringalgorithm- as CipherAlgorithm- Returns:
- the PrivateKey
-
loadPublicKeyFile
Description copied from interface:CryptoToolsLoad a public key in a binary format from a file to use for cryptography.- Specified by:
loadPublicKeyFilein interfaceCryptoTools- Parameters:
keyFile- as Stringalgorithm- as CipherAlgorithm- Returns:
- publicKey as PublicKey
-
generateRandomNumber
Description copied from interface:CryptoToolsGenerate a secure DOUBLE random value.- Specified by:
generateRandomNumberin interfaceCryptoTools- Parameters:
algortihm- as RNGAlgorithm- Returns:
- a random double
-