MessageProtectionOrder 列舉

定義

指定保護訊息的作業順序。

public enum class MessageProtectionOrder
public enum MessageProtectionOrder
type MessageProtectionOrder = 
Public Enum MessageProtectionOrder
繼承
MessageProtectionOrder

欄位

EncryptBeforeSign 2

指定要在 SOAP 訊息的數位簽章產生之前加密 SOAP 訊息。

SignBeforeEncrypt 0

指定要在 SOAP 訊息的任何部分加密之前產生 SOAP 訊息的數位簽章,但是不加密這個數位簽章。

SignBeforeEncryptAndEncryptSignature 1

指定要在 SOAP 訊息的任何部分加密之前產生 SOAP 訊息的數位簽章,而且要加密這個數位簽章。

範例

下列範例會 SymmetricSecurityBindingElement 建立專案,並將其 MessageProtectionOrder 屬性設定為 SignBeforeEncrypt。

public static Binding CreateCustomBinding()
{
    // Create an empty BindingElementCollection to populate,
    // then create a custom binding from it.
    BindingElementCollection outputBec = new BindingElementCollection();

    // Create a SymmetricSecurityBindingElement.
    SymmetricSecurityBindingElement ssbe =
        new SymmetricSecurityBindingElement();

    // Set the algorithm suite to one that uses 128-bit keys.
    ssbe.DefaultAlgorithmSuite = SecurityAlgorithmSuite.Basic128;

       // Set MessageProtectionOrder to SignBeforeEncrypt.
    ssbe.MessageProtectionOrder = MessageProtectionOrder.SignBeforeEncrypt;

    // Use a Kerberos token as the protection token.
    ssbe.ProtectionTokenParameters = new KerberosSecurityTokenParameters();

    // Add the SymmetricSecurityBindingElement to the BindingElementCollection.
    outputBec.Add ( ssbe );
    outputBec.Add(new TextMessageEncodingBindingElement());
    outputBec.Add(new HttpTransportBindingElement());

    // Create a CustomBinding and return it; otherwise, return null.
    return new CustomBinding(outputBec);
}
Public Shared Function CreateCustomBinding() As Binding 
    ' Create an empty BindingElementCollection to populate, 
    ' then create a custom binding from it.
    Dim outputBec As New BindingElementCollection()
    
    ' Create a SymmetricSecurityBindingElement.
    Dim ssbe As New SymmetricSecurityBindingElement()
    
    ' Set the algorithm suite to one that uses 128-bit keys.
    ssbe.DefaultAlgorithmSuite = SecurityAlgorithmSuite.Basic128
    
    ' Set MessageProtectionOrder to SignBeforeEncrypt.
    ssbe.MessageProtectionOrder = MessageProtectionOrder.SignBeforeEncrypt
    
    ' Use a Kerberos token as the protection token.
    ssbe.ProtectionTokenParameters = New KerberosSecurityTokenParameters()
    
    ' Add the SymmetricSecurityBindingElement to the BindingElementCollection.
    outputBec.Add(ssbe)
    outputBec.Add(New TextMessageEncodingBindingElement())
    outputBec.Add(New HttpTransportBindingElement())
    
    ' Create a CustomBinding and return it; otherwise, return null.
    Return New CustomBinding(outputBec)

End Function

備註

這個列舉型別 (Enumeration) 會與 AsymmetricSecurityBindingElement.MessageProtectionOrderAsymmetricSecurityBindingElement 屬性及 SymmetricSecurityBindingElement.MessageProtectionOrder 類別的 SymmetricSecurityBindingElement 屬性一起使用。

例如,如果訊息容易遭受摘要式攻擊 (,如果訊息是短的,或 entropy 低) ,您應該使用 SignBeforeEncryptAndEncryptSignature 或 EncryptBeforeSign 選項。 (Entropy 是由伺服器、用戶端或兩者提供的亂數據,並用來建立共用金鑰來加密和解密 data.)

何謂已排序?

WCF 提供三個不同的保護層級,決定如何使用 SOAP 訊息安全性來保護訊息。 預設值為 SignBeforeEncryptAndEncryptSignature。 這個設定會先簽署訊息,再加密訊息本文,然後加密 XML 簽章。 這可以降低密碼編譯猜測攻擊成功破解簽章的可能性。

不過,使用這個預設值對於效能具有另一層含意。 實際上,安全性提高會使得效能產生折衷。 加密簽章可能降低 10% 至 40% 之間的效能。 如果訊息的資料內容為低值,且效能輸送量更為顯著,請使用 SignBeforeEncrypt。 使用這項設定時,簽章摘要會以純文字格式傳送,如此一來,訊息更容易因其 Entropy 較低而遭受「猜測驗證法」(Guess-and-verify) 攻擊。

僅限自訂繫結

為了變更 MessageProtectionOrder 屬性,此時必須建立自訂安全性繫結。 如需建立自訂系結的詳細資訊,請參閱 建立User-Defined系結。 如需針對特定驗證模式建立自訂系結的詳細資訊,請參閱 如何:為指定的驗證模式建立 SecurityBindingElement

適用於

另請參閱