Makstvell
Makstvell
CC#
Created by Makstvell on 3/7/2024 in #help
AS2 over http C# Send message with signature to mendelson server.
And this: request.Headers.Add("EDIINT-Features", "multiple-attachments"); // Create multipart form data string boundary = "STARTBOUND_" + Guid.NewGuid().ToString() + "_ENDBOUND"; var formData = new MultipartFormDataContent(boundary);
formData.Headers.ContentType = new MediaTypeHeaderValue("multipart/signed"); formData.Headers.ContentType.Parameters.Add(new NameValueHeaderValue("protocol", ""application/pkcs7-signature"")); formData.Headers.ContentType.Parameters.Add(new NameValueHeaderValue("micalg", "sha1")); formData.Headers.ContentType.Parameters.Add(new NameValueHeaderValue("boundary", $""{boundary}"")); formData.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment"); formData.Headers.ContentDisposition.FileName = "smime.p7m"; var fileContentPart = new ByteArrayContent(as2Message); fileContentPart.Headers.ContentType = new MediaTypeHeaderValue("application/EDIFACT"); fileContentPart.Headers.Add("Content-Transfer-Encoding", "binary"); fileContentPart.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = "data.edifact" }; formData.Add(fileContentPart); var signatureData = SignData(as2Message, _PathToMyPrivateKey, _Passphrase); var signatureContentPart = new StringContent(Convert.ToBase64String(signatureData)); signatureContentPart.Headers.ContentType = new MediaTypeHeaderValue("application/pkcs7-signature"); signatureContentPart.Headers.ContentType.Parameters.Add(new NameValueHeaderValue("name", "smime.p7s")); signatureContentPart.Headers.ContentType.Parameters.Add(new NameValueHeaderValue("smime-type", "signed-data")); signatureContentPart.Headers.Add("Content-Transfer-Encoding", "base64"); signatureContentPart.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = "smime.p7s" }; formData.Add(signatureContentPart); request.Content = formData;
5 replies
CC#
Created by Makstvell on 3/7/2024 in #help
AS2 over http C# Send message with signature to mendelson server.
Now for Sign data I have this code: public byte[] SignData(byte[] data, string p12FilePath, string p12Password) { byte[] contentHash; using (SHA256 sha256 = SHA256.Create()) { contentHash = sha256.ComputeHash(data); } // Load the signer's certificate X509Certificate2 signerCert = new X509Certificate2(p12FilePath, p12Password); // Create a SignedCms object SignedCms signedCms = new SignedCms(SubjectIdentifierType.IssuerAndSerialNumber, new ContentInfo(contentHash), false); // Create a CmsSigner object CmsSigner signer = new CmsSigner(signerCert); signer.DigestAlgorithm = new Oid("2.16.840.1.101.3.4.2.1"); // Sign the hash of the content signedCms.ComputeSignature(signer, false); // Encode the signed CMS message byte[] signature = signedCms.Encode(); return signature; }
5 replies