|
36 | 36 | */
|
37 | 37 | public class KeyUtils {
|
38 | 38 |
|
| 39 | + /** A constant string with the value "ChaCha20" */ |
39 | 40 | public static final String CHA_CHA_20 = "ChaCha20";
|
| 41 | + |
| 42 | + /** A constant string with the value "X25519" */ |
40 | 43 | public static final String X25519 = "X25519";
|
41 | 44 |
|
| 45 | + /** Header line text for public key file in OpenSSL format */ |
42 | 46 | public static final String BEGIN_PUBLIC_KEY = "-----BEGIN PUBLIC KEY-----";
|
| 47 | + |
| 48 | + /** Footer line text for public key file in OpenSSL format */ |
43 | 49 | public static final String END_PUBLIC_KEY = "-----END PUBLIC KEY-----";
|
| 50 | + |
| 51 | + /** Header line text for private key file in OpenSSL format */ |
44 | 52 | public static final String BEGIN_PRIVATE_KEY = "-----BEGIN PRIVATE KEY-----";
|
| 53 | + |
| 54 | + /** Footer line text for private key file in OpenSSL format */ |
45 | 55 | public static final String END_PRIVATE_KEY = "-----END PRIVATE KEY-----";
|
| 56 | + |
| 57 | + /** Header line text for public key file in Crypt4GH format */ |
46 | 58 | public static final String BEGIN_CRYPT4GH_PUBLIC_KEY = "-----BEGIN CRYPT4GH PUBLIC KEY-----";
|
| 59 | + |
| 60 | + /** Footer line text for public key file in Crypt4GH format */ |
47 | 61 | public static final String END_CRYPT4GH_PUBLIC_KEY = "-----END CRYPT4GH PUBLIC KEY-----";
|
| 62 | + |
| 63 | + /** Header line text for private key file in Crypt4GH format */ |
48 | 64 | public static final String BEGIN_CRYPT4GH_ENCRYPTED_PRIVATE_KEY = "-----BEGIN CRYPT4GH ENCRYPTED PRIVATE KEY-----";
|
| 65 | + |
| 66 | + /** Footer line text for private key file in Crypt4GH format */ |
49 | 67 | public static final String END_CRYPT4GH_ENCRYPTED_PRIVATE_KEY = "-----END CRYPT4GH ENCRYPTED PRIVATE KEY-----";
|
50 | 68 |
|
| 69 | + /** Magic number string used at the beginning of private key files in Crypt4GH format */ |
51 | 70 | public static final String CRYPT4GH_AUTH_MAGIC = "c4gh-v1";
|
52 | 71 |
|
53 | 72 | private static KeyUtils ourInstance = new KeyUtils();
|
@@ -371,6 +390,7 @@ public void writeOpenSSLKey(Writer writer, Key key) throws IOException {
|
371 | 390 | * @param key Key to write.
|
372 | 391 | * @param password Password to lock private key.
|
373 | 392 | * @throws IOException If the file can't be written.
|
| 393 | + * @throws GeneralSecurityException If the key was not XECPublicKey or XECPrivateKey. |
374 | 394 | */
|
375 | 395 | public void writeCrypt4GHKey(Writer writer, Key key, char[] password) throws IOException, GeneralSecurityException {
|
376 | 396 | Collection<String> keyLines = new ArrayList<>();
|
@@ -425,6 +445,7 @@ public void writeOpenSSLKey(File keyFile, Key key) throws IOException {
|
425 | 445 | * @param key Key to write.
|
426 | 446 | * @param password Password to lock private key.
|
427 | 447 | * @throws IOException If the file can't be written.
|
| 448 | + * @throws GeneralSecurityException If the key was not XECPublicKey or XECPrivateKey. |
428 | 449 | */
|
429 | 450 | public void writeCrypt4GHKey(File keyFile, Key key, char[] password) throws IOException, GeneralSecurityException {
|
430 | 451 | try (FileWriter fileWriter = new FileWriter(keyFile)) {
|
|
0 commit comments