Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.ServiceModel;
- using System.Xml.Linq;
- using System.Security.Cryptography;
- using System.Text;
- using System.IO;
- namespace DNDUtility
- {
- using ContentService;
- public class DataManager
- {
- static WSHttpBinding customBinding = new WSHttpBinding(SecurityMode.None) { AllowCookies = true, MaxReceivedMessageSize = 200000000, Name = "CustomBinding_IContentVaultService"};
- static EndpointAddress remoteAddress = new EndpointAddress("http://ioun.wizards.com/ContentVault.svc");
- static ContentVaultServiceClient contentClient = new ContentVaultServiceClient(customBinding, remoteAddress);
- public static bool Login(string user, string pass)
- {
- return contentClient.Login(user,
- SimpleEncrypt(pass, user));
- }
- public static string[] GetChars()
- {
- ContentInfo[] content = contentClient.GetAvailableContent(0);
- string[] chars = new string[content.Length];
- for (int i = 0; i < content.Length; i++)
- {
- XDocument doc = XDocument.Parse(content[i].CommittedContent.Details.ToString());
- var name = doc.Element("CharacterDetails").Element("Name").Value;
- chars[i] = string.Format("{0} : {1}", i, name);
- }
- return chars;
- }
- /*public static void GetData()
- {
- ContentInfo[] content = contentClient.GetAvailableContent(0);
- DataWithVersion data = contentClient.GetData(
- new ContentIdentifier() { ContentID = content[0].CommittedContent.Identifier.ContentID },
- null);
- RawContentBlob blob = data.Data as RawContentBlob;
- String charFile = new UTF8Encoding().GetString(blob.RawData, 0, blob.RawData.Length);
- XDocument doc = XDocument.Parse(charFile);
- doc.Save(@"d:\Users\Tim Williams\Desktop\Work Documents\TerabyteTim\DND App\ContentVault\ConsoleApplication1\contentdoc.xml");
- }
- //Updates the given character with new data from an XML sheet.
- public static void SaveData(int charNum, byte[] newData)
- {
- ContentInfo[] content = contentClient.GetAvailableContent(0);
- ContentIdentifier newID = contentClient.Edit(content[charNum].CommittedContent.Identifier);
- contentClient.UpdateData(newID, newData,
- content[charNum].CommittedContent.Details);
- contentClient.Commit(newID, newID);
- }*/
- public static byte[] SimpleEncrypt(string value, string key)
- {
- byte[] buffer2;
- ICryptoTransform transform = GetSimpleAlgorithm(key).CreateEncryptor();
- using (MemoryStream stream = new MemoryStream())
- {
- using (CryptoStream stream2 = new CryptoStream(stream, transform, CryptoStreamMode.Write))
- {
- byte[] bytes = Encoding.UTF8.GetBytes(value);
- stream2.Write(bytes, 0, bytes.Length);
- stream2.Flush();
- stream2.FlushFinalBlock();
- stream.Position = 0L;
- buffer2 = stream.ToArray();
- }
- }
- return buffer2;
- }
- static SymmetricAlgorithm GetSimpleAlgorithm(string key)
- {
- AesManaged aes = new AesManaged();
- byte[] source = new SHA256Managed().ComputeHash(Encoding.UTF8.GetBytes(key));
- byte[] take = new byte[aes.BlockSize / 8];
- for (int i = 0; i < aes.BlockSize / 8; i++)
- {
- take[i] = source[i];
- }
- return new AesManaged { Key = source, IV = take };
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement