| using System; |
| using System.Security.Cryptography.X509Certificates; |
| using Azure.Identity; |
| using Azure.Security.KeyVault.Certificates; |
| |
| string keyVaultUrl = "https://txtestvault.vault.azure.net/"; |
| string certificateName = "txselfcert"; |
| string password = "123"; |
| |
| // Create a CertificateClient using DefaultAzureCredential for authentication |
| var credential = new DefaultAzureCredential(true); |
| var client = new CertificateClient(new Uri(keyVaultUrl), credential); |
| |
| // Read the PFX file into a byte array |
| byte[] pfxBytes = await File.ReadAllBytesAsync("certificate.pfx"); |
| |
| // Import the certificate into Key Vault |
| var importOptions = new ImportCertificateOptions(certificateName, pfxBytes) |
| { |
| Password = password |
| }; |
| |
| var importedCertificate = await client.ImportCertificateAsync(importOptions); |
| |
| Console.WriteLine($"Certificate '{certificateName}' imported successfully."); |
| using System; |
| using System.Security.Cryptography.X509Certificates; |
| using Azure.Identity; |
| using Azure.Security.KeyVault.Certificates; |
| using TXTextControl; |
| |
| string keyVaultUrl = "https://txtestvault.vault.azure.net/"; |
| string certificateName = "txselfcert"; |
| |
| // Create a CertificateClient using DefaultAzureCredential for authentication |
| var credential = new DefaultAzureCredential(true); |
| var client = new CertificateClient(new Uri(keyVaultUrl), credential); |
| |
| // Retrieve the certificate from the Azure Key Vault |
| var certificateWithPolicy = client.GetCertificate(certificateName); |
| byte[] pfxBytes = certificateWithPolicy.Value.Cer; // Extract the certificate's byte array |
| |
| // Load the certificate into an X509Certificate2 object for digital signature purposes |
| var cert = new X509Certificate2(pfxBytes, (string)null, X509KeyStorageFlags.PersistKeySet); |
| |
| // Initialize TXTextControl to create and save a document with the digital signature |
| using (var tx = new ServerTextControl()) |
| { |
| tx.Create(); |
| tx.Text = "Hello, World!"; |
| |
| // Prepare the digital signature for the document |
| var saveSettings = new SaveSettings |
| { |
| DigitalSignature = new DigitalSignature(cert, null) |
| }; |
| |
| // Save the document as a PDF with the digital signature |
| tx.Save("result.pdf", StreamType.AdobePDF, saveSettings); |
| } |
| |
| Console.WriteLine(" DF saved with digital signature."); |
当您在 Acrobat Reader 中打开创建的 PDF 文档时,您可以在