TestCast.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Microsoft.VisualStudio.TestTools.UnitTesting;
  6. namespace Renci.SshNet.Tests.Security.Cryptography
  7. {
  8. [TestClass]
  9. public class TestCast
  10. {
  11. [TestMethod]
  12. public void Test_Cast_128_CBC_NoPadding()
  13. {
  14. var key = new byte[] { 0xd3, 0x2b, 0x5e, 0x1e, 0xfe, 0x99, 0x02, 0xc2, 0x85, 0x85, 0x49, 0xb5, 0x29, 0x4a, 0x8c, 0x44 };
  15. var iv = new byte[] { 0x76, 0xc2, 0xd7, 0x95, 0x80, 0x39, 0xd1, 0xb7 };
  16. 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, 0xc8, 0xdc, 0xcb, 0x70, 0xb0, 0x53, 0xfe, 0xd5, 0x80, 0xf7 };
  17. var correctEncoding = new byte[] { 0x90, 0x1c, 0x5b, 0x18, 0xc1, 0xe2, 0xce, 0x96, 0xe4, 0x55, 0x13, 0xce, 0x1d, 0x84, 0xf8, 0xb0, 0xb3, 0x22, 0x73, 0x06, 0xf6, 0xf9, 0x4b, 0x06, 0xf9, 0x07, 0x38, 0x6e, 0xea, 0x0d, 0x6a, 0xb8 };
  18. var encodedResult = new byte[input.Length];
  19. var decodedResult = new byte[input.Length];
  20. var cipher = new Renci.SshNet.Security.Cryptography.Cast(128);
  21. cipher.Mode = System.Security.Cryptography.CipherMode.CBC;
  22. var enc = cipher.CreateEncryptor(key, iv);
  23. enc.TransformBlock(input, 0, input.Length, encodedResult, 0);
  24. var dec = cipher.CreateDecryptor(key, iv);
  25. dec.TransformBlock(encodedResult, 0, encodedResult.Length, decodedResult, 0);
  26. Assert.IsTrue(encodedResult.IsEqualTo(correctEncoding));
  27. Assert.IsTrue(decodedResult.IsEqualTo(input));
  28. }
  29. }
  30. }