Brunet.Security.SymmetricEncryption.SymmetricEncryption C# (CSharp) Method

SymmetricEncryption() public method

Creates a new SymmetricEncryption handler for the passed in SymmetricAlgorithm.
public SymmetricEncryption ( SymmetricAlgorithm Algorithm ) : Brunet
Algorithm System.Security.Cryptography.SymmetricAlgorithm
return Brunet
    public SymmetricEncryption(SymmetricAlgorithm Algorithm)
    {
      if(Algorithm.Mode != CipherMode.CBC) {
        throw new Exception("SymmetricEncryption requires the symmetric algorithm to use CBC.");
      }

      rng = new RNGCryptoServiceProvider();
      _sa = Algorithm;
      // We take care of PKCS7 padding here due to issues in the underlying implementations...
      _sa.Padding = PaddingMode.None;
      BlockSizeByte = _sa.BlockSize / 8;
      // Match the same size as our Window size...
      _decryptors = new Brunet.Collections.Cache(64);
      _enc_iv = new byte[BlockSizeByte];
      rng.GetBytes(_enc_iv);
      _enc = _sa.CreateEncryptor(_sa.Key, _enc_iv);
      _temp = new byte[BlockSizeByte];
    }