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)); }
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)); }
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); }
public static void RegisterSimpleXOREncryption() { var defaultKey = new XORKey(new List<byte> { 0x01 }); EncryptionFactory.RegisterEncryption(new XOREncryption(defaultKey)); }
private IEncryption CreateDefaultEncryption() { // Rotates key on every action, unless state is reset var key = new XORKey(new List<byte> { 0x01, 0x02, 0x03 }); return new XOREncryption(key); }
public XOREncryption(XORKey key) { m_Key = key; }