C# Aloaha Crypto Beispiel

Unser Kunde Matthew Ciantar hat uns mit einem exzellenten C# Codebeispiel beliefert. Dieses Beispiel zeigt, wie die Aloaha APIs in C# benutzt werden können. Nachfolgend sehen Sie den Quellcode dazu. Am Ende der Seite können Sie die Dateien herunterladen.

/*
* This command line applications uses Aloaha PDF Crypter
* to encrypt a PDF File with a given Public Key (Cer File).
*
* Author: Matthew Ciantar
* Date: 2006/01/20
*
* License for the Aloaha PDF Crypter is required
* Evaluation of API works without valid License
*
**/

using System;
using System.IO;
using System.Reflection;

namespace PDFCrypterTool
{
class Crypter
{
static void Main(string[] args)
{
if (args.Length == 3)
{
// Store Arguments in Local Variables
string CertificateFilePath = args[0];
string PDFSourceFilePath = args[1];
string PDFDestinationFilePath = args[2];

// Check existance of Certificate and Source File
if (File.Exists(CertificateFilePath) && File.Exists(PDFSourceFilePath))
{
Type aloahapdf = Type.GetTypeFromProgID("aloahapdf.edit");
object aloahapdfLateBound = Activator.CreateInstance(aloahapdf);

object[] Certificate = new object[1];
Certificate[0] = CertificateFilePath;
aloahapdf.InvokeMember("add_recipient", BindingFlags.Default | BindingFlags.InvokeMethod,
null, aloahapdfLateBound, Certificate );

object[] SourceFileName = new object[1];
SourceFileName[0] = PDFSourceFilePath;

object[] OriginalPDFString = new object[1];
OriginalPDFString[0] = (string)aloahapdf.InvokeMember("ReadStringFromFile", BindingFlags.Default | BindingFlags.InvokeMethod,
null, aloahapdfLateBound, SourceFileName);

string PDFString = (string)aloahapdf.InvokeMember("encrypt_pdf_string", BindingFlags.Default | BindingFlags.InvokeMethod,
null, aloahapdfLateBound, OriginalPDFString);

if (null != PDFString)
{
// Save file if encryption was succesfully
string DestinationFileName = PDFDestinationFilePath;
bool noOverwrite = false;

object[] WriteFileParams = new object[3];
WriteFileParams[0] = PDFDestinationFilePath;
WriteFileParams[1] = PDFString;
WriteFileParams[2] = noOverwrite;

aloahapdf.InvokeMember("WriteStringToFile", BindingFlags.Default | BindingFlags.InvokeMethod,
null, aloahapdfLateBound, WriteFileParams);
}
else
{
Console.Write("Failed to Encrypt file with Public Key.");
}
}
else
{
Console.Write("Invalid Files sepcified.");
Environment.ExitCode = -1;
}
}
else
{
PrintUsage();
Environment.ExitCode = -1;
}
}

public static void PrintUsage()
{
Console.Write("Usage: " + System.Environment.GetCommandLineArgs()[0] + " [Certificate File] [Soruce PDF] [Encrypted PDF]");
}
}
}

 Program.cs.txt (3,51 KB)

 Executable.zip (3,61 KB)
Aloaha Secure StickAloaha Smart LoginAloaha Smartcard ConnectorAloaha PDF SuiteE-Mail-TextePDF ScriptingAloaha PDF Saver/SignatorAloaha Multisignator FAQAloaha PDF SDKPDF Signatur APIAutomatische SeitennummerierungPDF AnhängePDF2ImageImage 2 PDFPDF Formular APIPDF Formular OCXVerbinden von XML und PDFXML Daten exportierenSenden Button einfügenSicherer PDF ViewerPDF OptimiererPDF Crypter APIC# Crypto Beispiel40/128 Bit PDF Verschlüsselungs APIBriefköpfe anfügenPDF BriefpapierPDF WasserzeichenPDF Druck APIPDF LesezeichenPDF BarcodeNormalisierung von PDF SeitenZertifikateingenschaftenAloaha Time StampingNativ unterstützte SmartCards Sichere PIN EingabeSichere PIN Speicherung