-
Notifications
You must be signed in to change notification settings - Fork 236
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Patrick Ammann
committed
Jun 2, 2022
1 parent
bad9cc5
commit 30e816a
Showing
20 changed files
with
684 additions
and
25 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System; | ||
using PdfSharpCore.Drawing; | ||
using PdfSharpCore.Drawing.Layout; | ||
|
||
namespace PdfSharpCore.Pdf.Signatures | ||
{ | ||
internal class DefaultAppearanceHandler : ISignatureAppearanceHandler | ||
{ | ||
public string Location { get; set; } | ||
public string Reason { get; set; } | ||
public string Signer { get; set; } | ||
|
||
|
||
public void DrawAppearance(XGraphics gfx, XRect rect) | ||
{ | ||
var backColor = XColor.Empty; | ||
var defaultText = string.Format("Signed by: {0}\nLocation: {1}\nReason: {2}\nDate: {3}", Signer, Location, Reason, DateTime.Now); | ||
|
||
XFont font = new XFont("Verdana", 7, XFontStyle.Regular); | ||
|
||
XTextFormatter txtFormat = new XTextFormatter(gfx); | ||
|
||
var currentPosition = new XPoint(0, 0); | ||
|
||
txtFormat.DrawString(defaultText, | ||
font, | ||
new XSolidBrush(XColor.FromKnownColor(XKnownColor.Black)), | ||
new XRect(currentPosition.X, currentPosition.Y, rect.Width - currentPosition.X, rect.Height), | ||
XStringFormats.TopLeft); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Security.Cryptography.Pkcs; | ||
using System.Security.Cryptography.X509Certificates; | ||
using System.Text; | ||
|
||
namespace PdfSharpCore.Pdf.Signatures | ||
{ | ||
public class DefaultSigner : ISigner | ||
{ | ||
public X509Certificate2 Certificate { get; private set; } | ||
|
||
public DefaultSigner(X509Certificate2 Certificate) | ||
{ | ||
this.Certificate = Certificate; | ||
} | ||
|
||
public byte[] GetSignedCms(Stream stream) | ||
{ | ||
var range = new byte[stream.Length]; | ||
|
||
stream.Position = 0; | ||
stream.Read(range, 0, range.Length); | ||
|
||
|
||
|
||
var contentInfo = new ContentInfo(range); | ||
|
||
SignedCms signedCms = new SignedCms(contentInfo, true); | ||
CmsSigner signer = new CmsSigner(Certificate); | ||
signer.UnsignedAttributes.Add(new Pkcs9SigningTime()); | ||
|
||
signedCms.ComputeSignature(signer, true); | ||
var bytes = signedCms.Encode(); | ||
|
||
return bytes; | ||
} | ||
|
||
|
||
|
||
public string GetName() | ||
{ | ||
return Certificate.GetNameInfo(X509NameType.SimpleName, false); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using PdfSharpCore.Drawing; | ||
|
||
namespace PdfSharpCore.Pdf.Signatures | ||
{ | ||
public interface ISignatureAppearanceHandler | ||
{ | ||
void DrawAppearance(XGraphics gfx, XRect rect); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Text; | ||
|
||
namespace PdfSharpCore.Pdf.Signatures | ||
{ | ||
public interface ISigner | ||
{ | ||
byte[] GetSignedCms(Stream stream); | ||
|
||
string GetName(); | ||
|
||
} | ||
} |
Oops, something went wrong.