internal void EnsureEncryptedKeySetUp()
 {
     if (this.encryptedKey == null)
     {
         System.ServiceModel.Security.EncryptedKey key = new System.ServiceModel.Security.EncryptedKey {
             Id = this.Id
         };
         if (this.serializeCarriedKeyName)
         {
             key.CarriedKeyName = this.CarriedKeyName;
         }
         else
         {
             key.CarriedKeyName = null;
         }
         key.EncryptionMethod = this.WrappingAlgorithm;
         key.EncryptionMethodDictionaryString = this.wrappingAlgorithmDictionaryString;
         key.SetUpKeyWrap(this.wrappedKey);
         if (this.WrappingTokenReference != null)
         {
             key.KeyIdentifier = this.WrappingTokenReference;
         }
         this.encryptedKey = key;
     }
 }
            public override SecurityToken ReadTokenCore(XmlDictionaryReader reader, SecurityTokenResolver tokenResolver)
            {
                EncryptedKey encryptedKey = new EncryptedKey();
                encryptedKey.SecurityTokenSerializer = this.tokenSerializer;
                encryptedKey.ReadFrom(reader);
                SecurityKeyIdentifier unwrappingTokenIdentifier = encryptedKey.KeyIdentifier;
                byte[] wrappedKey = encryptedKey.GetWrappedKey();
                WrappedKeySecurityToken wrappedKeyToken = CreateWrappedKeyToken(encryptedKey.Id, encryptedKey.EncryptionMethod,
                    encryptedKey.CarriedKeyName, unwrappingTokenIdentifier, wrappedKey, tokenResolver);
                wrappedKeyToken.EncryptedKey = encryptedKey;

                return wrappedKeyToken;
            }
 public override SecurityToken ReadTokenCore(XmlDictionaryReader reader, SecurityTokenResolver tokenResolver)
 {
     EncryptedKey key = new EncryptedKey {
         SecurityTokenSerializer = this.tokenSerializer
     };
     key.ReadFrom(reader);
     SecurityKeyIdentifier keyIdentifier = key.KeyIdentifier;
     byte[] wrappedKey = key.GetWrappedKey();
     WrappedKeySecurityToken token = this.CreateWrappedKeyToken(key.Id, key.EncryptionMethod, key.CarriedKeyName, keyIdentifier, wrappedKey, tokenResolver);
     token.EncryptedKey = key;
     return token;
 }