private static void AddSigningKeyToRelyingParty(ManagementService client, string relyingPartyName, byte[] signingCert, string signingCertPassword, DateTime defaultStartDate, DateTime defaultEndDate, RelyingParty relyingParty)
        {
            var relyingPartyKey = new RelyingPartyKey
                                      {
                                          DisplayName = "Signing Certificate for " + relyingPartyName,
                                          Type = KeyType.X509Certificate.ToString(),
                                          Usage = KeyUsage.Signing.ToString(),
                                          Value = signingCert,
                                          Password = string.IsNullOrEmpty(signingCertPassword) ? null : new UTF8Encoding().GetBytes(signingCertPassword),
                                          RelyingParty = relyingParty,
                                          StartDate = defaultStartDate,
                                          EndDate = defaultEndDate,
                                          IsPrimary = true
                                      };

            client.AddRelatedObject(relyingParty, "RelyingPartyKeys", relyingPartyKey);

            client.SaveChanges();
        }
        private static void AddSigningKeyToRelyingParty(ManagementService client, string relyingPartyName, byte[] symmetricKey, DateTime defaultStartDate, DateTime defaultEndDate, RelyingParty relyingParty)
        {
            var relyingPartyKey = new RelyingPartyKey
                                      {
                                          DisplayName = "Signing Key for " + relyingPartyName,
                                          Type = KeyType.Symmetric.ToString(),
                                          Usage = KeyUsage.Signing.ToString(),
                                          Value = symmetricKey,
                                          RelyingParty = relyingParty,
                                          StartDate = defaultStartDate,
                                          EndDate = defaultEndDate,
                                          IsPrimary = true
                                      };

            client.AddRelatedObject(relyingParty, "RelyingPartyKeys", relyingPartyKey);

            client.SaveChanges();
        }
        private static void AddEncryptionKeyToRelyingParty(ManagementService client, string relyingPartyName, byte[] encryptionCert, DateTime defaultStartDate, DateTime defaultEndDate, RelyingParty relyingParty)
        {
            var relyingPartyKey = new RelyingPartyKey
                                      {
                                          DisplayName = "Encryption Certificate for " + relyingPartyName,
                                          Type = KeyType.X509Certificate.ToString(),
                                          Usage = KeyUsage.Encrypting.ToString(),
                                          Value = encryptionCert,
                                          RelyingParty = relyingParty,
                                          StartDate = defaultStartDate,
                                          EndDate = defaultEndDate
                                      };

            client.AddRelatedObject(relyingParty, "RelyingPartyKeys", relyingPartyKey);

            client.SaveChanges();
        }