// Decompiled with JetBrains decompiler // Type: Microsoft.InfoCards.InfoCardMasterKey // Assembly: infocard, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 // MVID: ADE0A079-11DB-4A46-8BDE-D2A592CA8DEA // Assembly location: C:\Users\Administrateur\Downloads\Virusshare-00001-msil\Virus.Win32.Expiro.w-1f15ee7e9f7da02b6bfb4c5a5e6484eb9fa71b82d3699c54bcc7a31794b4a66d.exe using Microsoft.InfoCards.Diagnostics; using System; using System.IO; using System.Security.Cryptography; using System.Text; namespace Microsoft.InfoCards { internal class InfoCardMasterKey { private const byte Marker = 29; private const byte Version = 1; private Uri m_infoCardId; private byte[] m_key; public InfoCardMasterKey(Uri infoCardId) => this.m_infoCardId = infoCardId; public InfoCardMasterKey(Uri infoCardId, byte[] key) { this.m_infoCardId = infoCardId; this.m_key = key; } public static InfoCardMasterKey NewMasterKey(Uri infoCardId) { InfoCardMasterKey infoCardMasterKey = new InfoCardMasterKey(infoCardId); InfoCardTrace.Assert(null == infoCardMasterKey.m_key, "Should be null"); infoCardMasterKey.m_key = InfoCardMasterKey.GenerateKey(); return infoCardMasterKey; } public byte[] Key => this.m_key; private static byte[] GenerateKey() { byte[] data = new byte[32]; new RNGCryptoServiceProvider().GetBytes(data); return data; } public void Get(StoreConnection con) { InfoCardTrace.Assert((Uri) null != this.m_infoCardId, "populate infocard id before calling Get"); InfoCardTrace.Assert(con != null, "null connection"); this.Deserialize((Stream) new MemoryStream(this.GetRow(con, QueryDetails.FullRow).GetDataField())); } public void Save(StoreConnection con) { InfoCardTrace.Assert(con != null, "null connection"); this.ThrowIfNotComplete(); DataRow row = this.TryGetRow(con, QueryDetails.FullHeader); if (row == null) { row = new DataRow(); row.ObjectType = 3; row.GlobalId = (GlobalId) Guid.NewGuid(); } row.SetIndexValue("ix_parentid", (object) GlobalId.DeriveFrom(this.m_infoCardId.ToString())); row.SetIndexValue("ix_masterkey", (object) this.m_key); MemoryStream memoryStream = new MemoryStream(); this.Serialize((Stream) memoryStream); row.SetDataField(memoryStream.ToArray()); con.Save(row); } public void ThrowIfNotComplete() { if (!((Uri) null != this.m_infoCardId) || Utility.ArrayIsNullOrEmpty((Array) this.m_key)) throw InfoCardTrace.ThrowHelperError((Exception) new SerializationIncompleteException(this.GetType())); } public void Encrypt(PinProtectionHelper pinHelper) => this.m_key = pinHelper.EncryptMasterKey(this.m_key); public void Decrypt(PinProtectionHelper pinHelper) => this.m_key = pinHelper.DecryptMasterKey(this.m_key); public PinProtectionHelper GetPinHelper(string pin) => new PinProtectionHelper(pin, this.m_key); private void Serialize(Stream stream) { this.ThrowIfNotComplete(); BinaryWriter writer = new BinaryWriter(stream, Encoding.Unicode); writer.Write((byte) 1); Utility.SerializeBytes(writer, this.m_key); writer.Write((byte) 29); } private void Deserialize(Stream stream) { BinaryReader binaryReader = (BinaryReader) new InfoCardBinaryReader(stream, Encoding.Unicode); if ((byte) 1 != binaryReader.ReadByte()) InfoCardTrace.Assert(false, "Master key version mismatch"); this.m_key = binaryReader.ReadBytes(binaryReader.ReadInt32()); if ((byte) 29 != binaryReader.ReadByte()) InfoCardTrace.Assert(false, "Invalid stream detected"); this.ThrowIfNotComplete(); } protected DataRow GetRow(StoreConnection con, QueryDetails details) { DataRow row = this.TryGetRow(con, details); InfoCardTrace.Assert(row != null && 3 == row.ObjectType, "invalid service object type"); return row; } protected DataRow TryGetRow(StoreConnection con, QueryDetails details) { InfoCardTrace.Assert((Uri) null != this.m_infoCardId, "populate cardid before retrieving row"); return con.GetSingleRow(details, new QueryParameter("ix_objecttype", new object[1] { (object) 3 }), new QueryParameter("ix_parentid", new object[1] { (object) GlobalId.DeriveFrom(this.m_infoCardId.ToString()) })); } } }