use of org.apache.xml.security.keys.content.KeyValue in project xades4j by luisgoncalves.
the class KeyInfoBuilderTest method testIgnoreSignSigningCertificateIfNotIncluded.
@Test
public void testIgnoreSignSigningCertificateIfNotIncluded() throws Exception {
System.out.println("ignoreSignSigningCertificateIfNotIncluded");
KeyInfoBuilder keyInfoBuilder = new KeyInfoBuilder(new TestBasicSignatureOptionsProvider(false, true, true), new TestAlgorithmsProvider(), new TestAlgorithmsParametersMarshallingProvider());
XMLSignature xmlSignature = getTestSignature();
keyInfoBuilder.buildKeyInfo(testCertificate, xmlSignature);
Assert.assertEquals(0, xmlSignature.getSignedInfo().getLength());
KeyValue kv = xmlSignature.getKeyInfo().itemKeyValue(0);
Assert.assertTrue(kv.getPublicKey().getAlgorithm().startsWith("RSA"));
Assert.assertEquals(0, xmlSignature.getKeyInfo().lengthX509Data());
}
use of org.apache.xml.security.keys.content.KeyValue in project santuario-java by apache.
the class KeyValueTest method testDSAPublicKey.
@org.junit.Test
public void testDSAPublicKey() throws Exception {
File f = null;
String filename = "src/test/resources/ie/baltimore/merlin-examples/merlin-xmldsig-twenty-three/signature-enveloping-dsa.xml";
if (BASEDIR != null && !"".equals(BASEDIR)) {
f = new File(BASEDIR + SEP + filename);
} else {
f = new File(filename);
}
Document doc = db.parse(new FileInputStream(f));
NodeList nl = doc.getElementsByTagNameNS(Constants.SignatureSpecNS, "Signature");
XMLSignature sig = new XMLSignature((Element) nl.item(0), f.toURI().toURL().toString());
KeyInfo ki = sig.getKeyInfo();
KeyValue kv = ki.itemKeyValue(0);
PublicKey pk = kv.getPublicKey();
assertNotNull(pk);
}
use of org.apache.xml.security.keys.content.KeyValue in project xades4j by luisgoncalves.
the class KeyInfoBuilderTest method testIncludeCertAndKey.
@Test
public void testIncludeCertAndKey() throws Exception {
System.out.println("includeCertAndKey");
KeyInfoBuilder keyInfoBuilder = new KeyInfoBuilder(new BasicSignatureOptions().includeSigningCertificate(SigningCertificateMode.SIGNING_CERTIFICATE).includePublicKey(true), new SignatureAlgorithms(), new TestAlgorithmsParametersMarshallingProvider(), new DefaultX500NameStyleProvider());
XMLSignature xmlSignature = getTestSignature();
keyInfoBuilder.buildKeyInfo(certificates, xmlSignature);
Assert.assertEquals(0, xmlSignature.getSignedInfo().getLength());
KeyValue kv = xmlSignature.getKeyInfo().itemKeyValue(0);
Assert.assertTrue(kv.getPublicKey().getAlgorithm().startsWith("RSA"));
XMLX509Certificate x509Certificate = xmlSignature.getKeyInfo().itemX509Data(0).itemCertificate(0);
Assert.assertEquals(testCertificate, x509Certificate.getX509Certificate());
}
use of org.apache.xml.security.keys.content.KeyValue in project santuario-java by apache.
the class KeyUtils method prinoutKeyInfo.
/**
* Method prinoutKeyInfo
*
* @param ki
* @param os
* @throws XMLSecurityException
*/
public static void prinoutKeyInfo(KeyInfo ki, PrintStream os) throws XMLSecurityException {
for (int i = 0; i < ki.lengthKeyName(); i++) {
KeyName x = ki.itemKeyName(i);
os.println("KeyName(" + i + ")=\"" + x.getKeyName() + "\"");
}
for (int i = 0; i < ki.lengthKeyValue(); i++) {
KeyValue x = ki.itemKeyValue(i);
PublicKey pk = x.getPublicKey();
os.println("KeyValue Nr. " + i);
os.println(pk);
}
for (int i = 0; i < ki.lengthMgmtData(); i++) {
MgmtData x = ki.itemMgmtData(i);
os.println("MgmtData(" + i + ")=\"" + x.getMgmtData() + "\"");
}
for (int i = 0; i < ki.lengthX509Data(); i++) {
X509Data x = ki.itemX509Data(i);
os.println("X509Data(" + i + ")=\"" + (x.containsCertificate() ? "Certificate " : "") + (x.containsIssuerSerial() ? "IssuerSerial " : "") + "\"");
}
}
Aggregations