static void OldMain(string[] args) { try { string text = "Hello, world!"; string entropy = null; string description; Console.WriteLine("Plaintext: {0}\r\n", text); // Call DPAPI to encrypt data with user-specific key. string encrypted = DPAPI.Encrypt(DPAPI.KeyType.UserKey, text, entropy, "My Data"); Console.WriteLine("Encrypted: {0}\r\n", encrypted); // Call DPAPI to decrypt data. string decrypted = DPAPI.Decrypt(encrypted, entropy, out description); Console.WriteLine("Decrypted: {0} <<<{1}>>>\r\n", decrypted, description); } catch (Exception ex) { Terminals.Logging.Log.Info("", ex); while (ex != null) { Terminals.Logging.Log.Info("", ex); //Console.WriteLine(ex.Message); ex = ex.InnerException; } } }
internal static string DecryptPassword(string encryptedPassword) { if (String.IsNullOrEmpty(encryptedPassword)) { return(encryptedPassword); } try { if (Settings.TerminalsPassword == string.Empty) { return(DPAPI.Decrypt(encryptedPassword)); } else { string hashedPass = Settings.TerminalsPassword.Substring(0, keyLength); byte[] IV = System.Text.Encoding.Default.GetBytes(Settings.TerminalsPassword.Substring(Settings.TerminalsPassword.Length - ivLength)); //string hashedPass = Settings.TerminalsPassword.Substring(0, keyLength); string password = ""; //System.Text.Encoding.Default.GetString(System.Convert.FromBase64String(encryptedPassword)) Unified.Encryption.Decryptor dec = new Unified.Encryption.Decryptor(EncryptionAlgorithm); dec.IV = IV; byte[] data = dec.Decrypt(System.Convert.FromBase64String(encryptedPassword), System.Text.Encoding.Default.GetBytes(hashedPass)); if (data != null && data.Length > 0) { password = System.Text.Encoding.Default.GetString(data); } return(password); } } catch (Exception e) { //string f = e.ToString(); Terminals.Logging.Log.Info("", e); return(""); } }