-
Notifications
You must be signed in to change notification settings - Fork 20
MultiThreading
Instances of Encryptor
and Decryptor
and safe for use by multiple threads to use at once to encrypt or decrypt messages -- as long as you don't change any of the instances configuration settings (including adding or removing keys to the instance's keyring, or modifying the properties of keys or subkeys). Use a different instance for each thread if you may modify the instance's properties.
If you do use a different Encryptor
or Decryptor
per thread, you can optimize their memory usage by subclassing both, and overriding their getCopyBuffer()
method to return the same byte array every time the method is called. By default, this method will return a new byte array (up to 64k in size) for each message encrypted or decrypted.
You can further optimize your Encryptor
subclass to similarly override its getEncryptionBuffer()
, getCompressionBuffer()
, and getLiteralBuffer()
classes. These methods also by default will return a new byte array each time they are called, also up to 64k in size. Note, however, that the underlying Bouncy Castle implementation will only actually use the smallest power of 2 that fits inside these arrays (ie it will only use 512 bytes of a 1000-byte buffer). Also these buffers must be between 2^9 and 2^30 bytes in size (inclusive).