我正在尝试在 Android 应用程序中实现 RSA 算法。我正在使用 java.math.BigInteger.modPow()
函数进行加密/解密,它适用于我的计算机(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()"
我检查了指数和模数:两者都是正数,因此文档并没有真正帮助。减小 key 的大小(指数和模数)也没有改变任何东西。不幸的是,我找不到 native 函数的源代码,也不知道会发生什么。
您是否知道为什么会抛出此异常或错误代码的含义?
最佳答案
因为它告诉你没有初始化,所以 BigInteger 的创建一定是不知何故失败了。
截至libcrypto :
The BIGNUM library generally lives in libcrypto, which comes with OpenSSL. Its API is defined in openssl/bn.h. This library exports the BIGNUM type. BIGNUM objects always need to be initialized before use, even if they're statically declared.
因此,请检查您是否可以从您的代码中初始化它或尝试使用较低的 api 版本,因为我对此并不深入。
还要检查 bundle 的库是否与您的 32/64 位平台架构相对应。
另一个猜测:如果 SSL 错误队列不为空,Android 4.4.4 在创建 BigIntegers 时可能存在 [bug] (code.google.com/p/android/issues/detail?id=77262),也许就是这样你遇到了。
关于java - 安卓 BigInteger ArithmeticException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26489195/