コード例 #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("");
     }
 }
コード例 #2
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 "";
     }
 }