Android 在设备上找不到DecodeChex方法,但正在Emulator上工作

Android 在设备上找不到DecodeChex方法,但正在Emulator上工作,android,android-emulator,apache-commons,Android,Android Emulator,Apache Commons,我正在进行RSA加密项目,需要使用Apache commons codec中的方法,即: 十六进制编码十六进制(字节[]) 十六进制。解码十六进制(字符串) 这两种方法在Android emulator上都运行良好,但在设备上它将返回NoSuchMethodError public String RSADecrypt(final String message) { try { Cipher cipher = Cipher.getInstance("RS

我正在进行RSA加密项目,需要使用Apache commons codec中的方法,即:

  • 十六进制编码十六进制(字节[])
  • 十六进制。解码十六进制(字符串)
这两种方法在Android emulator上都运行良好,但在设备上它将返回NoSuchMethodError

public String RSADecrypt(final String message) {
        try {
            Cipher cipher = Cipher.getInstance("RSA");
            cipher.init(Cipher.DECRYPT_MODE, getPrivateKey());
            byte[] decryptedBytes = cipher.doFinal(Hex.decodeHex(message));
            return new String(decryptedBytes);
        } catch (BadPaddingException e) {
            e.printStackTrace();
        } catch (IllegalBlockSizeException e) {
            e.printStackTrace();
        } catch (NoSuchPaddingException e) {
            e.printStackTrace();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (InvalidKeyException e) {
            e.printStackTrace();
        } catch (DecoderException e) {
            e.printStackTrace();
        }
        return "";
    }
  • 我的模拟器在馅饼、奥利奥和牛轧糖上运行
  • 我的设备使用牛轧糖和棉花糖

一些Android版本包含较旧版本的Apache commons编解码器库(1.3),其中的
decodeChex(String)
方法尚不存在。尝试调用
decodechx(char[])
。例如,修改您的代码如下:

byte[] decryptedBytes = cipher.doFinal(Hex.decodeHex(message.toCharArray()));

这应该适用于commons codec v1.3。

一些Android版本包含Apache commons codec库(1.3)的旧版本,其中
decodeChex(String)
方法尚不存在。尝试调用
decodechx(char[])
。例如,修改您的代码如下:

byte[] decryptedBytes = cipher.doFinal(Hex.decodeHex(message.toCharArray()));

这应该适用于commons codec v1.3。

谢谢,它可以工作。所以这个问题与操作系统问题有关。是的。据我所知,Android本身包含commons编解码器库,即使您的应用程序包含相同库的更新版本,也会使用该库。通常使用的版本是1.3。另外,如果您对答案满意,请您将其标记为已接受,好吗?谢谢,谢谢,它起作用了。所以这个问题与操作系统问题有关。是的。据我所知,Android本身包含commons编解码器库,即使您的应用程序包含相同库的更新版本,也会使用该库。通常使用的版本是1.3。另外,如果您对答案满意,请您将其标记为已接受,好吗?谢谢