Tham khảo tài liệu 'java 6 platform revealed phần 8', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | 136 CHAPTER 6 EXTENSIBLE MARKUP LANGUAGE XML C14NMethodParameterSpec null null ref KeyInfoFactory kif KeyValue kv KeyInfo keyInfo kv return signedInfo keyInfo By now the hard part is over. Listing 6-12 shows how to identify where to insert the signature and connect back to the previously used body ID. The last call is what does the signing. Listing 6-12. The Signing Tree private static void signTree Node root PrivateKey privateKey XMLSignature sig throws MarshalException XMLSignatureException Element envelope getFirstChildElement root Element header getFirstChildElement envelope DOMSignContext sigContext new DOMSignContext privateKey header ds getNextSiblingElement header http soap security 2000-12 id sigContext Similar to signing validation see Listing 6-13 isn t that complicated once you have the necessary pieces. Again this requires you to find the signature element before locating the body element to validate. Finally the validate method of XMLSignature is called to see if the tree passes. Listing 6-13. Validating the XML Signature private static boolean validateXMLSignature PublicKey publicKey Node root XMLSignature sig throws XMLSignatureException CHAPTER 6 EXTENSIBLE MARKUP LANGUAGE XML 137 Element envelope getFirstChildElement root Element header getFirstChildElement envelope Element sigElement getFirstChildElement header DOMValidateContext valContext new DOMValidateContext publicKey sigElement getNextSiblingElement header http soap security 2000-12 id return valContext Listing 6-14 shows the complete program in action. A couple .