diff --git a/src/main/java/com/jcraft/jsch/KeyPairPKCS8.java b/src/main/java/com/jcraft/jsch/KeyPairPKCS8.java index 048bd80d..e1845cf1 100644 --- a/src/main/java/com/jcraft/jsch/KeyPairPKCS8.java +++ b/src/main/java/com/jcraft/jsch/KeyPairPKCS8.java @@ -862,6 +862,13 @@ static Cipher getCipher(byte[] id, ASN1 encryptparams, byte[][] ivp) throws Exce } static int parseASN1IntegerAsInt(byte[] content) { - return new BigInteger(content).intValueExact(); + BigInteger b = new BigInteger(content); + // https://github.com/mwiede/jsch/issues/392 not using intValueExact() because of Android + // incompatibility. + if (b.bitLength() <= 31) { + return b.intValue(); + } else { + throw new ArithmeticException("BigInteger out of int range"); + } } }