Exemplo n.º 1
0
 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("");
     }
 }
Exemplo n.º 2
0
        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;
                }
            }
        }
Exemplo n.º 3
0
 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);
     }
 }