public override bool Execute() { try { if (!validate()) { return(false); } byte[] bytes = File.ReadAllBytes(InputFile); byte[] customEntropy = DPAPIHelper.getCustomEntropy(Entropy, EntropyFile); bytes = ProtectedData.Unprotect(bytes, customEntropy, encryptionScope); Decrypted = Encoding.UTF8.GetString(bytes); return(true); } catch (Exception ex) { Log.LogError("exception in task DPAPIGetSecret"); Log.LogError("{0}", ex); } return(false); }
public override bool Execute() { #if DEBUG if (!Debugger.IsAttached) { var pid = Process.GetCurrentProcess().Id; Log.LogWarning("attach debugger to PID {0}, press any key to continue", pid); Console.ReadKey(); } #endif try { if (!validate()) { return(false); } FileInfo fi = new FileInfo(OutputFile); byte[] bytes = Encoding.UTF8.GetBytes(ToEncrypt); byte[] customEntropy = DPAPIHelper.getCustomEntropy(Entropy, EntropyFile); bytes = ProtectedData.Protect(bytes, customEntropy, encryptionScope); if (!fi.Directory.Exists) { Directory.CreateDirectory(fi.Directory.FullName); } File.WriteAllBytes(OutputFile, bytes); return(true); } catch (Exception ex) { Log.LogError("exception in task DPAPIWriteSecret"); Log.LogError("{0}", ex); } return(false); }