如何在 Android 中包含 Spongy Castle JAR?

发布于 2024-11-27 05:20:45 字数 845 浏览 1 评论 0原文

显然 Spongy Castle 是使用完整版 Bouncy Castle 的 Android 替代方案。

然而,在导入 jar 时,我遇到了各种“无法解析”错误,因为它依赖于 Android 中未包含的包,主要是 javax.mail、javax.activation 和 javax.awt.datatransfer。

那么解决这个问题的最佳方法是什么?对此问题的回复和 表示这些包根本不应该使用,并且这个流行问题不'甚至不考虑寻找一种恢复 AWT 的方法。那么海绵城堡是如何依赖他们的呢? 人们正在使用 Spongy Castle,对吗?

Apparently Spongy Castle is the Android alternative to using a full version of Bouncy Castle.

However, on importing the jar I'm getting all kinds of "cannot be resolved" errors because it relies on packages not included with Android, primarily javax.mail, javax.activation, and javax.awt.datatransfer.

So what's the best way around this? Responses to this question and this indicate those packages shouldn't be used at all, and this popular question doesn't even consider finding a way to get AWT back. So how is Spongy Castle relying on them? People are using Spongy Castle, right?

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

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

发布评论

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

评论(3

深海夜未眠 2024-12-04 05:20:45

如果您使用 gradle,那么您只需在 build.gradle 文件中指定依赖项,如下所示:

dependencies {
     ....
    compile 'com.madgag.spongycastle:core:1.54.0.0'
    compile 'com.madgag.spongycastle:prov:1.54.0.0'
    compile 'com.madgag.spongycastle:pkix:1.54.0.0'
    compile 'com.madgag.spongycastle:pg:1.54.0.0'

    }

您可以找到库的最新版本此处

不要忘记将其作为安全提供程序插入到您的应用程序中。

    static {
    Security.insertProviderAt(new org.spongycastle.jce.provider.BouncyCastleProvider(), 1);
}

If you are using gradle, then you can just specify your dependencies in build.gradle file like this:

dependencies {
     ....
    compile 'com.madgag.spongycastle:core:1.54.0.0'
    compile 'com.madgag.spongycastle:prov:1.54.0.0'
    compile 'com.madgag.spongycastle:pkix:1.54.0.0'
    compile 'com.madgag.spongycastle:pg:1.54.0.0'

    }

You can find out the latest version of the library here.

Don't forget to insert it as a security provider in your app.

    static {
    Security.insertProviderAt(new org.spongycastle.jce.provider.BouncyCastleProvider(), 1);
}
[浮城] 2024-12-04 05:20:45

这是如何在项目中包含 Spongy Castle 的两个非常简单的示例:

自 v1.47 起,Spongy Castle 已被分成单独的子 jar,这些子 jar 完全镜像匹配的 Bouncy Castle 工件(例如sc-light-jdk15on.jarscpg-jdk15on.jar 等),并且务必确保包含全部您正在做的事情所需的海绵城堡罐子。

有关依赖项的完整信息可以在以下位置找到:

http://rtyley.github.com/spongycastle/#downloads< /a>

至少您需要 sc-light-jdk15on.jar (基本轻量级 API 实现),可能还需要 scprov-jdk15on.jarJCE 轻量级 API 的包装器)。如果您使用 Maven,那么所有这些依赖关系管理的事情都会为您处理好。

您在 javax.mailjavax.activation 等上描述的有问题的依赖项表明您可能选择了不正确的 jar(例如 every-single-library-component ) ,而不是“核心提供者”) - 因为 scprov-jdk15on jar 肯定有任何这些奇怪的依赖项,并且在 Android 上运行得很好。

(免责声明,我是 Spongy Castle 的维护者,但我也收到了大量其他用户的成功报告!)

These are two very simple examples of how to include Spongy Castle in a project:

Since v1.47, Spongy Castle has been split into separate sub-jars that exactly mirror the matching Bouncy Castle artifacts (eg sc-light-jdk15on.jar, scpg-jdk15on.jar, etc), and it is important to ensure you include all the Spongy Castle jars required for what you're doing.

Full information on dependencies can be found at:

http://rtyley.github.com/spongycastle/#downloads

At minimum you'll need the sc-light-jdk15on.jar (the base lightweight-API implementation) and probably scprov-jdk15on.jar (the JCE wrapper around the lightweight-API). If you're using Maven then all this dependency-management stuff is taken care of for you.

The problematic dependencies you describe on javax.mail, javax.activation, etc, indicate that you might have chosen an incorrect jar (e.g. the every-single-library-component one, rather than the 'core provider' one) - as the scprov-jdk15on jar definitely doesn't have any of those weird dependencies, and runs happily on Android.

(disclaimer, I'm the maintainer of Spongy Castle, but I've had plenty of success reports from other users too!)

万水千山粽是情ミ 2024-12-04 05:20:45

同时BouncyCastle可以直接使用。在后来的 Android 版本中,内部 BC 包名称已更改,至少包名称冲突不再是问题,但仍然存在问题。有关解决方案,请查看以下内容:https://stackoverflow.com/a/57897224/3351474

In the meanwhile BouncyCastle can be used directly. In later Android versions the internal BC package name has changed and at least the package name collision is not the problem anymore, but there are still issues. For a solution look at this: https://stackoverflow.com/a/57897224/3351474

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