コード例 #1
0
        public void Run()
        {
            int         type = 2;
            XmlDocument doc  = null;
            SignedMortalityReasonType smrt = null;
            bool useSTS = true;                         // url: http://pan.certifikat.dk/sts/

/*			if(type==0)
 *                      {
 *                              smrt = CreateInstancePart1();
 *                              doc = SignParts(smrt, true, false, GetMOCESCertificate());
 *                      }
 *                      else if(type==1)
 *                      {
 *                              smrt = CreateInstancePart2();
 *                              doc = SignParts(smrt, false, true, GetMOCESCertificate());
 *                      }
 *                      else if (type == 2)
 *                      {
 *                              smrt = CreateInstancePart1AndPart2ForSameCertificate();
 *                              doc = SignParts(smrt, true, true, GetMOCESCertificate());
 *                      }
 *                      else if (type == 3)
 *                      {
 *                              smrt = CreateInstancePart1AndPart2ForDifferentCertificates();
 *                              doc = SignParts(smrt, true, false, GetSKSMOCESCertificate());
 *                              smrt = (SignedMortalityReasonType)Deserialize(doc.OuterXml, smrt.GetType());
 *                              doc = SignParts(smrt, false, true, GetMOCESCertificate());
 *                      }
 *                      //doc.Save(OutFileName);
 *
 *                      // Standard verifier
 *                      //bool bOK = VerifyDetachedSignature(OutFileName);
 *
 *                      smrt = (SignedMortalityReasonType)Deserialize(doc.OuterXml, smrt.GetType());
 */
            try
            {
                if (useSTS)
                {
                    AxisStsFacadeService sts = new AxisStsFacadeService();
                    sts.SetPolicy(new DGWSPolicy(GetSKSMOCESCertificate(), GetSKSVOCESCertificate(), true));
                    Object o = sts.issueIdCard(null);
                    int    g = 5;
                }

                MortalityRegistrationService service = new MortalityRegistrationService();
                service.SetPolicy(new DGWSPolicy(GetMOCESCertificate(), GetSKSVOCESCertificate(), false));
                bool b = service.Report(smrt);
//				bool b = service.RemoveReport("{B460D543-4627-4FEE-A310-367151256F32}");
                System.Diagnostics.Debug.WriteLine(b);
            }
            catch (Exception e)
            {
                Console.Out.Write(e.ToString());
                System.Diagnostics.Debug.WriteLine(e.ToString());
            }
        }
コード例 #2
0
        private SignedMortalityReasonType CreateInstancePart1()
        {
            SignedMortalityReasonType reason = new SignedMortalityReasonType();

            reason.MortalityReason                       = new MortalityReasonType();
            reason.MortalityReason.SchemaID              = Guid.NewGuid().ToString();
            reason.MortalityReason.PersonIdentifier      = new PersonIdentifierType();
            reason.MortalityReason.PersonIdentifier.Item = "1312814435";

            HospitalDoctorType doc = new HospitalDoctorType();

            doc.Part1 = CreatePart1();
            doc.Part1.DoctorFunction = DoctorFunctionType.HospitalDoctor;

            reason.Part1Signature = new SignedMortalityReasonTypePart1Signature();
            reason.MortalityReason.CertifyingDoctor      = new CertifyingDoctorType();
            reason.MortalityReason.CertifyingDoctor.Item = doc;

            return(reason);
        }
コード例 #3
0
        private SignedMortalityReasonType CreateInstancePart1AndPart2ForSameCertificate()
        {
            SignedMortalityReasonType reason = new SignedMortalityReasonType();

            reason.MortalityReason                       = new MortalityReasonType();
            reason.MortalityReason.SchemaID              = Guid.NewGuid().ToString();
            reason.MortalityReason.PersonIdentifier      = new PersonIdentifierType();
            reason.MortalityReason.PersonIdentifier.Item = "1312814435";

            PersonalDoctorType doc = new PersonalDoctorType();

            doc.Part1 = CreatePart1();
            doc.Part2 = CreatePart2();
            doc.Part1.DoctorFunction = DoctorFunctionType.PersonalGP;
            doc.Part2.DoctorFunction = DoctorFunctionType.PersonalGP;

            reason.AllSignature = new SignedMortalityReasonTypeAllSignature();
            reason.MortalityReason.CertifyingDoctor      = new CertifyingDoctorType();
            reason.MortalityReason.CertifyingDoctor.Item = doc;

            return(reason);
        }
コード例 #4
0
        // Sign an XML file and save the signature in a new file.
        XmlDocument SignParts(SignedMortalityReasonType smrt, Boolean bPart1, Boolean bPart2, X509Certificate2 certificate)
        {
            String xmlSource = Serialize(smrt, smrt.GetType());

            // Create a SignedXml object.
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(xmlSource);
            SignedXml signedXml = new SignedXml(doc);

            // Add parts to be signed
            if (bPart1)
            {
                AddSignatureReference(signedXml, doc, "Part1");
            }
            if (bPart2)
            {
                AddSignatureReference(signedXml, doc, "Part2");
            }

            // Get Certificate and signing Key
            signedXml.SigningKey = certificate.PrivateKey;

            // Add public key and certificate
            KeyInfo keyInfo = new KeyInfo();

            keyInfo.AddClause(new RSAKeyValue((RSA)certificate.PublicKey.Key));
            keyInfo.AddClause(new KeyInfoX509Data(certificate));
            signedXml.KeyInfo = keyInfo;

            // Compute the signature.
            signedXml.ComputeSignature();

            // Get the XML representation of the signature and save it to an XmlElement object.
            XmlElement xmlSignature = signedXml.GetXml();

            doc.PreserveWhitespace = true;
            XmlNode n   = doc.ImportNode(xmlSignature, true);
            String  res = n.OuterXml;

            String tagName = "";

            if (bPart1 && bPart2)
            {
                tagName = "AllSignature";
            }
            else if (bPart1)
            {
                tagName = "Part1Signature";
            }
            else if (bPart2)
            {
                tagName = "Part2Signature";
            }

            XmlNode root = doc.DocumentElement;
            XmlNode node = root[tagName];

            if (node.HasChildNodes == false)
            {
                node.AppendChild(n);
            }
            else
            {
                node.ReplaceChild(n, node.FirstChild);
            }
            return(doc);
        }