2
0

TestCipher.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Microsoft.VisualStudio.TestTools.UnitTesting;
  6. using Renci.SshNet.Security;
  7. using Renci.SshNet.Tests.Properties;
  8. using Renci.SshNet.Security.Cryptography.Ciphers;
  9. using Renci.SshNet.Security.Cryptography.Ciphers.Modes;
  10. namespace Renci.SshNet.Tests.Security
  11. {
  12. [TestClass]
  13. public class TestCipher
  14. {
  15. [TestMethod]
  16. [Owner("olegkap")]
  17. [TestCategory("Cipher")]
  18. public void Test_Cipher_TripleDESCBC_Connection()
  19. {
  20. var connectionInfo = new PasswordConnectionInfo(Resources.HOST, 22, Resources.USERNAME, Resources.PASSWORD);
  21. connectionInfo.Encryptions.Clear();
  22. connectionInfo.Encryptions.Add("3des-cbc", new CipherInfo(192, (key, iv) => { return new TripleDesCipher(key, new CbcCipherMode(iv), null); }));
  23. using (var client = new SshClient(connectionInfo))
  24. {
  25. client.Connect();
  26. client.Disconnect();
  27. }
  28. }
  29. [TestMethod]
  30. [Owner("olegkap")]
  31. [TestCategory("Cipher")]
  32. public void Test_Cipher_AEes128CBC_Connection()
  33. {
  34. var connectionInfo = new PasswordConnectionInfo(Resources.HOST, 22, Resources.USERNAME, Resources.PASSWORD);
  35. connectionInfo.Encryptions.Clear();
  36. connectionInfo.Encryptions.Add("aes128-cbc", new CipherInfo(128, (key, iv) => { return new AesCipher(key, new CbcCipherMode(iv), null); }));
  37. using (var client = new SshClient(connectionInfo))
  38. {
  39. client.Connect();
  40. client.Disconnect();
  41. }
  42. }
  43. [TestMethod]
  44. [Owner("olegkap")]
  45. [TestCategory("Cipher")]
  46. public void Test_Cipher_Aes192CBC_Connection()
  47. {
  48. var connectionInfo = new PasswordConnectionInfo(Resources.HOST, 22, Resources.USERNAME, Resources.PASSWORD);
  49. connectionInfo.Encryptions.Clear();
  50. connectionInfo.Encryptions.Add("aes192-cbc", new CipherInfo(192, (key, iv) => { return new AesCipher(key, new CbcCipherMode(iv), null); }));
  51. using (var client = new SshClient(connectionInfo))
  52. {
  53. client.Connect();
  54. client.Disconnect();
  55. }
  56. }
  57. [TestMethod]
  58. [Owner("olegkap")]
  59. [TestCategory("Cipher")]
  60. public void Test_Cipher_Aes256CBC_Connection()
  61. {
  62. var connectionInfo = new PasswordConnectionInfo(Resources.HOST, 22, Resources.USERNAME, Resources.PASSWORD);
  63. connectionInfo.Encryptions.Clear();
  64. connectionInfo.Encryptions.Add("aes256-cbc", new CipherInfo(256, (key, iv) => { return new AesCipher(key, new CbcCipherMode(iv), null); }));
  65. using (var client = new SshClient(connectionInfo))
  66. {
  67. client.Connect();
  68. client.Disconnect();
  69. }
  70. }
  71. [TestMethod]
  72. [Owner("olegkap")]
  73. [TestCategory("Cipher")]
  74. public void Test_Cipher_Aes128CTR_Connection()
  75. {
  76. var connectionInfo = new PasswordConnectionInfo(Resources.HOST, 22, Resources.USERNAME, Resources.PASSWORD);
  77. connectionInfo.Encryptions.Clear();
  78. connectionInfo.Encryptions.Add("aes128-ctr", new CipherInfo(128, (key, iv) => { return new AesCipher(key, new CtrCipherMode(iv), null); }));
  79. using (var client = new SshClient(connectionInfo))
  80. {
  81. client.Connect();
  82. client.Disconnect();
  83. }
  84. }
  85. [TestMethod]
  86. [Owner("olegkap")]
  87. [TestCategory("Cipher")]
  88. public void Test_Cipher_Aes192CTR_Connection()
  89. {
  90. var connectionInfo = new PasswordConnectionInfo(Resources.HOST, 22, Resources.USERNAME, Resources.PASSWORD);
  91. connectionInfo.Encryptions.Clear();
  92. connectionInfo.Encryptions.Add("aes192-ctr", new CipherInfo(192, (key, iv) => { return new AesCipher(key, new CtrCipherMode(iv), null); }));
  93. using (var client = new SshClient(connectionInfo))
  94. {
  95. client.Connect();
  96. client.Disconnect();
  97. }
  98. }
  99. [TestMethod]
  100. [Owner("olegkap")]
  101. [TestCategory("Cipher")]
  102. public void Test_Cipher_Aes256CTR_Connection()
  103. {
  104. var connectionInfo = new PasswordConnectionInfo(Resources.HOST, 22, Resources.USERNAME, Resources.PASSWORD);
  105. connectionInfo.Encryptions.Clear();
  106. connectionInfo.Encryptions.Add("aes256-ctr", new CipherInfo(256, (key, iv) => { return new AesCipher(key, new CtrCipherMode(iv), null); }));
  107. using (var client = new SshClient(connectionInfo))
  108. {
  109. client.Connect();
  110. client.Disconnect();
  111. }
  112. }
  113. [TestMethod]
  114. [Owner("olegkap")]
  115. [TestCategory("Cipher")]
  116. public void Test_Cipher_BlowfishCBC_Connection()
  117. {
  118. var connectionInfo = new PasswordConnectionInfo(Resources.HOST, 22, Resources.USERNAME, Resources.PASSWORD);
  119. connectionInfo.Encryptions.Clear();
  120. connectionInfo.Encryptions.Add("blowfish-cbc", new CipherInfo(128, (key, iv) => { return new BlowfishCipher(key, new CbcCipherMode(iv), null); }));
  121. using (var client = new SshClient(connectionInfo))
  122. {
  123. client.Connect();
  124. client.Disconnect();
  125. }
  126. }
  127. [TestMethod]
  128. [Owner("olegkap")]
  129. [TestCategory("Cipher")]
  130. public void Test_Cipher_Cast128CBC_Connection()
  131. {
  132. var connectionInfo = new PasswordConnectionInfo(Resources.HOST, 22, Resources.USERNAME, Resources.PASSWORD);
  133. connectionInfo.Encryptions.Clear();
  134. connectionInfo.Encryptions.Add("cast128-cbc", new CipherInfo(128, (key, iv) => { return new CastCipher(key, new CbcCipherMode(iv), null); }));
  135. using (var client = new SshClient(connectionInfo))
  136. {
  137. client.Connect();
  138. client.Disconnect();
  139. }
  140. }
  141. }
  142. }