Class JavaCryptoTools

java.lang.Object
org.europa.together.application.JavaCryptoTools
All Implemented Interfaces:
Serializable, CryptoTools

@Repository public class JavaCryptoTools extends Object implements CryptoTools, Serializable
Implementation of Java cryptography.
See Also:
  • Constructor Details

    • JavaCryptoTools

      public JavaCryptoTools()
      Constructor.
  • Method Details

    • calculateHash

      public String calculateHash(String plainText, HashAlgorithm algorithm)
      Description copied from interface: CryptoTools
      Calculates from a given String an hash.
      Specified by:
      calculateHash in interface CryptoTools
      Parameters:
      plainText - as String
      algorithm - as HashAlgorithm
      Returns:
      the calculated hash as String
    • getMaxKeySize

      public int getMaxKeySize(CipherAlgorithm cipher) throws NoSuchAlgorithmException
      Description copied from interface: CryptoTools
      Detect the maximum length is able to use for the supported cryptographic algorithms.
      Specified by:
      getMaxKeySize in interface CryptoTools
      Parameters:
      cipher - as CipherAlgorithm
      Returns:
      length as int
      Throws:
      NoSuchAlgorithmException
    • generateCipherKeyPair

      public KeyPair generateCipherKeyPair(CipherAlgorithm cipher)
      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 interface CryptoTools
      Parameters:
      cipher - as CipherAlgorithm
      Returns:
      public & private Key as KeyPair
    • saveKeyPairToFile

      public void saveKeyPairToFile(String path, KeyPair keyRing)
      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 interface CryptoTools
      Parameters:
      path - as String
      keyRing - as KeyPair
    • loadPrivateKeyFile

      public PrivateKey loadPrivateKeyFile(String keyFile, CipherAlgorithm algorithm)
      Description copied from interface: CryptoTools
      Load a private key in a binary format from a file to use for cryptography.
      Specified by:
      loadPrivateKeyFile in interface CryptoTools
      Parameters:
      keyFile - as String
      algorithm - as CipherAlgorithm
      Returns:
      the PrivateKey
    • loadPublicKeyFile

      public PublicKey loadPublicKeyFile(String keyFile, CipherAlgorithm algorithm)
      Description copied from interface: CryptoTools
      Load a public key in a binary format from a file to use for cryptography.
      Specified by:
      loadPublicKeyFile in interface CryptoTools
      Parameters:
      keyFile - as String
      algorithm - as CipherAlgorithm
      Returns:
      publicKey as PublicKey