diff --git a/src/main/java/com/wolfssl/provider/jce/WolfCryptKeyPairGenerator.java b/src/main/java/com/wolfssl/provider/jce/WolfCryptKeyPairGenerator.java index b2c96273..0d72d1e0 100644 --- a/src/main/java/com/wolfssl/provider/jce/WolfCryptKeyPairGenerator.java +++ b/src/main/java/com/wolfssl/provider/jce/WolfCryptKeyPairGenerator.java @@ -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"); }