public static void WriteProfileToDisk(ProfileType profile, string key) { FileStream fStream = File.Open(Path.Combine(DataOperations.GetProfilePath(), profile.ProfileName + ".dat"), FileMode.Create); byte[] encryptedBytes = CryptographyHelper.Encrypt(Serializer.getSerializedStream(profile).ToArray(), key); fStream.Write(encryptedBytes, 0, encryptedBytes.Length); fStream.Close(); }
public static ProfileType GetProfileFromDisk(string ProfileName, string Key) { if (ChekProfileFileExsists(ProfileName)) { FileStream FileStream; MemoryStream MemoryStream; try { FileStream = new FileStream(DataOperations.GetProfileFilePath(ProfileName), FileMode.Open); byte[] EncrypedFromStream = new byte[FileStream.Length]; FileStream.Read(EncrypedFromStream, 0, EncrypedFromStream.Length); MemoryStream = new MemoryStream(CryptographyHelper.Decrypt(EncrypedFromStream, Key)); } catch { ProfileType Profile = new ProfileType(); Profile.ErrorCode = (short)Enumerators.ProfileTypeErrorCodes.ReadFileError; return(Profile); } try { ProfileType Profile = Serializer.getDeserializedProfile(MemoryStream); FileStream.Close(); MemoryStream.Close(); Profile.ErrorCode = (short)Enumerators.ProfileTypeErrorCodes.NoFailture; return(Profile); } catch { ProfileType Profile = new ProfileType(); Profile.ErrorCode = (short)Enumerators.ProfileTypeErrorCodes.SerializerError; return(Profile); } } else { ProfileType Profile = new ProfileType(); Profile.ErrorCode = (short)Enumerators.ProfileTypeErrorCodes.FileNotFound; return(Profile); } }