TripleDesCipherTest.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. using Microsoft.VisualStudio.TestTools.UnitTesting;
  2. using Renci.SshNet.Security.Cryptography.Ciphers;
  3. using Renci.SshNet.Security.Cryptography.Ciphers.Modes;
  4. using Renci.SshNet.Tests.Common;
  5. using Renci.SshNet.Tests.Properties;
  6. using System.Linq;
  7. namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers
  8. {
  9. /// <summary>
  10. /// Implements 3DES cipher algorithm.
  11. /// </summary>
  12. [TestClass]
  13. public class TripleDesCipherTest : TestBase
  14. {
  15. [TestMethod]
  16. public void Test_Cipher_3DES_CBC()
  17. {
  18. var input = new byte[] { 0x00, 0x00, 0x00, 0x1c, 0x0a, 0x05, 0x00, 0x00, 0x00, 0x0c, 0x73, 0x73, 0x68, 0x2d, 0x75, 0x73, 0x65, 0x72, 0x61, 0x75, 0x74, 0x68, 0x72, 0x4e, 0x06, 0x08, 0x28, 0x2d, 0xaa, 0xe2, 0xb3, 0xd9 };
  19. var key = new byte[] { 0x78, 0xf6, 0xc6, 0xbb, 0x57, 0x03, 0x69, 0xca, 0xba, 0x31, 0x18, 0x2f, 0x2f, 0x4c, 0x35, 0x34, 0x64, 0x06, 0x85, 0x30, 0xbe, 0x78, 0x60, 0xb3 };
  20. var iv = new byte[] { 0xc0, 0x75, 0xf2, 0x26, 0x0a, 0x2a, 0x42, 0x96 };
  21. var output = new byte[] { 0x28, 0x77, 0x2f, 0x07, 0x3e, 0xc2, 0x27, 0xa6, 0xdb, 0x36, 0x4d, 0xc6, 0x7a, 0x26, 0x7a, 0x38, 0xe6, 0x54, 0x0b, 0xab, 0x07, 0x87, 0xf0, 0xa4, 0x73, 0x1f, 0xde, 0xe6, 0x81, 0x1d, 0x4b, 0x4b };
  22. var testCipher = new Renci.SshNet.Security.Cryptography.Ciphers.TripleDesCipher(key, new Renci.SshNet.Security.Cryptography.Ciphers.Modes.CbcCipherMode(iv), null);
  23. var r = testCipher.Encrypt(input);
  24. if (!r.SequenceEqual(output))
  25. Assert.Fail("Invalid encryption");
  26. }
  27. [TestMethod]
  28. [Owner("olegkap")]
  29. [TestCategory("Cipher")]
  30. [TestCategory("integration")]
  31. public void Test_Cipher_TripleDESCBC_Connection()
  32. {
  33. var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD);
  34. connectionInfo.Encryptions.Clear();
  35. connectionInfo.Encryptions.Add("3des-cbc", new CipherInfo(192, (key, iv) => { return new TripleDesCipher(key, new CbcCipherMode(iv), null); }));
  36. using (var client = new SshClient(connectionInfo))
  37. {
  38. client.Connect();
  39. client.Disconnect();
  40. }
  41. }
  42. /// <summary>
  43. ///A test for TripleDesCipher Constructor
  44. ///</summary>
  45. [TestMethod]
  46. [Ignore] // placeholder for actual test
  47. public void TripleDesCipherConstructorTest()
  48. {
  49. byte[] key = null; // TODO: Initialize to an appropriate value
  50. CipherMode mode = null; // TODO: Initialize to an appropriate value
  51. CipherPadding padding = null; // TODO: Initialize to an appropriate value
  52. TripleDesCipher target = new TripleDesCipher(key, mode, padding);
  53. Assert.Inconclusive("TODO: Implement code to verify target");
  54. }
  55. /// <summary>
  56. ///A test for DecryptBlock
  57. ///</summary>
  58. [TestMethod]
  59. [Ignore] // placeholder for actual test
  60. public void DecryptBlockTest()
  61. {
  62. byte[] key = null; // TODO: Initialize to an appropriate value
  63. CipherMode mode = null; // TODO: Initialize to an appropriate value
  64. CipherPadding padding = null; // TODO: Initialize to an appropriate value
  65. TripleDesCipher target = new TripleDesCipher(key, mode, padding); // TODO: Initialize to an appropriate value
  66. byte[] inputBuffer = null; // TODO: Initialize to an appropriate value
  67. int inputOffset = 0; // TODO: Initialize to an appropriate value
  68. int inputCount = 0; // TODO: Initialize to an appropriate value
  69. byte[] outputBuffer = null; // TODO: Initialize to an appropriate value
  70. int outputOffset = 0; // TODO: Initialize to an appropriate value
  71. int expected = 0; // TODO: Initialize to an appropriate value
  72. int actual;
  73. actual = target.DecryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset);
  74. Assert.AreEqual(expected, actual);
  75. Assert.Inconclusive("Verify the correctness of this test method.");
  76. }
  77. /// <summary>
  78. ///A test for EncryptBlock
  79. ///</summary>
  80. [TestMethod]
  81. [Ignore] // placeholder for actual test
  82. public void EncryptBlockTest()
  83. {
  84. byte[] key = null; // TODO: Initialize to an appropriate value
  85. CipherMode mode = null; // TODO: Initialize to an appropriate value
  86. CipherPadding padding = null; // TODO: Initialize to an appropriate value
  87. TripleDesCipher target = new TripleDesCipher(key, mode, padding); // TODO: Initialize to an appropriate value
  88. byte[] inputBuffer = null; // TODO: Initialize to an appropriate value
  89. int inputOffset = 0; // TODO: Initialize to an appropriate value
  90. int inputCount = 0; // TODO: Initialize to an appropriate value
  91. byte[] outputBuffer = null; // TODO: Initialize to an appropriate value
  92. int outputOffset = 0; // TODO: Initialize to an appropriate value
  93. int expected = 0; // TODO: Initialize to an appropriate value
  94. int actual;
  95. actual = target.EncryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset);
  96. Assert.AreEqual(expected, actual);
  97. Assert.Inconclusive("Verify the correctness of this test method.");
  98. }
  99. }
  100. }