Android BigInteger ArithmeticException

qwe*_*rty 12 java android rsa biginteger arithmeticexception

我正在尝试在Android应用程序中实现RSA算法.我正在使用java.math.BigInteger.modPow()en// decryption函数,它适用于我的计算机(Windows和Xubuntu)和我的Raspberry Pi(也是Debian).当我的手机(Android 4.4.4)上执行相同的代码时,在第二次调用时会抛出以下异常modPow():

java.jang.ArithmeticException: error:0306B06B:bignum routines:BN_div:not initialized
    at java.math.NativeBN.BN_mod_exp(NativeMethod)
    at java.math.BigInt.modExp(BigInt.java:327)
    at java.math.BigInteger.modPow(BigInteger.java:997)
    at "where I call java.math.BigInteger.modPow()"
Run Code Online (Sandbox Code Playgroud)

我检查了指数和模数:两者都是正数,因此文档并没有真正帮助.减小密钥的大小(指数和模数)也没有改变任何东西.不幸的是,我找不到本机功能的来源,并且没有想法可能会发生什么.

你知道为什么会抛出这个异常或错误代码应该是什么意思吗?

gan*_*ers 0

因为它告诉您未初始化,所以 BigInteger 的创建一定以某种方式失败了。

\n\n

从libcrypto开始:

\n\n
\n

BIGNUM 库通常位于 OpenSSL 附带的 libcrypto 中。其 API 定义在 openssl/bn.h 中。该库导出 BIGNUM 类型。BIGNUM 对象始终需要在使用前进行初始化,即使它们是静态声明的。

\n
\n\n

因此,请检查是否可以从代码中初始化它或尝试较低的 api 版本,因为 i\xc2\xb4m 对此没有那么深入。

\n\n

另请检查捆绑的库是否与您的平台架构 32/64 位相对应。

\n\n

另一个猜测:如果 SSL 错误队列不为空,Android 4.4.4 在创建 BigIntegers 时可能存在 [bug] (code.google.com/p/android/issues/detail?id=77262),也许这就是您遇到的情况。

\n