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에서는 보내는 사람과 받는 사람이 공통된 비밀 키를 갖는 것으로 간주합니다. 받는 사람이 공개 키와 개인 키 쌍을 갖는 경우(대부분 이 경우에 해당), CreditCard 요소를 예제 3과 같이 암호화할 수 있습니다. 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(Organization for the Advancement of Structured Information Standards)에서 개발되었습니다. 이 스펙은 메시지 무결성, 메시지 기밀성 및 단일 메시지 인증을 통해 고급 보안을 제공할 수 있는 SOAP(Simple Object Access Protocol) 메시징의 개선사항을 기술합니다. 메시징 기밀성은 XML 암호화 기반의 암호화로 실현됩니다.
WSS-Core 스펙은 SOAP 메시지의 본문 블록, 헤더 블록, 해당 하부 구조 및 첨부 파일을 조합하여 암호화하도록 지원합니다. 또한 이 스펙은 SOAP 메시지의 일부를 암호화할 때 보안 헤더 블록의 참조를 메시지의 암호화된 부분 맨 처음에 추가하도록 요구합니다. 받는 사람은 이 참조를 사용하여 복호화가 필요한 암호화된 메시지 부분을 쉽게 식별할 수 있습니다.
참조의 XML 구문은 암호화된 정보와 암호화 방식에 따라 다릅니다. 예를 들어, 예제 4의 CreditCard 요소가 받는 사람의 공통 비밀 키나 공개 키로 암호화된 것으로 가정해 보십시오.
예제 4: 샘플 SOAP 메시지
<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 메시지는 예제 5, 6에 표시되어 있습니다. 두 예제에서는 ReferenceList 및 EncryptedKey 요소가 각각 참조로 사용됩니다.
예제 5: 공통 비밀 키로 암호화된 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'>
<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>
디지털 서명과의 관계
WSS-Core 스펙은 XML-Signature 스펙 기반의 디지털 서명으로 실현되는 메시지 무결성도 제공합니다.
공통 데이터 범위를 벗어난 암호화 및 디지털 서명의 조합은 암호화 취약점의 원인이 될 수 있습니다.