Created
January 29, 2019 19:02
-
-
Save soaresdiogo/5ff743c69207fdba42e43bc603a3c998 to your computer and use it in GitHub Desktop.
Sign File and Generate the PKCS7 "RSA"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string mapPath = HttpContext.Current.Server.MapPath("/"); | |
string pfx = @mapPath + "/keystore.p12"; | |
X509Certificate2 cert = new X509Certificate2(pfx, "password"); | |
string xml = @mapPath + "/file.SF"; | |
byte[] fileContent = System.IO.File.ReadAllBytes(xml); | |
ContentInfo contentInfo = new ContentInfo(fileContent); | |
SignedCms cms = new SignedCms(contentInfo, true); | |
CmsSigner signer = new CmsSigner(cert); | |
cms.ComputeSignature(signer); | |
byte[] pkcs7 = cms.Encode(); | |
File.WriteAllBytes(@mapPath + "/file.RSA", pkcs7); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment