XML 加密

XML 加密是万维网 (WWW) 协会 (W3C) 在 2002 年开发的规范,包含对数据进行加密的步骤、对已加密数据进行解密的步骤、用来表示已加密数据的 XML 语法、要用于对数据进行解密的信息以及加密算法(例如三重 DES、AES 和 RSA)的列表。

可将 XML 加密应用于 XML 元素、XML 元素内容和任意数据(其中包括 XML 文档)。例如,假定需要对示例 1 中显示的 <CreditCard> 元素进行加密。

示例 1:样本 XML 文档:

<PaymentInfo xmlns='http://example.org/paymentv2'>
  <Name>John Smith</Name>
  <CreditCard Limit='5,000' Currency='USD'>
    <Number>4019 2445 0277 5567</Number>
    <Issuer>Example Bank</Issuer>
    <Expiration>04/02</Expiration>
  </CreditCard>
</PaymentInfo>

示例 2:带公共密钥的 XML 文档:

示例 2 显示加密后的 XML 文档。<EncryptedData> 元素表示已加密的 <CreditCard> 元素。<EncryptionMethod> 元素描述应用的加密算法(在此示例中为三重 DES)。<KeyInfo> 元素包含检索解密密钥(在此示例中为 <KeyName> 元素)所需的信息。<CipherValue> 元素包含通过对 <CreditCard> 元素进行序列化和加密获取的密文。

<PaymentInfo xmlns='http://example.org/paymentv2'>
  <Name>John Smith</Name>
  <EncryptedData Type='http://www.w3.org/2001/04/xmlenc#Element'
     xmlns='http://www.w3.org/2001/04/xmlenc#'>
    <EncryptionMethod
       Algorithm='http://www.w3.org/2001/04/xmlenc#tripledes-cbc'/>
       <KeyInfo xmlns='http://www.w3.org/2000/09/xmldsig#'>
         <KeyName>John Smith</KeyName>
       </KeyInfo>
       <CipherData>
         <CipherValue>ydUNqHkMrD...</CipherValue>
       </CipherData>
  </EncryptedData>
</PaymentInfo>

示例 3:使用接收方的公用密钥加密的 XML 文档:

在示例 2 中,假定发送方和接收方都具有公共密钥。如果接收方具有公用和专用密钥对(这是通常情况),那么可以按示例 3 中所示对 <CreditCard> 元素进行加密。<EncryptedData> 元素与示例 2 中找到的 <EncryptedData> 元素相同。但是 <KeyInfo> 元素包含 <EncryptedKey> 元素。

<PaymentInfo xmlns='http://example.org/paymentv2'>
  <Name>John Smith</Name>
  <EncryptedData Type='http://www.w3.org/2001/04/xmlenc#Element'
    xmlns='http://www.w3.org/2001/04/xmlenc#'>
    <EncryptionMethod
      Algorithm='http://www.w3.org/2001/04/xmlenc#tripledes-cbc'/>
    <KeyInfo xmlns='http://www.w3.org/2000/09/xmldsig#'>
      <EncryptedKey xmlns='http://www.w3.org/2001/04/xmlenc#'>
        <EncryptionMethod
          Algorithm='http://www.w3.org/2001/04/xmlenc#rsa-1_5'/>
        <KeyInfo xmlns='http://www.w3.org/2000/09/xmldsig#'>
          <KeyName>Sally Doe</KeyName>
        </KeyInfo>
        <CipherData>
          <CipherValue>yMTEyOTA1M...</CipherValue>
        </CipherData>
      </EncryptedKey>
    </KeyInfo>
    <CipherData>
      <CipherValue>ydUNqHkMrD...</CipherValue>
    </CipherData>
  </EncryptedData>
</PaymentInfo>

以 WSS-Core 加密 XML:

WSS-Core 规范是由“结构化信息标准促进组织”(OASIS) 开发的规范。此规范描述了对 SOAP 消息传递的增强,这些增强旨在通过消息完整性、消息机密性和单个消息认证来提供保护质量。消息机密性由基于 XML 加密的加密实现。

WSS-Core 规范支持对主体块、头块、其子结构,以及 SOAP 消息附件的任何组合进行加密。对 SOAP 消息的一些部分进行加密时,此规范还要求您将引用从安全性头块添加到该消息的已加密部分之前。该引用可以是供接收方标识要对消息的哪些已加密部分进行解密的线索。

该引用的 XML 语法随已加密信息以及加密方式的不同而不同。例如,假定使用常见密钥或接收方的公共密钥对示例 4 中的 <CreditCard> 元素进行加密。

示例 4:样本 SOAP V1.1 消息:

<SOAP-ENV:Envelope
  SOAP-ENV:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'
  xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'>
  <SOAP-ENV:Body>
    <PaymentInfo xmlns='http://example.org/paymentv2'>
      <Name>John Smith</Name>
      <CreditCard Limit='5,000' Currency='USD'>
        <Number>4019 2445 0277 5567</Number>
        <Issuer>Example Bank</Issuer>
        <Expiration>04/02</Expiration>
      </CreditCard>
    </PaymentInfo>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
SOAP V1.2 不支持 encodingStyle,因此,该示例更改为如下所示:
<SOAP-ENV:Envelope
   xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'>
  <SOAP-ENV:Body>
    <PaymentInfo xmlns='http://example.org/paymentv2'>
      <Name>John Smith</Name>
      <CreditCard Limit='5,000' Currency='USD'>
        <Number>4019 2445 0277 5567</Number>
        <Issuer>Example Bank</Issuer>
        <Expiration>04/02</Expiration>
      </CreditCard>
    </PaymentInfo>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

示例 5 和 6 中显示产生的 SOAP 消息。在这些示例中,<ReferenceList> 和 <EncryptedKey> 元素分别用作引用。

示例 5:使用公共密钥加密的 SOAP V1.1 消息

<SOAP-ENV:Envelope
   xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'>
  <SOAP-ENV:Header>
    <Security SOAP-ENV:mustUnderstand='1'
      xmlns='http://schemas.xmlsoap.org/ws/2003/06/secext'>
      <ReferenceList xmlns='http://www.w3.org/2001/04/xmlenc#'>
        <DataReference URI='#ed1'/>
      </ReferenceList>
    </Security>
  </SOAP-ENV:Header>
  <SOAP-ENV:Body>
    <PaymentInfo xmlns='http://example.org/paymentv2'>
      <Name>John Smith</Name>
      <EncryptedData Id='ed1'
        Type='http://www.w3.org/2001/04/xmlenc#Element'
        xmlns='http://www.w3.org/2001/04/xmlenc#'>
        <EncryptionMethod
          Algorithm='http://www.w3.org/2001/04/xmlenc#tripledes-cbc'/>
        <KeyInfo xmlns='http://www.w3.org/2000/09/xmldsig#'>
          <KeyName>John Smith</KeyName>
        </KeyInfo>
        <CipherData>
          <CipherValue>ydUNqHkMrD...</CipherValue>
        </CipherData>
      </EncryptedData>
    </PaymentInfo>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

SOAP V1.2 不支持 encodingStyle,因此,该示例更改为如下所示:

<SOAP-ENV:Envelope
   xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'>
  <SOAP-ENV:Header>
    <Security SOAP-ENV:mustUnderstand='1'
      xmlns='http://schemas.xmlsoap.org/ws/2003/06/secext'>
      <ReferenceList xmlns='http://www.w3.org/2001/04/xmlenc#'>
        <DataReference URI='#ed1'/>
      </ReferenceList>
    </Security>
  </SOAP-ENV:Header>
  <SOAP-ENV:Body>
    <PaymentInfo xmlns='http://example.org/paymentv2'>
      <Name>John Smith</Name>
      <EncryptedData Id='ed1'
        Type='http://www.w3.org/2001/04/xmlenc#Element'
        xmlns='http://www.w3.org/2001/04/xmlenc#'>
        <EncryptionMethod
          Algorithm='http://www.w3.org/2001/04/xmlenc#tripledes-cbc'/>
        <KeyInfo xmlns='http://www.w3.org/2000/09/xmldsig#'>
          <KeyName>John Smith</KeyName>
        </KeyInfo>
        <CipherData>
          <CipherValue>ydUNqHkMrD...</CipherValue>
        </CipherData>
      </EncryptedData>
    </PaymentInfo>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

示例 6:使用接收方的公用密钥加密 SOAP 消息:

