Bouncy Castle API 线程安全吗?

发布于 2024-07-05 01:30:59 字数 488 浏览 6 评论 0原文

Bouncy Castle API 线程安全吗? 特别是,

org.bouncycastle.crypto.paddings.PaddedBufferedBlockCipher
org.bouncycastle.crypto.paddings.PKCS7Padding
org.bouncycastle.crypto.engines.AESFastEngine
org.bouncycastle.crypto.modes.CBCBlockCipher

我计划在我的应用程序中编写一个单例 Spring bean 以提供基本级别的加密支持。 由于它是一个 Web 应用程序,因此多个线程同时访问该组件的机会更大。 因此,胎面安全在这里至关重要。

如果您在使用 Bouncy Castle 时遇到过此类情况,请告诉我。

Is Bouncy Castle API Thread Safe ? Especially,

org.bouncycastle.crypto.paddings.PaddedBufferedBlockCipher
org.bouncycastle.crypto.paddings.PKCS7Padding
org.bouncycastle.crypto.engines.AESFastEngine
org.bouncycastle.crypto.modes.CBCBlockCipher

I am planning to write a singleton Spring bean for basic level cryptography support in my app. Since it is a web application, there are greater chances of multiple threads accessing this component at a time. So tread safety is essential here.

Please let me know if you have come across such situations using Bouncy Castle.

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

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

发布评论

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

评论(2

苏佲洛 2024-07-12 01:30:59

J2ME版本不是线程安全的。

The J2ME version is not thread safe.

素染倾城色 2024-07-12 01:30:59

API/代码是否线程安全并不重要。 CBC 加密本身不是线程安全的。
一些术语 -

E(X) = Enctrypt message X
D(X) = Dectrypt X. (Note that D(E(X)) = X)
IV = Initialization vector. A random sequence to bootstrap the CBC algorithm
CBC = Cipher block chaining.

一个非常简单的 CBC 实现可能如下所示:
P1、P2、P3 = 纯文本消息

1. Generate an IV, just random bits.
2. Calculate E( P1 xor IV) call this C1
3. Calculate E( P2 xor C1) call this C2
4. Calculate E( P3 xor C2) call this C3.

如您所见,加密 P1、P2 和 P3(按此顺序)的结果与加密 P2、P1 和 P3(按此顺序)的结果不同。

因此,在 CBC 实现中,顺序很重要。 根据定义,任何顺序很重要的算法都不能是线程安全的。

您可以创建一个提供加密对象的单例工厂,但您不能相信它们是线程安全的。

It really does not matter if the API/Code is thread safe. CBC encryption in itself is not thread safe.
Some terminology -

E(X) = Enctrypt message X
D(X) = Dectrypt X. (Note that D(E(X)) = X)
IV = Initialization vector. A random sequence to bootstrap the CBC algorithm
CBC = Cipher block chaining.

A really simple CBC implementation can look like:
P1, P2, P3 = Plain text messages

1. Generate an IV, just random bits.
2. Calculate E( P1 xor IV) call this C1
3. Calculate E( P2 xor C1) call this C2
4. Calculate E( P3 xor C2) call this C3.

As you can see, the result of encrypting P1, P2 and P3 (in that order) is different from encrypting P2, P1 and P3 (in that order).

So, in a CBC implementation, order is important. Any algorithm where order is important can not, by definition, be thread safe.

You can make a Singleton factory that delivers encryption objects, but you cant trust them to be thread safe.

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