public void AttachBinary(Entry entry, string key, ProtectedMemoryBinary protectedMemoryBinary)
        {
            lock(this.syncLock)
            {
                int id = this.Binaries.Count;
                this.Binaries.Add(new BinaryMapping()
                {
                    Id = id,
                    Key = key,
                    Value = protectedMemoryBinary
                });

                entry.Binaries.Add(new ProtectedBinary()
                {
                    Key = key,
                    Ref = id,
                    Value = protectedMemoryBinary
                });

                this.Meta.Binaries.Add(new Binary()
                {
                    Compressed = this.HeaderInfo.DatabaseCompression == (byte)1,
                    Id = id
                });
            }
        }
            public static void EncryptsValue()
            {
                var bytes = Encoding.UTF8.GetBytes("megatron password");
                var protectedMemoryBinary = new ProtectedMemoryBinary(bytes);

                var internalBinary = typeof(ProtectedMemoryBinary).GetRuntimeFields().SingleOrDefault(o => o.Name == "binary");
                var encryptedBytes = (byte[])internalBinary.GetValue(protectedMemoryBinary);

                Assert.NotEmpty(encryptedBytes);
                Assert.NotEqual(bytes, encryptedBytes);
               
                Assert.Equal(protectedMemoryBinary.Length, bytes.Length);

                Assert.NotEqual(new byte[8], protectedMemoryBinary.Id);
            }
            public static void ReturnsDecyptedData()
            {
                var bytes = Encoding.UTF8.GetBytes("megatron3 password");
                var protectedMemoryBinary = new ProtectedMemoryBinary(bytes);

                var internalBinary = typeof(ProtectedMemoryBinary).GetRuntimeFields().SingleOrDefault(o => o.Name == "binary");
                var encryptedBytes = (byte[])internalBinary.GetValue(protectedMemoryBinary);
                var copy = new byte[bytes.Length];
                Array.Copy(encryptedBytes, copy, bytes.Length);

                Assert.NotEmpty(copy);
                Assert.NotEqual(bytes, copy);

                var decryptedBytes = protectedMemoryBinary.UnprotectAndCopyData();
                Assert.Equal(bytes, decryptedBytes);
            }
            public static void StoresValueInMemory()
            {
                var bytes = Encoding.UTF8.GetBytes("megatron2 password");
                var protectedMemoryBinary = new ProtectedMemoryBinary(bytes, false);

                var internalBinary = typeof(ProtectedMemoryBinary).GetRuntimeFields().SingleOrDefault(o => o.Name == "binary");
                var encryptedBytes = (byte[])internalBinary.GetValue(protectedMemoryBinary);
                var copy = new byte[bytes.Length];
                Array.Copy(encryptedBytes, copy, bytes.Length);

                Assert.NotEmpty(copy);
                Assert.Equal(bytes, copy);
                Assert.Equal(protectedMemoryBinary.Length, bytes.Length);
                if (!(bytes.Length % 16 == 0))
                    Assert.NotEqual(encryptedBytes.Length, bytes.Length);

                Assert.NotEqual(new byte[8], protectedMemoryBinary.Id);
            }
 protected void SetData(byte[] data)
 { 
     this.binary = new ProtectedMemoryBinary(data, true);
 }