-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIndex.razor
More file actions
124 lines (111 loc) · 4.72 KB
/
Index.razor
File metadata and controls
124 lines (111 loc) · 4.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
@page "/"
@using DevExpress.Pdf;
@using DevExpress.Drawing;
@using DevExpress.Blazor
@using System.Security.Cryptography.X509Certificates;
@inject IJSRuntime JS
<div class="container">
<div class="card mt-3">
<div class="card-header">
PDF Signature Validation
</div>
<div class="card-body px-0">
<DxFormLayout>
<DxFormLayoutItem ColSpanMd="12">
<Template>
<p class="ml-3 mr-3">
This application allows you to validate PDF signatures and generate an information report. Click "Browse" to upload a file.
All detected signatures are shown in the table below.
</p>
</Template>
</DxFormLayoutItem>
<DxFormLayoutItem>
<Template>
<div class="input-group ml-3 mb-3">
<div class="custom-file">
<InputFile OnChange="@LoadDocument" class="custom-file-input"></InputFile>
<label class="custom-file-label">Load a PDF File</label>
</div>
</div>
</Template>
</DxFormLayoutItem>
</DxFormLayout>
@if(isLoading) {
<p class="ml-3 mb-3">Uploading...</p>
} else {
@if(signatureList.Count > 0) {
<div class="col">
<DxGrid Data="@signatureList"
CssClass="mt-3"
PagerVisible="false">
<DxGridDataColumn FieldName="@nameof(SignatureInfo.Name)"
Caption="Field Name" />
<DxGridDataColumn FieldName="@nameof(SignatureInfo.IssuerName)"
Caption="Certificate Issuer Name" />
<DxGridDataColumn FieldName="@nameof(SignatureInfo.SignerName)"
Caption="Signer Name" />
<DxGridDataColumn FieldName="@nameof(SignatureInfo.Verified)"
Caption="Is Signature Valid" />
<DxGridDataColumn FieldName="@nameof(SignatureInfo.CertificateValid)"
Caption="Is Certificate Valid" />
</DxGrid>
</div>
} else if(FileIsLoaded) {
<p class="ml-3 mb-3">The loaded file does not contain any signatures</p>
}
}
</div>
</div>
</div>
@code {
bool isLoading;
List<SignatureInfo> signatureList = new List<SignatureInfo>();
PdfDocumentSigner? documentSigner;
bool FileIsLoaded = false;
async Task LoadDocument(InputFileChangeEventArgs e) {
signatureList.Clear();
isLoading = true;
await using MemoryStream fs = new();
if (e.FileCount > 0)
{
FileIsLoaded = true;
await e.File.OpenReadStream().CopyToAsync(fs);
documentSigner = new(fs);
isLoading = false;
var signatureInfo = documentSigner.GetSignatureInfo();
if (signatureInfo != null)
{
foreach (var signature in signatureInfo)
{
GenerateInfoList(signature);
}
}
}else {
FileIsLoaded = false;
}
}
void GenerateInfoList(PdfSignatureInfo pdfSignature) {
var signerName = pdfSignature.SignerName;
var signature = documentSigner.GetPdfPkcs7Signature(pdfSignature.FieldName);
bool isSignatureValid = signature.VerifySignature();
var certificate = signature.GetSignatureCertificate();
signatureList.Add(new SignatureInfo(pdfSignature, certificate, isSignatureValid));
}
public class SignatureInfo {
public string Name { get; private set; }
public X509Certificate2 Certificate { get; set; }
public string SignerName;
public bool Verified;
public bool CertificateValid;
public string IssuerName;
public SignatureInfo(PdfSignatureInfo pdfSignature, X509Certificate2 certificate, bool isSignatureValid)
{
Name = pdfSignature.FieldName;
Certificate = certificate;
SignerName = pdfSignature.SignerName;
Verified = isSignatureValid;
IssuerName = certificate.Issuer;
CertificateValid = certificate.Verify();
}
}
}