自 Android 2.3 起 PSS 签名验证失败

发布于 2024-11-26 17:20:58 字数 727 浏览 3 评论 0原文

在我的应用程序中,我使用 SHA1 和 RSA 验证通过概率签名方案 (PSS) 签名的文件的数字签名。签名是在 BouncyCastle 的帮助下在 J2SE 中创建的。

在 Android 应用程序中,此验证到目前为止运行良好(例如 2.1、2.2)。在 Android 2.3 设备/模拟器上测试应用程序时,我收到 NoSuchAlgorithmException。

NoSuchAlgorithmException: Signature SHA1withRSA/PSS implementation not found 

我用于验证签名的相关代码如下:

Signature signature = Signature.getInstance("SHA1withRSA/PSS", "BC");
signature.setParameter(new PSSParameterSpec(64));
signature.initVerify(thePublicKey);
signature.update(theMessage.getBytes());
boolean signatureIsValid = signature.verify(theSignature);

自Android 2.2以来发生了什么,为什么从“BC”提供程序中删除了算法“SHA1withRSA/PSS”?

有人有替代方案(最多适用于所有 Android 版本)吗?

谢谢你!

In my app, I am verifying the digital signature of a file signed with the Probabilistic Signature Scheme (PSS) using SHA1 and RSA. The signatures are created in J2SE with the help of BouncyCastle.

In the Android app this verification worked fine so far (e.g., 2.1, 2.2). When testing the app on Android 2.3 devices/simulator I receive a NoSuchAlgorithmException.

NoSuchAlgorithmException: Signature SHA1withRSA/PSS implementation not found 

The relevant code I use for verifying the signature is the following:

Signature signature = Signature.getInstance("SHA1withRSA/PSS", "BC");
signature.setParameter(new PSSParameterSpec(64));
signature.initVerify(thePublicKey);
signature.update(theMessage.getBytes());
boolean signatureIsValid = signature.verify(theSignature);

What happened since Android 2.2, why was the algorithm "SHA1withRSA/PSS" removed from the "BC" provider?

Does anybody have a alternative (which at best works with all Android versions)?

Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

離人涙 2024-12-03 17:20:58

我设法让 PSS 签名正常工作的唯一方法是将我的签名提供程序切换到 Spongy Castle。

快速操作方法:

  1. 下载 SpongyCastle JAR 文件并将其放入您的 libs/ 项目文件夹中。我使用了 APG 的 JAR: http://code.google.com/p/android-privacy-guard/source/browse/lib/bcprov-jdk16-146.jar?name=apg_service
  2. 如果使用Eclipse,通过转到其属性 -> 将文件添加到您的项目中Java 构建路径 ->图书馆 ->添加 JAR...->选择文件
  3. 在签名类中的某处添加以下行

    静态{
    Security.addProvider(new org.spongycastle.jce.provider.BouncyCastleProvider());
    }

  4. 在 getInstance() 中将 BC 替换为 SC

    Signaturesignature = Signature.getInstance("SHA1withRSA/PSS", "SC");

缺点:您的二进制文件将包含额外的 1.5mb。

The only way I managed to get PSS Signatures working was by switching my signature provider to Spongy Castle.

Quick how-to:

  1. Download the SpongyCastle JAR file and put it in your libs/ project folder. I used the JAR from APG: http://code.google.com/p/android-privacy-guard/source/browse/lib/bcprov-jdk16-146.jar?name=apg_service
  2. If using Eclipse, add the file to your project by going to its properties -> Java Build Path -> Libraries -> Add JARs... -> select the file
  3. Add the following line somewhere in your signing class

    static {
    Security.addProvider(new org.spongycastle.jce.provider.BouncyCastleProvider());
    }

  4. Replace your BC with SC in getInstance()

    Signature signature = Signature.getInstance("SHA1withRSA/PSS", "SC");

The downside: Your binary will include a bonus 1.5mb.

倾听心声的旋律 2024-12-03 17:20:58

我面临着同样的问题。将 Bouncy Castle 移植到 Android 上,自己动手是唯一的方法吗?

I'm facing the same problem. Is do-it-yourself-way by porting Bouncy Castle to Android the only way?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文