<SOAP-ENV:Envelope
  SOAP-ENV:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'
  xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'>
  <SOAP-ENV:Header>
    <Security SOAP-ENV:mustUnderstand='1'
      xmlns='http://schemas.xmlsoap.org/ws/2003/06/secext'>
      <EncryptedKey xmlns='http://www.w3.org/2001/04/xmlenc#'>
        <EncryptionMethod
          Algorithm='http://www.w3.org/2001/04/xmlenc#rsa-1_5'/>
        <KeyInfo xmlns='http://www.w3.org/2000/09/xmldsig#'>
          <KeyName>Sally Doe</KeyName>
        </KeyInfo>
        <CipherData>
          <CipherValue>yMTEyOTA1M...</CipherValue>
        </CipherData>
        <ReferenceList>
          <DataReference URI='#ed1'/>
        </ReferenceList>
      </EncryptedKey>
    </Security>
  </SOAP-ENV:Header>
  <SOAP-ENV:Body>
    <PaymentInfo xmlns='http://example.org/paymentv2'>
      <Name>John Smith</Name>
      <EncryptedData Id='ed1'
        Type='http://www.w3.org/2001/04/xmlenc#Element'
        xmlns='http://www.w3.org/2001/04/xmlenc#'>
        <EncryptionMethod
          Algorithm='http://www.w3.org/2001/04/xmlenc#tripledes-cbc'/>
        <CipherData>
          <CipherValue>ydUNqHkMrD...</CipherValue>
        </CipherData>
      </EncryptedData>
    </PaymentInfo>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

SOAP V1.2 不支持 encodingStyle,因此,该示例更改为如下所示:

<SOAP-ENV:Envelope xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'>
  <SOAP-ENV:Header>
    <Security SOAP-ENV:mustUnderstand='1'
      xmlns='http://schemas.xmlsoap.org/ws/2003/06/secext'>
      <EncryptedKey xmlns='http://www.w3.org/2001/04/xmlenc#'>
        <EncryptionMethod
          Algorithm='http://www.w3.org/2001/04/xmlenc#rsa-1_5'/>
        <KeyInfo xmlns='http://www.w3.org/2000/09/xmldsig#'>
          <KeyName>Sally Doe</KeyName>
        </KeyInfo>
        <CipherData>
          <CipherValue>yMTEyOTA1M...</CipherValue>
        </CipherData>
        <ReferenceList>
          <DataReference URI='#ed1'/>
        </ReferenceList>
      </EncryptedKey>
    </Security>
  </SOAP-ENV:Header>
  <SOAP-ENV:Body>
    <PaymentInfo xmlns='http://example.org/paymentv2'>
      <Name>John Smith</Name>
      <EncryptedData Id='ed1'
        Type='http://www.w3.org/2001/04/xmlenc#Element'
        xmlns='http://www.w3.org/2001/04/xmlenc#'>
        <EncryptionMethod
          Algorithm='http://www.w3.org/2001/04/xmlenc#tripledes-cbc'/>
        <CipherData>
          <CipherValue>ydUNqHkMrD...</CipherValue>
        </CipherData>
      </EncryptedData>
    </PaymentInfo>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

与数字签名的关系:

WSS-Core 规范还提供消息完整性,这由基于 XML 签名规范的数字签名来实现。

对公共数据的加密与数字签名的组合会暴露加密弱点。

对称加密与非对称加密

对于 XML 加密,应用程序服务器支持以下两种加密类型:

  • 对称加密

    在 WebSphere® Application Server V7 之前的应用程序服务器发行版(其中包括 IBM® WebSphere Application Server V6.1 Feature Pack for Web Services)中,缺省情况下,KeyName 引用用来在 SOAP 消息外部引用共享密钥。但是,Web Service 安全性 (WS-Security) V1.1 标准不推荐使用 KeyName 引用。因为 KeyName 不受该安全策略支持,所以它在应用程序服务器中不受支持。

    Web Services Secure Conversation (WS-SecureConversation) 标准定义如何在客户机与服务之间交换共享密钥,以及如何在消息中引用共享密钥。将 Kerberos 与 Web Service 安全性配合使用的用法(如 Kerberos 令牌概要文件中所述)还定义了如何使用 Kerberos 会话密钥或派生自该会话密钥的密钥来执行对称加密。因此,可以通过使用 WS-SecureConversation 或 Kerberos 来执行对称加密。当使用 WS-SecureConversation 时,WebSphere Application Server 支持 DerivedKeyToken。当使用 Kerberos 时,WebSphere Application Server 支持使用 DerivedKeyToken 以及直接使用 Kerberos 会话密钥。

  • 非对称加密

    对于非对称加密,XML 加密引入了密钥合并的思想。使用在进行处理期间动态生成的共享密钥来对数据(例如 SOAP 主体元素的内容)进行加密。然后,使用接收方的公用密钥来对生成的共享密钥进行加密。WebSphere Application Server 支持用于非对称加密的 X509Token。


指示主题类型的图标 概念主题



时间戳记图标 最近一次更新时间: last_date
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=cord&product=was-nd-mp&topic=cwbs_encryptv6
文件名:cwbs_encryptv6.html