Skip to content

Commit

Permalink
Merge pull request #76 from cconlon/longValue
Browse files Browse the repository at this point in the history
JCE: KeyPairGenerator: remove use of longValueExact()
  • Loading branch information
dgarske authored Aug 1, 2024
2 parents 5ce2d0e + 2d7f778 commit 9ebc287
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,13 @@ public synchronized void initialize(AlgorithmParameterSpec params,
RSAKeyGenParameterSpec rsaSpec = (RSAKeyGenParameterSpec)params;
this.keysize = rsaSpec.getKeysize();

try {
this.publicExponent =
rsaSpec.getPublicExponent().longValueExact();
} catch (ArithmeticException e) {
this.publicExponent =
rsaSpec.getPublicExponent().longValue();

/* Double check longValue() converted correctly. Some platforms
* do not have longValueExact() */
if (!BigInteger.valueOf(this.publicExponent).equals(
rsaSpec.getPublicExponent())) {
throw new InvalidAlgorithmParameterException(
"RSA public exponent value larger than long");
}
Expand Down

0 comments on commit 9ebc287

Please sign in to comment.