示例#1
0
        public static SignKeys GenerateSignKeyPair()
        {
            SignKeys keys = new SignKeys();
            using (DSACryptoServiceProvider dsa = new DSACryptoServiceProvider())
            {
                keys.PublicAndPrivate = dsa.ExportCspBlob(true);
                keys.PublicOnly = dsa.ExportCspBlob(false);
            }

            return keys;
        }
示例#2
0
文件: MainForm.cs 项目: iqman/MACMSC
        private void buttonGenerateKeypairsForUser_Click(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(this.textBoxNewUserId.Text))
                {
                    MessageBox.Show("You must enter a username");
                    return;
                }
                this.newUserId = GuidCreator.CreateGuidFromString(this.textBoxNewUserId.Text);

                if (this.masterKeypair == null)
                {
                    MessageBox.Show("You must load master key pair first");
                    return;
                }

                string filename = FileDialogs.AskUserForFileNameToSaveIn();
                if (!string.IsNullOrEmpty(filename))
                {
                    if (!Path.HasExtension(filename))
                    {
                        filename = filename + ".xml";
                    }

                    this.signKeyPair = DataSigner.GenerateSignKeyPair();

                    IPreService proxy = GetPreProxy();
                    this.userKeypair = proxy.GenerateKeyPair();

                    proxy = GetPreProxy();
                    this.delegationToken.ToUser = proxy.GenerateDelegationKey(this.masterKeypair.Private, this.userKeypair.Public);

                    IGatewayService gateWayproxy = GetServiceProxy();
                    gateWayproxy.RegisterUser(this.myId, this.newUserId, this.delegationToken, this.signKeyPair.PublicOnly);

                    UserKeys uk = new UserKeys();
                    uk.MasterKeyPublicKey = Convert.ToBase64String(this.masterKeypair.Public);
                    uk.UserPrivateKey = Convert.ToBase64String(this.userKeypair.Private);
                    uk.UserSignKeys = Convert.ToBase64String(this.signKeyPair.PublicAndPrivate);

                    XmlFile.WriteFile(uk, filename);

                    MessageBox.Show("Done");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message);
                Logger.LogError("Error generating user keypair", ex);
            }
        }