示例#1
0
        public static void DeleteEncryptedFile(string fileName)
        {
            var filePath = EncryptedFile.GetEncryptedFilePath(fileName);

            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }
        }
示例#2
0
        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);
        }
示例#3
0
        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));
        }
示例#4
0
 public void ClearCache()
 {
     EncryptedFile.DeleteEncryptedFile(TokenCache.FileName);
 }
示例#5
0
 public void SaveCacheToFile()
 {
     EncryptedFile.WriteEncryptedFile(TokenCache.FileName, this);
 }
示例#6
0
 public static TokenCache GetCacheFromFile()
 {
     return(EncryptedFile.ReadEncryptedFile <TokenCache>(TokenCache.FileName));
 }