Beispiel #1
0
        public void should_correctly_encrypt_bytes()
        {
            var expectedBytes = new byte[] { 0x01, 0x01, 0x01 };
            var givenBytes = new byte[] { 0x0, 0x03, 0x02 };

            var key = new XORKey(new List<byte> { 0x01, 0x02, 0x03 });

            var encryption = new XOREncryption(key);
            var actualBytes = encryption.EncryptBytes(givenBytes);

            Assert.That(actualBytes, Is.EqualTo(expectedBytes));
        }
Beispiel #2
0
        public void should_correctly_encrypt_byte()
        {
            byte expectedByte = 0x02;
            byte givenByte = 0x03;

            var key = new XORKey(new List<byte> { 0x01 });

            var encryption = new XOREncryption(key);
            var actualByte = encryption.EncryptByte(givenByte);

            Assert.That(actualByte, Is.EqualTo(expectedByte));
        }
Beispiel #3
0
        public void should_correctly_read_encryption_flag()
        {
            byte[] encryptionBytes = { 0xFF, 0xFF };
            var key = new XORKey(new List<byte> { 0x01 });

            var mockStream = MockRepository.GenerateMock<Stream>();

            var encryption = new XOREncryption(key);

            mockStream.Stub(e => e.Read(
                                     Arg<byte[]>.Out(encryptionBytes).Dummy,
                                     Arg<int>.Is.Equal(0),
                                     Arg<int>.Is.Equal(2))).Return(0);

            var result = encryption.IsResourceEncrypted(mockStream);

            Assert.That(result, Is.True);
        }