示例#1
0
        public static void SetLastLogin(LastLogin login)
        {
            byte[] decrypted = BitConverter.GetBytes(IPAddress.NetworkToHostOrder((short)login.Username.Length))
                               .Concat(System.Text.Encoding.UTF8.GetBytes(login.Username))
                               .Concat(BitConverter.GetBytes(IPAddress.NetworkToHostOrder((short)login.Password.Length)))
                               .Concat(System.Text.Encoding.UTF8.GetBytes(login.Password)).ToArray();

            PKCSKeyGenerator crypto          = new PKCSKeyGenerator(LastLoginPassword, LastLoginSalt, 5, 1);
            ICryptoTransform cryptoTransform = crypto.Encryptor;

            byte[] encrypted = cryptoTransform.TransformFinalBlock(decrypted, 0, decrypted.Length);
            if (File.Exists(LastLoginFile))
            {
                File.Delete(LastLoginFile);
            }
            using (Stream stream = File.Create(LastLoginFile))
                stream.Write(encrypted, 0, encrypted.Length);
        }
示例#2
0
 public static LastLogin GetLastLogin()
 {
     try
     {
         byte[]           encryptedLogin  = File.ReadAllBytes(LastLoginFile);
         PKCSKeyGenerator crypto          = new PKCSKeyGenerator(LastLoginPassword, LastLoginSalt, 5, 1);
         ICryptoTransform cryptoTransform = crypto.Decryptor;
         byte[]           decrypted       = cryptoTransform.TransformFinalBlock(encryptedLogin, 0, encryptedLogin.Length);
         short            userLength      = IPAddress.HostToNetworkOrder(BitConverter.ToInt16(decrypted, 0));
         byte[]           user            = decrypted.Skip(2).Take(userLength).ToArray();
         short            passLength      = IPAddress.HostToNetworkOrder(BitConverter.ToInt16(decrypted, userLength + 2));
         byte[]           password        = decrypted.Skip(4 + userLength).ToArray();
         LastLogin        result          = new LastLogin();
         result.Username = System.Text.Encoding.UTF8.GetString(user);
         result.Password = System.Text.Encoding.UTF8.GetString(password);
         return(result);
     }
     catch
     {
         return(null);
     }
 }
示例#3
0
        public static void SetLastLogin(LastLogin login)
        {
            byte[] decrypted = BitConverter.GetBytes(IPAddress.NetworkToHostOrder((short)login.Username.Length))
                .Concat(System.Text.Encoding.UTF8.GetBytes(login.Username))
                .Concat(BitConverter.GetBytes(IPAddress.NetworkToHostOrder((short)login.Password.Length)))
                .Concat(System.Text.Encoding.UTF8.GetBytes(login.Password)).ToArray();

            PKCSKeyGenerator crypto = new PKCSKeyGenerator(LastLoginPassword, LastLoginSalt, 5, 1);
            ICryptoTransform cryptoTransform = crypto.Encryptor;
            byte[] encrypted = cryptoTransform.TransformFinalBlock(decrypted, 0, decrypted.Length);
            if (File.Exists(LastLoginFile))
                File.Delete(LastLoginFile);
            using (Stream stream = File.Create(LastLoginFile))
                stream.Write(encrypted, 0, encrypted.Length);
        }
示例#4
0
 public static LastLogin GetLastLogin()
 {
     try
     {
         byte[] encryptedLogin = File.ReadAllBytes(LastLoginFile);
         PKCSKeyGenerator crypto = new PKCSKeyGenerator(LastLoginPassword, LastLoginSalt, 5, 1);
         ICryptoTransform cryptoTransform = crypto.Decryptor;
         byte[] decrypted = cryptoTransform.TransformFinalBlock(encryptedLogin, 0, encryptedLogin.Length);
         short userLength = IPAddress.HostToNetworkOrder(BitConverter.ToInt16(decrypted, 0));
         byte[] user = decrypted.Skip(2).Take(userLength).ToArray();
         short passLength = IPAddress.HostToNetworkOrder(BitConverter.ToInt16(decrypted, userLength + 2));
         byte[] password = decrypted.Skip(4 + userLength).ToArray();
         LastLogin result = new LastLogin();
         result.Username = System.Text.Encoding.UTF8.GetString(user);
         result.Password = System.Text.Encoding.UTF8.GetString(password);
         return result;
     }
     catch
     {
         return null;
     }
 }