Ignore:
Timestamp:
Jan 18, 2011, 10:10:46 PM (11 years ago)
Author:
kopal
Message:
  • changing user name and/or password in settings now changes these also on the connect view
  • removed the lase message boxes and replaced them by label outputs
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/CrypP2P/Internal/P2PBase.cs

    r2360 r2379  
    3939using PeersAtPlay.P2POverlay.Chord;
    4040using PeersAtPlay.P2PStorage.WebDHT;
     41using System.Security.Cryptography;
    4142
    4243/* TODO:
     
    200201                                        NotificationLevel.Info);
    201202            IsInitialized = true;
    202             Dht.Initialize(P2PSettings.Default.PeerName, P2PSettings.Default.Password, P2PSettings.Default.WorldName, overlay,
     203            Dht.Initialize(P2PSettings.Default.PeerName, DecryptString(P2PSettings.Default.Password), P2PSettings.Default.WorldName, overlay,
    203204                           bootstrapper, linkmanager, null);
    204205        }
     
    537538        }
    538539
     540        /// <summary>
     541        /// Encrypts the given string using the current windows user password and converts
     542        /// this to a base64 string
     543        /// </summary>
     544        /// <param name="s"></param>
     545        /// <returns>encrypted base64 string</returns>
     546        public static string EncryptString(string s)
     547        {
     548            byte[] bytes = Encoding.Unicode.GetBytes(s);
     549            byte[] encBytes = ProtectedData.Protect(bytes, null, DataProtectionScope.CurrentUser);
     550            return Convert.ToBase64String(encBytes);
     551        }
     552
     553        /// <summary>
     554        /// Decrypts the given base64 string using the current windows user password
     555        /// </summary>
     556        /// <param name="s"></param>
     557        /// <returns>decrypted string</returns>
     558        public static string DecryptString(string s)
     559        {
     560            if (string.IsNullOrEmpty(s))
     561            {
     562                return "";
     563            }
     564            try
     565            {
     566                byte[] encBytes = Convert.FromBase64String(s);
     567                byte[] bytes = ProtectedData.Unprotect(encBytes, null, DataProtectionScope.CurrentUser);
     568                return Encoding.Unicode.GetString(bytes);
     569            }
     570            catch (Exception)
     571            {
     572                return "";
     573            }
     574        }
     575
     576
    539577        #endregion
    540578    }
Note: See TracChangeset for help on using the changeset viewer.