CipherInfo.cs 939 B

12345678910111213141516171819202122232425262728
  1. using System;
  2. using System.Diagnostics.Contracts;
  3. using System.Linq;
  4. using System.Security.Cryptography;
  5. namespace FxSsh.Algorithms
  6. {
  7. public class CipherInfo
  8. {
  9. public CipherInfo(SymmetricAlgorithm algorithm, int keySize, CipherModeEx mode)
  10. {
  11. Contract.Requires(algorithm != null);
  12. Contract.Requires(algorithm.LegalKeySizes.Any(x =>
  13. x.MinSize <= keySize && keySize <= x.MaxSize && keySize % x.SkipSize == 0));
  14. algorithm.KeySize = keySize;
  15. KeySize = algorithm.KeySize;
  16. BlockSize = algorithm.BlockSize;
  17. Cipher = (key, vi, isEncryption) => new EncryptionAlgorithm(algorithm, keySize, mode, key, vi, isEncryption);
  18. }
  19. public int KeySize { get; private set; }
  20. public int BlockSize { get; private set; }
  21. public Func<byte[], byte[], bool, EncryptionAlgorithm> Cipher { get; private set; }
  22. }
  23. }