CipherBlowFish.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Security.Cryptography;
  6. using Renci.SshNet.Security.Cryptography;
  7. namespace Renci.SshNet.Security
  8. {
  9. /// <summary>
  10. /// Represents base class for AES based encryption.
  11. /// </summary>
  12. public class CipherBlowfish : Cipher
  13. {
  14. /// <summary>
  15. /// Gets algorithm name.
  16. /// </summary>
  17. public override string Name
  18. {
  19. get { return "blowfish-cbc"; }
  20. }
  21. /// <summary>
  22. /// Gets or sets the key size, in bits, of the secret key used by the cipher.
  23. /// </summary>
  24. /// <value>
  25. /// The key size, in bits.
  26. /// </value>
  27. public override int KeySize
  28. {
  29. get
  30. {
  31. return 16 * 8;
  32. }
  33. }
  34. /// <summary>
  35. /// Gets or sets the block size, in bits, of the cipher operation.
  36. /// </summary>
  37. /// <value>
  38. /// The block size, in bits.
  39. /// </value>
  40. public override int BlockSize
  41. {
  42. get
  43. {
  44. return 8;
  45. }
  46. }
  47. /// <summary>
  48. /// Creates the encryptor.
  49. /// </summary>
  50. /// <returns></returns>
  51. protected override ModeBase CreateEncryptor()
  52. {
  53. return new CbcMode(new BlowfishCipher(this.Key.Take(this.KeySize / 8).ToArray(), this.Vector.Take(this.BlockSize).ToArray()));
  54. }
  55. /// <summary>
  56. /// Creates the decryptor.
  57. /// </summary>
  58. /// <returns></returns>
  59. protected override ModeBase CreateDecryptor()
  60. {
  61. return new CbcMode(new BlowfishCipher(this.Key.Take(this.KeySize / 8).ToArray(), this.Vector.Take(this.BlockSize).ToArray()));
  62. }
  63. }
  64. }