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 Details

    • FEATURE_ID

      @API(status=STABLE, since="2.0") static final String FEATURE_ID
      Identifier for the given feature.
      See Also:
  • Method Details

    • calculateHash

      @API(status=STABLE, since="2.0") String calculateHash(String plainText, HashAlgorithm algorithm)
      Calculates from a given String an hash.
      Parameters:
      plainText - as String
      algorithm - 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
    • generateCipherKeyPair

      @API(status=STABLE, since="2.1") KeyPair generateCipherKeyPair(CipherAlgorithm cipher)
      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

      @API(status=STABLE, since="2.1") void saveKeyPairToFile(String path, KeyPair keyRing)
      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 String
      keyRing - 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 String
      algorithm - 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 String
      algorithm - as CipherAlgorithm
      Returns:
      publicKey as PublicKey