1. Project Clover database Mon Dec 22 2025 14:59:38 CST
  2. Package org.europa.together.business

File CryptoTools.java

 

Code metrics

0
0
0
1
108
31
0
-
-
0
-

Classes

Class Line # Actions
CryptoTools 23 0 - 0 0
-1.0 -
 

Contributing tests

No tests hitting this source file were found.

Source view

1    package org.europa.together.business;
2   
3    import java.security.KeyPair;
4    import java.security.NoSuchAlgorithmException;
5    import java.security.PrivateKey;
6    import java.security.PublicKey;
7    import org.apiguardian.api.API;
8    import static org.apiguardian.api.API.Status.STABLE;
9    import org.europa.together.domain.CipherAlgorithm;
10    import org.europa.together.domain.HashAlgorithm;
11    import org.europa.together.domain.RNGAlgorithm;
12    import org.springframework.stereotype.Component;
13   
14    /**
15    * Basic cryptographic functions for applications.
16    *
17    * @author elmar.dott@gmail.com
18    * @version 1.0
19    * @since 2.0
20    */
21    @API(status = STABLE, since = "2.0", consumers = "JavaCryptoTools")
22    @Component
 
23    public interface CryptoTools {
24   
25    /**
26    * Identifier for the given feature.
27    */
28    @API(status = STABLE, since = "2.0")
29    String FEATURE_ID = "CM-14";
30   
31    /**
32    * Calculates from a given String an hash.
33    *
34    * @param plainText as String
35    * @param algorithm as HashAlgorithm
36    * @return the calculated hash as String
37    */
38    @API(status = STABLE, since = "2.0")
39    String calculateHash(String plainText, HashAlgorithm algorithm);
40   
41    /**
42    * Detect the maximum length is able to use for the supported cryptographic
43    * algorithms.
44    *
45    * @param cipher as CipherAlgorithm
46    * @return length as int
47    * @throws java.security.NoSuchAlgorithmException in case of error
48    */
49    @API(status = STABLE, since = "2.1")
50    int getMaxKeySize(CipherAlgorithm cipher) throws NoSuchAlgorithmException;
51   
52    /**
53    * Generate a public / private key pair. Usage:<br>
54    * <code>
55    * KeyPair pair = generateCipherKeyPair(CipherAlgorithm.RSA);
56    * Key publicKey = pair.getPublic();
57    * Key privateKey= pair.getPrivate();
58    * </code>
59    *
60    * @param cipher as CipherAlgorithm
61    * @return public &amp; private Key as KeyPair
62    */
63    @API(status = STABLE, since = "2.1")
64    KeyPair generateCipherKeyPair(CipherAlgorithm cipher);
65   
66    /**
67    * Writes the public / private keys as binary format to a given destination.
68    * If the path is empty the USER HOME directory is used as default
69    * destination. If the directory don't exist it will created.<br>
70    * - public : publicKey.pub<br>
71    * - private: private.key
72    *
73    * @param path as String
74    * @param keyRing as KeyPair
75    */
76    @API(status = STABLE, since = "2.1")
77    void saveKeyPairToFile(String path, KeyPair keyRing);
78   
79    /**
80    * Load a private key in a binary format from a file to use for
81    * cryptography.
82    *
83    * @param keyFile as String
84    * @param algorithm as CipherAlgorithm
85    * @return the PrivateKey
86    */
87    @API(status = STABLE, since = "2.1")
88    PrivateKey loadPrivateKeyFile(String keyFile, CipherAlgorithm algorithm);
89   
90    /**
91    * Load a public key in a binary format from a file to use for cryptography.
92    *
93    * @param keyFile as String
94    * @param algorithm as CipherAlgorithm
95    * @return publicKey as PublicKey
96    */
97    @API(status = STABLE, since = "2.1")
98    PublicKey loadPublicKeyFile(String keyFile, CipherAlgorithm algorithm);
99   
100    /**
101    * Generate a secure DOUBLE random value.
102    *
103    * @param algortihm as RNGAlgorithm
104    * @return a random double
105    */
106    @API(status = STABLE, since = "3.2")
107    double generateRandomNumber(RNGAlgorithm algortihm);
108    }