Skip to content

Commit 2abeb11

Browse files
committed
Correct JavaDoc with refactor
1 parent c140e0e commit 2abeb11

File tree

7 files changed

+76
-9
lines changed

7 files changed

+76
-9
lines changed

src/main/java/edu/fiu/adwise/ciphercraft/dgk/DGKPrivateKey.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import edu.fiu.adwise.ciphercraft.misc.KeyFunctions;
1414
import edu.fiu.adwise.ciphercraft.misc.NTL;
1515
import edu.fiu.adwise.ciphercraft.misc.ObjectIdentifier;
16+
import edu.fiu.adwise.ciphercraft.paillier.PaillierPublicKey;
1617
import org.bouncycastle.asn1.*;
1718
import org.bouncycastle.asn1.pkcs.PrivateKeyInfo;
1819
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
@@ -112,6 +113,13 @@ public DGKPrivateKey (BigInteger p, BigInteger q, BigInteger vp,
112113
this.generategLUT();
113114
}
114115

116+
/**
117+
* Loads a DGK private key from a PEM-encoded file.
118+
*
119+
* @param keyFile the path to the PEM file containing the private key
120+
* @return a {@link DGKPrivateKey} instance parsed from the file
121+
* @throws IOException if an error occurs while reading or parsing the file
122+
*/
115123
public static DGKPrivateKey fromFile(String keyFile) throws IOException {
116124
byte[] encoded = KeyFunctions.readPemFile(keyFile, PRIVATE_KEY_START, PRIVATE_KEY_END);
117125
return fromEncoded(encoded);

src/main/java/edu/fiu/adwise/ciphercraft/dgk/DGKPublicKey.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@ public DGKPublicKey(BigInteger n, BigInteger g, BigInteger h, BigInteger u,
8888
this.k = k;
8989
}
9090

91+
/**
92+
* Loads a DGK public key from a PEM-encoded file.
93+
*
94+
* @param keyFile the path to the PEM file containing the public key
95+
* @return a {@link DGKPublicKey} instance parsed from the file
96+
* @throws IOException if an error occurs while reading or parsing the file
97+
*/
9198
public static DGKPublicKey fromFile(String keyFile) throws IOException {
9299
byte[] encoded = KeyFunctions.readPemFile(keyFile, PUBLIC_KEY_START, PUBLIC_KEY_END);
93100
return fromEncoded(encoded);

src/main/java/edu/fiu/adwise/ciphercraft/misc/KeyFunctions.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/*
2+
* Copyright (c) 2025 ADWISE Lab, Florida International University (FIU), AndrewQuijano
3+
* Licensed under the MIT License. See LICENSE file in the project root for details.
4+
*/
15
package edu.fiu.adwise.ciphercraft.misc;
26

37
import java.io.BufferedReader;
@@ -11,6 +15,15 @@
1115
import static edu.fiu.adwise.ciphercraft.misc.CipherConstants.*;
1216
import static edu.fiu.adwise.ciphercraft.misc.CipherConstants.PRIVATE_KEY_END;
1317

18+
/**
19+
* Utility class for reading and writing cryptographic keys in PEM format.
20+
* <p>
21+
* Provides methods to serialize {@link java.security.Key} objects to PEM files
22+
* and to parse PEM-encoded key files into byte arrays.
23+
* <p>
24+
* This class supports both public and private keys, automatically handling
25+
* the appropriate PEM headers and footers.
26+
*/
1427
public class KeyFunctions {
1528

1629
/**
@@ -33,6 +46,15 @@ public static void writeKey(Key key, String key_file) throws IOException {
3346
}
3447
}
3548

49+
/**
50+
* Reads a PEM-encoded key from a file and decodes its Base64 content.
51+
*
52+
* @param filePath the path to the PEM file
53+
* @param beginMarker the string marking the beginning of the key section (e.g., "-----BEGIN PUBLIC KEY-----")
54+
* @param endMarker the string marking the end of the key section (e.g., "-----END PUBLIC KEY-----")
55+
* @return a byte array containing the decoded key data
56+
* @throws IOException if an I/O error occurs while reading the file
57+
*/
3658
public static byte[] readPemFile(String filePath, String beginMarker, String endMarker) throws IOException {
3759
StringBuilder pemContent = new StringBuilder();
3860
try (BufferedReader br = new BufferedReader(new FileReader(filePath))) {

src/main/java/edu/fiu/adwise/ciphercraft/misc/ObjectIdentifier.java

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/*
2+
* Copyright (c) 2025 ADWISE Lab, Florida International University (FIU), AndrewQuijano
3+
* Licensed under the MIT License. See LICENSE file in the project root for details.
4+
*/
15
package edu.fiu.adwise.ciphercraft.misc;
26

37
import edu.fiu.adwise.ciphercraft.dgk.DGK_Key;
@@ -8,28 +12,40 @@
812

913
import java.security.Key;
1014

15+
/**
16+
* Utility class for mapping cryptographic key instances to their corresponding
17+
* ASN.1 Object Identifiers (OIDs) for VCU-specific algorithms.
18+
* <p>
19+
* Supports DGK, ElGamal, Goldwasser-Micali, and Paillier algorithms, assigning
20+
* each a unique OID under the Virginia Commonwealth University (VCU) Private Enterprise Number (PEN)
21+
* as registered with IANA.
22+
* <p>
23+
* The OIDs are used for identifying algorithms in cryptographic protocols and data formats.
24+
*/
1125
public class ObjectIdentifier {
1226

1327
/**
1428
* The Object Identifier (OID) for a VCU-specific cryptographic algorithm.
1529
* <p>
1630
* An OID is a globally unique identifier with a hierarchical structure.
17-
* The prefix {@code 1.3.6.1.4.1} is the globally recognized path for **Private Enterprise Numbers (PENs)**.
31+
* The prefix {@code 1.3.6.1.4.1} is the globally recognized path for <b>Private Enterprise Numbers (PENs)</b>.
1832
* <ul>
19-
* <li>{@code 1}: Refers to ISO (International Organization for Standardization).</li>
20-
* <li>{@code 3}: A sub-tree for "identified-organization."</li>
21-
* <li>{@code 6}: A sub-tree for the U.S. Department of Defense (DoD).</li>
22-
* <li>{@code 1}: The "internet" branch under the DoD.</li>
23-
* <li>{@code 4}: The "private" branch for privately assigned numbers.</li>
24-
* <li>{@code 1}: The "enterprise" branch, which IANA manages for PENs.</li>
33+
* <li>{@code 1}: Refers to ISO (International Organization for Standardization).</li>
34+
* <li>{@code 3}: A sub-tree for "identified-organization."</li>
35+
* <li>{@code 6}: A sub-tree for the U.S. Department of Defense (DoD).</li>
36+
* <li>{@code 1}: The "internet" branch under the DoD.</li>
37+
* <li>{@code 4}: The "private" branch for privately assigned numbers.</li>
38+
* <li>{@code 1}: The "enterprise" branch, which IANA manages for PENs.</li>
2539
* </ul>
2640
* <p>
2741
* The number {@code 10384} is the specific PEN assigned to Virginia Commonwealth University (VCU)
2842
* by the Internet Assigned Numbers Authority (IANA). The final number, {@code 1}, is a
2943
* sub-identifier defined by VCU for DGK, and the sequence continues for ElGamal, Goldwasser-Micali and Paillier.
3044
* <p>
3145
* You can verify this assignment on the official IANA registry here:
32-
* {@link <a href="https://www.iana.org/assignments/enterprise-numbers">IANA Link</a>}.
46+
* <a href="https://www.iana.org/assignments/enterprise-numbers">IANA Link</a>
47+
* <a href="https://michaelwaterman.nl/2025/05/10/part-5-pki-best-practices-creating-unique-object-identifiers-oids/">Best Practices Guide</a>
48+
*
3349
* @param key the cryptographic key instance
3450
* @return the corresponding ASN1ObjectIdentifier for the algorithm, or {@code null} if unknown
3551
*/

src/main/java/edu/fiu/adwise/ciphercraft/paillier/PaillierKeyPairGenerator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public class PaillierKeyPairGenerator extends KeyPairGeneratorSpi implements Cip
3030
* Main method to generate and save Paillier public and private keys to files.
3131
*
3232
* @param args Command-line arguments (not used).
33+
* @throws IOException If an I/O error occurs during key file writing.
3334
*/
3435
public static void main(String [] args) throws IOException {
3536
String paillier_private_key_file = "paillier.priv";

src/main/java/edu/fiu/adwise/ciphercraft/paillier/PaillierPrivateKey.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@ public PaillierPrivateKey(int key_size, BigInteger n, BigInteger mod,
7474
this.rho = PaillierCipher.L(this.g.modPow(this.lambda, this.modulus), this.n).modInverse(this.modulus);
7575
}
7676

77+
/**
78+
* Loads a Paillier private key from a PEM-encoded file.
79+
*
80+
* @param keyFile the path to the PEM file containing the private key
81+
* @return a {@link PaillierPrivateKey} instance parsed from the file
82+
* @throws IOException if an error occurs while reading or parsing the file
83+
*/
7784
public static PaillierPrivateKey fromFile(String keyFile) throws IOException {
7885
byte[] encoded = KeyFunctions.readPemFile(keyFile, PRIVATE_KEY_START, PRIVATE_KEY_END);
7986
return fromEncoded(encoded);

src/main/java/edu/fiu/adwise/ciphercraft/paillier/PaillierPublicKey.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,18 @@ public PaillierPublicKey(int key_size, BigInteger n, BigInteger modulus, BigInte
5757
this.g = g;
5858
}
5959

60+
/**
61+
* Loads a Paillier public key from a PEM-encoded file.
62+
*
63+
* @param keyFile the path to the PEM file containing the public key
64+
* @return a {@link PaillierPublicKey} instance parsed from the file
65+
* @throws IOException if an error occurs while reading or parsing the file
66+
*/
6067
public static PaillierPublicKey fromFile(String keyFile) throws IOException {
6168
byte[] encoded = KeyFunctions.readPemFile(keyFile, PUBLIC_KEY_START, PUBLIC_KEY_END);
6269
return fromEncoded(encoded);
6370
}
6471

65-
6672
/**
6773
* Retrieves the encryption of zero using this public key.
6874
*

0 commit comments

Comments
 (0)