11

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 を使用してこのような状況に遭遇した場合はお知らせください。

4

2 に答える 2

13

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.

于 2008-09-08T11:23:51.583 に答える
0

J2ME バージョンはスレッドセーフではありません。

于 2010-12-03T12:59:14.310 に答える