public static T DeserializeJsonString <T>(string jsonString, Encoding encoding)
 {
     try
     {
         return(JsonSerializationHelpers.DeserializeJsonBytes <T>(encoding.GetBytes(jsonString)));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
 public static T DeserializeJsonStringFromFile <T>(string fileName)
 {
     try
     {
         return(JsonSerializationHelpers.DeserializeJsonBytes <T>(File.ReadAllBytes(fileName)));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
 public static void SerializeObjectToJsonFile <T>(T obj, string fileName, Encoding encoding)
 {
     try
     {
         string jsonString = JsonSerializationHelpers.SerializeObjectToJsonString <T>(obj);
         File.WriteAllText(fileName, jsonString, encoding);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Example #4
0
        private static ProtectedSettings GetExtensionProtectedSettings(string thumbprint, string b64Data)
        {
            byte[] encryptedBytes = Convert.FromBase64String(b64Data);
            //Console.WriteLine("got encrypted bytes");
            X509Certificate2 certificateByThumbprint = EncryptionHelpers.GetCertificateByThumbprint(StoreName.My, StoreLocation.LocalMachine, thumbprint);

            //Console.WriteLine("got thumbprint");
            if (certificateByThumbprint == null)
            {
                return((ProtectedSettings)null);
            }
            ProtectedSettings protectedSettings = JsonSerializationHelpers.DeserializeJsonString <ProtectedSettings>(EncryptionHelpers.DecryptWithCertificate(encryptedBytes, certificateByThumbprint), Encoding.Unicode);

            //Console.WriteLine("got decrypted");
            return(protectedSettings);
        }