1. Project Clover database Wed Jan 17 2024 23:40:18 CST
  2. Package org.europa.together.business

File CryptoTools.java

 

Code metrics

0
0
0
1
98
28
0
-
-
0
-

Classes

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