use of org.hl7.fhir.r5.model.Signature in project org.hl7.fhir.core by hapifhir.
the class DigitalSignatures method main.
public static void main(String[] args) throws SAXException, IOException, ParserConfigurationException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, KeyException, MarshalException, XMLSignatureException, FHIRException {
// http://docs.oracle.com/javase/7/docs/technotes/guides/security/xmldsig/XMLDigitalSignature.html
//
byte[] inputXml = "<Envelope xmlns=\"urn:envelope\">\r\n</Envelope>\r\n".getBytes();
// load the document that's going to be signed
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
DocumentBuilder builder = dbf.newDocumentBuilder();
Document doc = builder.parse(new ByteArrayInputStream(inputXml));
// create a key pair
KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
kpg.initialize(512);
KeyPair kp = kpg.generateKeyPair();
// sign the document
DOMSignContext dsc = new DOMSignContext(kp.getPrivate(), doc.getDocumentElement());
XMLSignatureFactory fac = XMLSignatureFactory.getInstance("DOM");
Reference ref = fac.newReference("", fac.newDigestMethod(DigestMethod.SHA1, null), Collections.singletonList(fac.newTransform(Transform.ENVELOPED, (TransformParameterSpec) null)), null, null);
SignedInfo si = fac.newSignedInfo(fac.newCanonicalizationMethod(CanonicalizationMethod.INCLUSIVE, (C14NMethodParameterSpec) null), fac.newSignatureMethod(SignatureMethod.RSA_SHA1, null), Collections.singletonList(ref));
KeyInfoFactory kif = fac.getKeyInfoFactory();
KeyValue kv = kif.newKeyValue(kp.getPublic());
KeyInfo ki = kif.newKeyInfo(Collections.singletonList(kv));
XMLSignature signature = fac.newXMLSignature(si, ki);
signature.sign(dsc);
OutputStream os = System.out;
new XmlGenerator().generate(doc.getDocumentElement(), os);
}
use of org.hl7.fhir.r5.model.Signature in project org.hl7.fhir.core by hapifhir.
the class RdfParser method composeSignature.
protected void composeSignature(Complex parent, String parentType, String name, Signature element, int index) {
if (element == null)
return;
Complex t;
if (Utilities.noString(parentType))
t = parent;
else {
t = parent.predicate("fhir:" + parentType + '.' + name);
}
composeElement(t, "Signature", name, element, index);
for (int i = 0; i < element.getType().size(); i++) composeCoding(t, "Signature", "type", element.getType().get(i), i);
if (element.hasWhenElement())
composeInstant(t, "Signature", "when", element.getWhenElement(), -1);
if (element.hasWho())
composeType(t, "Signature", "who", element.getWho(), -1);
if (element.hasContentTypeElement())
composeCode(t, "Signature", "contentType", element.getContentTypeElement(), -1);
if (element.hasBlobElement())
composeBase64Binary(t, "Signature", "blob", element.getBlobElement(), -1);
}
use of org.hl7.fhir.r5.model.Signature in project org.hl7.fhir.core by hapifhir.
the class DigitalSignatures method main.
public static void main(String[] args) throws SAXException, IOException, ParserConfigurationException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, KeyException, MarshalException, XMLSignatureException, FHIRException, org.hl7.fhir.exceptions.FHIRException {
// http://docs.oracle.com/javase/7/docs/technotes/guides/security/xmldsig/XMLDigitalSignature.html
//
byte[] inputXml = "<Envelope xmlns=\"urn:envelope\">\r\n</Envelope>\r\n".getBytes();
// load the document that's going to be signed
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
DocumentBuilder builder = dbf.newDocumentBuilder();
Document doc = builder.parse(new ByteArrayInputStream(inputXml));
// create a key pair
KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
kpg.initialize(512);
KeyPair kp = kpg.generateKeyPair();
// sign the document
DOMSignContext dsc = new DOMSignContext(kp.getPrivate(), doc.getDocumentElement());
XMLSignatureFactory fac = XMLSignatureFactory.getInstance("DOM");
Reference ref = fac.newReference("", fac.newDigestMethod(DigestMethod.SHA1, null), Collections.singletonList(fac.newTransform(Transform.ENVELOPED, (TransformParameterSpec) null)), null, null);
SignedInfo si = fac.newSignedInfo(fac.newCanonicalizationMethod(CanonicalizationMethod.INCLUSIVE, (C14NMethodParameterSpec) null), fac.newSignatureMethod(SignatureMethod.RSA_SHA1, null), Collections.singletonList(ref));
KeyInfoFactory kif = fac.getKeyInfoFactory();
KeyValue kv = kif.newKeyValue(kp.getPublic());
KeyInfo ki = kif.newKeyInfo(Collections.singletonList(kv));
XMLSignature signature = fac.newXMLSignature(si, ki);
signature.sign(dsc);
OutputStream os = System.out;
new XmlGenerator().generate(doc.getDocumentElement(), os);
}
use of org.hl7.fhir.r5.model.Signature in project org.hl7.fhir.core by hapifhir.
the class Bundle method copy.
public Bundle copy() {
Bundle dst = new Bundle();
copyValues(dst);
dst.type = type == null ? null : type.copy();
dst.total = total == null ? null : total.copy();
if (link != null) {
dst.link = new ArrayList<BundleLinkComponent>();
for (BundleLinkComponent i : link) dst.link.add(i.copy());
}
;
if (entry != null) {
dst.entry = new ArrayList<BundleEntryComponent>();
for (BundleEntryComponent i : entry) dst.entry.add(i.copy());
}
;
dst.signature = signature == null ? null : signature.copy();
return dst;
}
use of org.hl7.fhir.r5.model.Signature in project org.hl7.fhir.core by hapifhir.
the class JsonParser method composeType.
protected void composeType(String prefix, Type type) throws IOException {
if (type == null)
;
else if (type instanceof Age)
composeAge(prefix + "Age", (Age) type);
else if (type instanceof Count)
composeCount(prefix + "Count", (Count) type);
else if (type instanceof Money)
composeMoney(prefix + "Money", (Money) type);
else if (type instanceof Distance)
composeDistance(prefix + "Distance", (Distance) type);
else if (type instanceof Duration)
composeDuration(prefix + "Duration", (Duration) type);
else if (type instanceof SimpleQuantity)
composeSimpleQuantity(prefix + "SimpleQuantity", (SimpleQuantity) type);
else if (type instanceof Period)
composePeriod(prefix + "Period", (Period) type);
else if (type instanceof Coding)
composeCoding(prefix + "Coding", (Coding) type);
else if (type instanceof Range)
composeRange(prefix + "Range", (Range) type);
else if (type instanceof Quantity)
composeQuantity(prefix + "Quantity", (Quantity) type);
else if (type instanceof Attachment)
composeAttachment(prefix + "Attachment", (Attachment) type);
else if (type instanceof Ratio)
composeRatio(prefix + "Ratio", (Ratio) type);
else if (type instanceof Annotation)
composeAnnotation(prefix + "Annotation", (Annotation) type);
else if (type instanceof SampledData)
composeSampledData(prefix + "SampledData", (SampledData) type);
else if (type instanceof Reference)
composeReference(prefix + "Reference", (Reference) type);
else if (type instanceof CodeableConcept)
composeCodeableConcept(prefix + "CodeableConcept", (CodeableConcept) type);
else if (type instanceof Identifier)
composeIdentifier(prefix + "Identifier", (Identifier) type);
else if (type instanceof Signature)
composeSignature(prefix + "Signature", (Signature) type);
else if (type instanceof TriggerDefinition)
composeTriggerDefinition(prefix + "TriggerDefinition", (TriggerDefinition) type);
else if (type instanceof ElementDefinition)
composeElementDefinition(prefix + "ElementDefinition", (ElementDefinition) type);
else if (type instanceof Timing)
composeTiming(prefix + "Timing", (Timing) type);
else if (type instanceof ModuleMetadata)
composeModuleMetadata(prefix + "ModuleMetadata", (ModuleMetadata) type);
else if (type instanceof ActionDefinition)
composeActionDefinition(prefix + "ActionDefinition", (ActionDefinition) type);
else if (type instanceof Address)
composeAddress(prefix + "Address", (Address) type);
else if (type instanceof HumanName)
composeHumanName(prefix + "HumanName", (HumanName) type);
else if (type instanceof DataRequirement)
composeDataRequirement(prefix + "DataRequirement", (DataRequirement) type);
else if (type instanceof Meta)
composeMeta(prefix + "Meta", (Meta) type);
else if (type instanceof ParameterDefinition)
composeParameterDefinition(prefix + "ParameterDefinition", (ParameterDefinition) type);
else if (type instanceof ContactPoint)
composeContactPoint(prefix + "ContactPoint", (ContactPoint) type);
else if (type instanceof MarkdownType) {
composeMarkdownCore(prefix + "Markdown", (MarkdownType) type, false);
composeMarkdownExtras(prefix + "Markdown", (MarkdownType) type, false);
} else if (type instanceof UnsignedIntType) {
composeUnsignedIntCore(prefix + "UnsignedInt", (UnsignedIntType) type, false);
composeUnsignedIntExtras(prefix + "UnsignedInt", (UnsignedIntType) type, false);
} else if (type instanceof CodeType) {
composeCodeCore(prefix + "Code", (CodeType) type, false);
composeCodeExtras(prefix + "Code", (CodeType) type, false);
} else if (type instanceof IdType) {
composeIdCore(prefix + "Id", (IdType) type, false);
composeIdExtras(prefix + "Id", (IdType) type, false);
} else if (type instanceof OidType) {
composeOidCore(prefix + "Oid", (OidType) type, false);
composeOidExtras(prefix + "Oid", (OidType) type, false);
} else if (type instanceof PositiveIntType) {
composePositiveIntCore(prefix + "PositiveInt", (PositiveIntType) type, false);
composePositiveIntExtras(prefix + "PositiveInt", (PositiveIntType) type, false);
} else if (type instanceof UuidType) {
composeUuidCore(prefix + "Uuid", (UuidType) type, false);
composeUuidExtras(prefix + "Uuid", (UuidType) type, false);
} else if (type instanceof IntegerType) {
composeIntegerCore(prefix + "Integer", (IntegerType) type, false);
composeIntegerExtras(prefix + "Integer", (IntegerType) type, false);
} else if (type instanceof DateTimeType) {
composeDateTimeCore(prefix + "DateTime", (DateTimeType) type, false);
composeDateTimeExtras(prefix + "DateTime", (DateTimeType) type, false);
} else if (type instanceof DateType) {
composeDateCore(prefix + "Date", (DateType) type, false);
composeDateExtras(prefix + "Date", (DateType) type, false);
} else if (type instanceof DecimalType) {
composeDecimalCore(prefix + "Decimal", (DecimalType) type, false);
composeDecimalExtras(prefix + "Decimal", (DecimalType) type, false);
} else if (type instanceof UriType) {
composeUriCore(prefix + "Uri", (UriType) type, false);
composeUriExtras(prefix + "Uri", (UriType) type, false);
} else if (type instanceof Base64BinaryType) {
composeBase64BinaryCore(prefix + "Base64Binary", (Base64BinaryType) type, false);
composeBase64BinaryExtras(prefix + "Base64Binary", (Base64BinaryType) type, false);
} else if (type instanceof TimeType) {
composeTimeCore(prefix + "Time", (TimeType) type, false);
composeTimeExtras(prefix + "Time", (TimeType) type, false);
} else if (type instanceof StringType) {
composeStringCore(prefix + "String", (StringType) type, false);
composeStringExtras(prefix + "String", (StringType) type, false);
} else if (type instanceof BooleanType) {
composeBooleanCore(prefix + "Boolean", (BooleanType) type, false);
composeBooleanExtras(prefix + "Boolean", (BooleanType) type, false);
} else if (type instanceof InstantType) {
composeInstantCore(prefix + "Instant", (InstantType) type, false);
composeInstantExtras(prefix + "Instant", (InstantType) type, false);
} else
throw new Error("Unhandled type");
}
Aggregations