Skip to content

Feature2.6.1 #300

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 17, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 13 additions & 15 deletions src/main/java/org/summerboot/jexpress/security/EncryptorUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -462,11 +462,11 @@ public static byte[] decrypt(SecretKey symmetricKey, byte[] encryptedLibraryByte
}
}

public static KeyPair generateKeyPairRSA() throws NoSuchAlgorithmException, InvalidKeySpecException, InvalidAlgorithmParameterException {
public static KeyPair generateKeyPairRSA() throws NoSuchAlgorithmException, InvalidKeySpecException, InvalidAlgorithmParameterException, NoSuchProviderException {
return generateKeyPair("RSA", 4096);
}

public static KeyPair generateKeyPairEC() throws NoSuchAlgorithmException, InvalidKeySpecException, InvalidAlgorithmParameterException {
public static KeyPair generateKeyPairEC() throws NoSuchAlgorithmException, InvalidKeySpecException, InvalidAlgorithmParameterException, NoSuchProviderException {
return generateKeyPair("EC", 256);// secp256r1 , secp384r1, secp521r1
}

Expand All @@ -482,34 +482,32 @@ public static KeyPair generateKeyPairEC() throws NoSuchAlgorithmException, Inval
* @throws NoSuchAlgorithmException
* @throws InvalidKeySpecException
*/
public static KeyPair generateKeyPair(String keyfactoryAlgorithm, int size) throws NoSuchAlgorithmException, InvalidKeySpecException, InvalidAlgorithmParameterException {
public static KeyPair generateKeyPair(String keyfactoryAlgorithm, int size) throws NoSuchAlgorithmException, InvalidKeySpecException, InvalidAlgorithmParameterException, NoSuchProviderException {
if (keyfactoryAlgorithm == null) {
keyfactoryAlgorithm = "EC";
size = 256; // default to EC with 256 bits
}
keyfactoryAlgorithm = keyfactoryAlgorithm.toUpperCase();
KeyPairGenerator kpg;
switch (keyfactoryAlgorithm.toUpperCase()) {
case "RSA" -> {
switch (keyfactoryAlgorithm) {
case "RSA", "DSA", "DH" -> {
if (size < 2048) {
throw new InvalidAlgorithmParameterException("RSA key size must be at least 2048 bits.");
}
kpg = KeyPairGenerator.getInstance("RSA");
kpg = KeyPairGenerator.getInstance(keyfactoryAlgorithm);
kpg.initialize(size);
}
case "EDSA" -> {
kpg = KeyPairGenerator.getInstance(keyfactoryAlgorithm, "BC");
}
case "EC" -> {
if (size < 256) {
throw new InvalidAlgorithmParameterException("EC key size must be at least 256 bits.");
}
kpg = KeyPairGenerator.getInstance("EC");
kpg = KeyPairGenerator.getInstance(keyfactoryAlgorithm);
ECGenParameterSpec spec = getECCurveName(size);
kpg.initialize(spec);
}
case "DSA", "DH" -> {
if (size < 2048) {
throw new InvalidAlgorithmParameterException(keyfactoryAlgorithm + " key size must be at least 2048 bits.");
}
kpg = KeyPairGenerator.getInstance(keyfactoryAlgorithm.toUpperCase());
kpg.initialize(size);
}
default -> throw new NoSuchAlgorithmException(keyfactoryAlgorithm);
}

Expand All @@ -521,7 +519,7 @@ private static ECGenParameterSpec getECCurveName(int size) {
case 256 -> "secp256r1"; // NIST P-256
case 384 -> "secp384r1";
case 521 -> "secp521r1";
default -> "secp521r1";// use 512
default -> "secp256r1";// use 256 by default
});
}

Expand Down
Loading