XML加密技术
学习使用XML Encryption保护敏感数据。 · 难度:入门 · +15XP
XML加密概述
XML加密允许加密XML文档中的元素、内容或整个文档,并嵌入加密元数据。支持对称和非对称算法,加密结果以<EncryptedData>元素表示。
加密结构
<EncryptedData xmlns="http://www.w3.org/2001/04/xmlenc#">
<EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes128-cbc"/>
<KeyInfo>
<KeyName>shared-key</KeyName>
</KeyInfo>
<CipherData>
<CipherValue>加密后的二进制数据</CipherValue>
</CipherData>
</EncryptedData>关键元素
| 元素 | 说明 |
|---|---|
| EncryptionMethod | 指定算法 |
| KeyInfo | 密钥信息 |
| CipherData | 包含密文 |
| EncryptedKey | 加密其他密钥 |
示例:加密信用卡号
<order>
<item>书籍</item>
<EncryptedData xmlns="http://www.w3.org/2001/04/xmlenc#" Type="http://www.w3.org/2001/04/xmlenc#Element">
<CipherData>
<CipherValue>AbCdEf123456==</CipherValue>
</CipherData>
</EncryptedData>
</order>练习提示
加密一个完整的<creditcard>元素,包含号码和有效期。注意Type属性需设置为Element。