Rijndael and CryptoStream Algorithm: Is it possible to encrypt / decrypt multithreading?

I use Rijndael to encrypt / decrypt some documents. I am wondering if there is an implementation for C # that allows multi-threaded use of the algorithm, either manually or using the framework Parallel? I suppose this is not possible because it is based on threads ( CryptoStream), but still worth asking for it. Does anyone have sources for verification?

0
source share
1 answer

I have never heard of multithreaded CryptoStream in .NET, however, I think it depends on your encryption mode. If the ECB encryption mode, of course, you can easily make it multithreaded manually using Parallel.For or ForEach. With CBC or any other closed-loop encryption mode, it is unlikely that you can make it parallel if you do not use multiple initialization vectors. For ECB mode:

  • Divide your data in arrays with several bytes (let's say you encrypt 1280 bytes with 10 streams that divide the data into 10 byte arrays that contain 0..127 bytes, 128..255 bytes, etc., each array should contain an integer number of blocks).
  • Parallel.For ForEach 10- (, List < byte [] > , Parallel.ForEach ).
  • 10 / Rijndael SymmetricAlgorithm.CreateEncryptor/SymmetricAlgorithm.CreateDecryptor
  • .
  • 1000 .

, - CryptoStream, API .

+1

Source: https://habr.com/ru/post/1667228/


All Articles