| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 | using System;using System.Collections.Generic;using System.Linq;using System.Text;using Microsoft.VisualStudio.TestTools.UnitTesting;namespace Renci.SshClient.Tests.Security.Cryptography{    [TestClass]    public class TestBlowfish    {        [TestMethod]        public void Test_Blowfish_CBC_NoPadding()        {            var key = new byte[] { 0xe0, 0xb1, 0xb3, 0xbc, 0xa7, 0xe2, 0x2b, 0xca, 0xf0, 0xc1, 0xc7, 0xaa, 0x93, 0x50, 0xb7, 0x72 };            var iv = new byte[] { 0x0b, 0x7c, 0xf1, 0x33, 0xe0, 0x4a, 0x64, 0x30, 0x37, 0x08, 0x83, 0xd3, 0x56, 0x04, 0x12, 0xd9, 0x88, 0xd0, 0x89, 0xf2, 0xe9, 0xd9, 0x25, 0xea, 0x81, 0x64, 0x5b, 0x03, 0xf2, 0xd3, 0xd5, 0x11 };            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, 0x4c, 0x78, 0x42, 0xbb, 0x1a, 0x87, 0x5e, 0xba, 0xfc, 0x9e };            var correctEncoding = new byte[] { 0x42, 0x36, 0xf4, 0xe9, 0xfd, 0x47, 0x97, 0x43, 0x11, 0x0a, 0x52, 0xf6, 0x1e, 0x7b, 0x78, 0xc0, 0x34, 0x73, 0x58, 0xce, 0x0c, 0xd9, 0x20, 0x97, 0x76, 0x03, 0xb0, 0x2d, 0x4b, 0xce, 0x33, 0x8f };            var encodedResult = new byte[input.Length];            var decodedResult = new byte[input.Length];            var cipher = new Renci.SshClient.Security.Cryptography.Blowfish();            cipher.Mode = System.Security.Cryptography.CipherMode.CBC;            var enc = cipher.CreateEncryptor(key, iv);            enc.TransformBlock(input, 0, input.Length, encodedResult, 0);            var dec = cipher.CreateDecryptor(key, iv);            dec.TransformBlock(encodedResult, 0, encodedResult.Length, decodedResult, 0);            Assert.IsTrue(encodedResult.IsEqualTo(correctEncoding));            Assert.IsTrue(decodedResult.IsEqualTo(input));        }        [TestMethod]        public void Test_Blowfish_128_CBC_NoPadding()        {            var key = new byte[] { 0xe0, 0xb1, 0xb3, 0xbc, 0xa7, 0xe2, 0x2b, 0xca, 0xf0, 0xc1, 0xc7, 0xaa, 0x93, 0x50, 0xb7, 0x72 };            var iv = new byte[] { 0x0b, 0x7c, 0xf1, 0x33, 0xe0, 0x4a, 0x64, 0x30, 0x37, 0x08, 0x83, 0xd3, 0x56, 0x04, 0x12, 0xd9, 0x88, 0xd0, 0x89, 0xf2, 0xe9, 0xd9, 0x25, 0xea, 0x81, 0x64, 0x5b, 0x03, 0xf2, 0xd3, 0xd5, 0x11 };            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, 0x4c, 0x78, 0x42, 0xbb, 0x1a, 0x87, 0x5e, 0xba, 0xfc, 0x9e };            var correctEncoding = new byte[] { 0x42, 0x36, 0xf4, 0xe9, 0xfd, 0x47, 0x97, 0x43, 0x11, 0x0a, 0x52, 0xf6, 0x1e, 0x7b, 0x78, 0xc0, 0x34, 0x73, 0x58, 0xce, 0x0c, 0xd9, 0x20, 0x97, 0x76, 0x03, 0xb0, 0x2d, 0x4b, 0xce, 0x33, 0x8f };            var encodedResult = new byte[input.Length];            var decodedResult = new byte[input.Length];            var cipher = new Renci.SshClient.Security.Cryptography.Blowfish(128);            cipher.Mode = System.Security.Cryptography.CipherMode.CBC;            var enc = cipher.CreateEncryptor(key, iv);            enc.TransformBlock(input, 0, input.Length, encodedResult, 0);            var dec = cipher.CreateDecryptor(key, iv);            dec.TransformBlock(encodedResult, 0, encodedResult.Length, decodedResult, 0);            Assert.IsTrue(encodedResult.IsEqualTo(correctEncoding));            Assert.IsTrue(decodedResult.IsEqualTo(input));        }    }}
 |