Package org.europa.together.business
Interface CryptoTools
- All Known Implementing Classes:
JavaCryptoTools
@API(status=STABLE,
since="2.0",
consumers="JavaCryptoTools")
@Component
public interface CryptoTools
Basic cryptographic functions for applications.
- Since:
- 2.0
- Version:
- 1.0
- Author:
- elmar.dott@gmail.com
-
Field Summary
Fields -
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.
-
Field Details
-
FEATURE_ID
Identifier for the given feature.- See Also:
-
-
Method Details
-
calculateHash
Calculates from a given String an hash.- Parameters:
plainText- as Stringalgorithm- as HashAlgorithm- Returns:
- the calculated hash as String
-
getMaxKeySize
@API(status=STABLE, since="2.1") int getMaxKeySize(CipherAlgorithm cipher) throws NoSuchAlgorithmException Detect the maximum length is able to use for the supported cryptographic algorithms.- Parameters:
cipher- as CipherAlgorithm- Returns:
- length as int
- Throws:
NoSuchAlgorithmException- in case of error
-
generateCipherKeyPair
Generate a public / private key pair. Usage:
KeyPair pair = generateCipherKeyPair(CipherAlgorithm.RSA); Key publicKey = pair.getPublic(); Key privateKey= pair.getPrivate();- Parameters:
cipher- as CipherAlgorithm- Returns:
- public & private Key as KeyPair
-
saveKeyPairToFile
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- Parameters:
path- as StringkeyRing- as KeyPair
-
loadPrivateKeyFile
@API(status=STABLE, since="2.1") PrivateKey loadPrivateKeyFile(String keyFile, CipherAlgorithm algorithm) Load a private key in a binary format from a file to use for cryptography.- Parameters:
keyFile- as Stringalgorithm- as CipherAlgorithm- Returns:
- the PrivateKey
-
loadPublicKeyFile
@API(status=STABLE, since="2.1") PublicKey loadPublicKeyFile(String keyFile, CipherAlgorithm algorithm) Load a public key in a binary format from a file to use for cryptography.- Parameters:
keyFile- as Stringalgorithm- as CipherAlgorithm- Returns:
- publicKey as PublicKey
-
generateRandomNumber
Generate a secure DOUBLE random value.- Parameters:
algortihm- as RNGAlgorithm- Returns:
- a random double
-