Пример #1
0
        private async void LoginButton_Tapped(object sender, TappedRoutedEventArgs e)
        {
            Logining();
            _loginViewModel.LoginUserInfo.UserName = RSACryptoHelper.Encrypt(Uri.EscapeDataString(_loginViewModel.UserName));
            _loginViewModel.LoginUserInfo.Password = RSACryptoHelper.Encrypt(Uri.EscapeDataString(_loginViewModel.Password));
            var result = await AuthenticationService.SignInAsync(_loginViewModel.LoginUserInfo);

            if (!result.Success)
            {
                if (result.Message.Contains("验证码错误"))
                {
                    //刷新验证码
                    RefreshValidateImage();
                }
                else
                {
                    MessageDialog dialog = new MessageDialog(result.Message);
                    await dialog.ShowAsync();
                }
            }
            else
            {
                await LoginSuccess();
            }
            LoginCompleted();
        }
Пример #2
0
        static void Main(string[] args)
        {
            string pk = @"-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0NZLS8G/wWUbce/OI/ZA
Xto4PQ3QYzXBdWCAWY6zqob4XExALu5KQwD/3F7M6LrFv3RhLtnKPBWe4zFlUTKm
N/53NH4RwtOgaArjRLXjsBx1YWHUq7UFNeo+n/57pLT984VWwG2GYOl7Yli5+X1y
oYP2OKFTLw9NXxtuRsDAhPGAQcvy9tAiqMZb5qhKjOQeFELtsoUt20IQv+wonhwJ
Az+u/cIm9K+bbfG/us/MGkmSt9zSfBmHWWbxeSb02tgiJXF2xCb6KRuR0ZM1Xk9c
/fa0AuT4lUzY/FnQQcead1J77d2H5qKBGQmk3kTdhWksHu59VWJQluJjivaJCDuS
xQIDAQAB
-----END PUBLIC KEY-----";

            string strPublic = pk
                               .Split(new string[] { "-----" }, StringSplitOptions.RemoveEmptyEntries)[1]
                               .Replace(" ", "").Replace("\r", "").Replace("\n", "");

            var rs = new RSACryptoHelper(null, strPublic);

            string data = "test1234";

            string result = rs.Encrypt(data);

            Console.WriteLine(result);

            Console.Read();
        }
Пример #3
0
        /// <summary>
        /// Create the RSACryptoServiceProvider for the domain
        /// </summary>
        /// <param name="basePath">Path of the private key to open</param>
        /// <returns></returns>
        public bool initElement(string basePath)
        {
            string path;

            if (Path.IsPathRooted(privateKeyFile))
            {
                path = @"keys\" + privateKeyFile;
            }
            else
            {
                path = Path.Combine(basePath, @"keys\" + privateKeyFile);
            }

            if (!File.Exists(path))
            {
                Logger.LogError("PrivateKey for domain " + domain + " not found: " + path);
                return(false);
            }

            byte[] key = File.ReadAllBytes(path);
            switch (RSACryptoHelper.GetFormatFromEncodedRsaPrivateKey(key))
            {
            case RSACryptoFormat.PEM:
                string pemkey = File.ReadAllText(path, Encoding.ASCII);
                cryptoProvider = RSACryptoHelper.GetProviderFromPemEncodedRsaPrivateKey(pemkey);
                break;

            case RSACryptoFormat.DER:
                cryptoProvider = RSACryptoHelper.GetProviderFromDerEncodedRsaPrivateKey(key);
                break;

            case RSACryptoFormat.XML:
                string xmlkey = File.ReadAllText(path, Encoding.ASCII);
                cryptoProvider = RSACryptoHelper.GetProviderFromXmlEncodedRsaPrivateKey(xmlkey);
                break;

            default:
                throw new ArgumentException(
                          Resources.RSACryptHelper_UnknownFormat,
                          "encodedKey");
            }

            return(true);
        }
Пример #4
0
        /// <summary>
        /// Button "Upload" in domain configuration action - Upload the selected private key file
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btUpload_Click(object sender, EventArgs e)
        {
            if (dgvDomainConfiguration.SelectedCells.Count > 0)
            {
                using (OpenFileDialog fileDialog = new OpenFileDialog())
                {
                    fileDialog.CheckFileExists = true;
                    fileDialog.CheckPathExists = true;
                    fileDialog.Filter          = "All Files|*.*";
                    fileDialog.Title           = "Select a file";
                    fileDialog.Multiselect     = false;

                    if (fileDialog.ShowDialog() == DialogResult.OK)
                    {
                        FileInfo fileInfo   = new FileInfo(fileDialog.FileName);
                        byte[]   binaryData = File.ReadAllBytes(fileDialog.FileName);
                        if (RSACryptoHelper.GetFormatFromEncodedRsaPrivateKey(binaryData) != RSACryptoFormat.UNKNOWN)
                        {
                            dgvDomainConfiguration.Rows[dgvDomainConfiguration.SelectedCells[0].RowIndex].Cells[2].Value = fileInfo.Name;

                            if (attachments.ContainsKey(dgvDomainConfiguration.SelectedCells[0].RowIndex))
                            {
                                attachments[dgvDomainConfiguration.SelectedCells[0].RowIndex] = binaryData;
                            }
                            else
                            {
                                attachments.Add(dgvDomainConfiguration.SelectedCells[0].RowIndex, binaryData);
                            }
                        }
                        else
                        {
                            MessageBox.Show("The format of the private key file you try to import is invalid.");
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("Select a row for upload the private key.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #5
0
        /// <summary>
        /// Button "Generate" in domain configuration action - Generate a new private key file
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btGenerate_Click(object sender, EventArgs e)
        {
            byte[] binaryData = RSACryptoHelper.GenerateXMLEncodedRsaPrivateKey();
            string domain     = dgvDomainConfiguration.Rows[dgvDomainConfiguration.SelectedCells[0].RowIndex].Cells[0].Value.ToString();
            string selector   = dgvDomainConfiguration.Rows[dgvDomainConfiguration.SelectedCells[0].RowIndex].Cells[1].Value.ToString();

            PrivateKeyWindows form = new PrivateKeyWindows(domain, selector);

            form.ShowDialog();

            dgvDomainConfiguration.Rows[dgvDomainConfiguration.SelectedCells[0].RowIndex].Cells[2].Value = form.txtFilename.Text;

            if (attachments.ContainsKey(dgvDomainConfiguration.SelectedCells[0].RowIndex))
            {
                attachments[dgvDomainConfiguration.SelectedCells[0].RowIndex] = binaryData;
            }
            else
            {
                attachments.Add(dgvDomainConfiguration.SelectedCells[0].RowIndex, binaryData);
            }
        }