2
0

TripleDesCipherTest.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233
  1. using System.Linq;
  2. using Microsoft.VisualStudio.TestTools.UnitTesting;
  3. using Renci.SshNet.Security.Cryptography.Ciphers;
  4. using Renci.SshNet.Security.Cryptography.Ciphers.Modes;
  5. using Renci.SshNet.Tests.Common;
  6. namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers
  7. {
  8. /// <summary>
  9. /// Implements 3DES cipher algorithm.
  10. /// </summary>
  11. [TestClass]
  12. public class TripleDesCipherTest : TestBase
  13. {
  14. [TestMethod]
  15. public void Test_Cipher_3DES_CBC()
  16. {
  17. 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 };
  18. 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 };
  19. var iv = new byte[] { 0xc0, 0x75, 0xf2, 0x26, 0x0a, 0x2a, 0x42, 0x96 };
  20. 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 };
  21. var testCipher = new TripleDesCipher(key, new CbcCipherMode(iv), null);
  22. var r = testCipher.Encrypt(input);
  23. if (!r.SequenceEqual(output))
  24. {
  25. Assert.Fail("Invalid encryption");
  26. }
  27. }
  28. }
  29. }