background image

genenveloped Example

<< Using KeySelectors | Generating an XML Signature >>
<< Using KeySelectors | Generating an XML Signature >>
226
J
AVA
XML D
IGITAL
S
IGNATURE
API
XMLStructure xmlStructure = (XMLStructure) list.get(i);
if (xmlStructure instanceof KeyValue) {
PublicKey pk = null;
try {
pk = ((KeyValue)xmlStructure).getPublicKey();
} catch (KeyException ke) {
throw new KeySelectorException(ke);
}
// make sure algorithm is compatible with method
if (algEquals(sm.getAlgorithm(),
pk.getAlgorithm())) {
return new SimpleKeySelectorResult(pk);
}
}
}
throw new KeySelectorException("No KeyValue element
found!");
}
static boolean algEquals(String algURI, String algName) {
if (algName.equalsIgnoreCase("DSA") &&
algURI.equalsIgnoreCase(SignatureMethod.DSA_SHA1)) {
return true;
} else if (algName.equalsIgnoreCase("RSA") &&
algURI.equalsIgnoreCase(SignatureMethod.RSA_SHA1)) {
return true;
} else {
return false;
}
}
}
genenveloped Example
The code discussed in this section is in the
GenEnveloped.java
file in the
<JWSDP_HOME>/xmldsig/samples/genenveloped
directory. The file on which it
operates,
envelope.xml
, is in the same directory. It generates the file
envelo-
pedSignature.xml.
To compile and run this sample, execute the following command from the
<JWSDP_HOME>/xmldsig/samples/genenveloped
directory:
$ ant