public static void DeleteEncryptedFile(string fileName) { var filePath = EncryptedFile.GetEncryptedFilePath(fileName); if (File.Exists(filePath)) { File.Delete(filePath); } }
public static void WriteEncryptedFile <T>(string fileName, T content) { var filePath = EncryptedFile.GetEncryptedFilePath(fileName); var json = JsonConvert.SerializeObject(content); var bytes = Encoding.UTF8.GetBytes(json); bytes = ProtectedData.Protect(bytes, null, DataProtectionScope.CurrentUser); File.WriteAllBytes(filePath, bytes); }
public static T ReadEncryptedFile <T>(string fileName) { var filePath = EncryptedFile.GetEncryptedFilePath(fileName); var bytes = File.ReadAllBytes(filePath); bytes = ProtectedData.Unprotect(bytes, null, DataProtectionScope.CurrentUser); var json = Encoding.UTF8.GetString(bytes); return(JsonConvert.DeserializeObject <T>(json)); }
public void ClearCache() { EncryptedFile.DeleteEncryptedFile(TokenCache.FileName); }
public void SaveCacheToFile() { EncryptedFile.WriteEncryptedFile(TokenCache.FileName, this); }
public static TokenCache GetCacheFromFile() { return(EncryptedFile.ReadEncryptedFile <TokenCache>(TokenCache.FileName)); }