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); }
private static void ProcessFile(string fileName) { string thumbprint = ""; string data = ""; string username = ""; Console.WriteLine("Parsing file {0}", fileName); using (StreamReader r = new StreamReader(fileName)) { JObject o = (JObject)JToken.ReadFrom(new JsonTextReader(r)); JArray settings = (JArray)o["runtimeSettings"]; JToken handlerSettings = settings.First["handlerSettings"]; //Console.WriteLine(handlerSettings); thumbprint = (string)handlerSettings["protectedSettingsCertThumbprint"]; //Console.WriteLine(thumbprint); data = (string)handlerSettings["protectedSettings"]; //Console.WriteLine(data); username = (string)handlerSettings["publicSettings"]["UserName"]; } Console.WriteLine("Username: {0}", username); ProtectedSettings protectedSettings = GetExtensionProtectedSettings(thumbprint, data); Console.WriteLine("Password: {0}", protectedSettings.Password); }