Android 4.4 当 signing/checking 签名使用 SpongyCastle 时引发 UnsupportedOperationException

UnsupportedOperationException raised on Android 4.4 when signing/checking signature using SpongyCastle

以下代码在 Android 4.4 上执行时会抛出 UnsupportedOperationException,但它在 Android 5 和 6 上运行良好(已在设备和模拟器上测试)。 setParameter 抛出异常。

    Signature signature = Signature.getInstance("SHA256withRSA/PSS", "SC");
    PSSParameterSpec spec1 = new PSSParameterSpec("SHA-256", "MGF1", new MGF1ParameterSpec("SHA-256"), 32, 1);
    signature.setParameter(spec1);

我正在使用海绵城堡可以使用SHA256withRSA/PSS。

知道为什么吗?

在 android 开源项目问题 63139 中记录了这个确切的错误。对于低于 5.0 的任何 android 版本,都会发生这种情况。具体来说,"The implementation of private static SignatureImpl class(line 590) lacks one of the engineSetParameter implementations."请阅读问题报告以获取更多信息。

https://code.google.com/p/android/issues/detail?id=63139