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 EncryptPassword(string decryptedPassword) { if (Settings.TerminalsPassword == string.Empty) { return(DPAPI.Encrypt(DPAPI.KeyType.UserKey, decryptedPassword)); } else { string password = ""; try { string hashedPass = Settings.TerminalsPassword.Substring(0, keyLength); byte[] IV = System.Text.Encoding.Default.GetBytes(Settings.TerminalsPassword.Substring(Settings.TerminalsPassword.Length - ivLength)); Unified.Encryption.Encryptor enc = new Unified.Encryption.Encryptor(EncryptionAlgorithm); enc.IV = IV; byte[] data = enc.Encrypt(System.Text.Encoding.Default.GetBytes(decryptedPassword), System.Text.Encoding.Default.GetBytes(hashedPass)); if (data != null && data.Length > 0) { password = Convert.ToBase64String(data); //password = System.Text.Encoding.Default.GetString(data); } } catch (Exception ec) { //string f = ec.ToString(); Terminals.Logging.Log.Info("", ec); } return(password); } }