Example #1
0
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            if (properties.Definition.Id == PowerWebPartConstants.CentralAdminFeatureId)
            {
                PowerWebPartStore store = PowerWebPartStore.Current;

                if (store == null)
                {
                    store = new PowerWebPartStore(PowerWebPartConstants.StoreName, SPFarm.Local, PowerWebPartConstants.StoreId);

                    CspParameters cspParams = new CspParameters();
                    cspParams.Flags = CspProviderFlags.UseMachineKeyStore;

                    RSACryptoServiceProvider rsaAlg = new RSACryptoServiceProvider(cspParams);
                    rsaAlg.PersistKeyInCsp = false;
                    store.SigningKey       = rsaAlg.ToXmlString(true);

                    store.Update();
                }

                string featurePath = properties.Definition.RootDirectory;

                store.Update(true);
            }
        }
        void btnCreateKey_Click(object sender, EventArgs e)
        {
            RSACryptoServiceProvider rsaAlg = CreateRsa();

            try
            {
                store.SigningKey = rsaAlg.ToXmlString(true);
                store.Update();
            }
            finally
            {
                if (rsaAlg != null)
                {
                    rsaAlg.Clear();
                }
            }
        }