In this blog we will see how we can leverage SecurityParams AutoCAD .NET API to digitally sign drawings[read DWG\DXF].
First and foremost important thing is to have Digital Certificate issued from a recognised vendor, about code signing fundamentals you can refer to this, Certificate vendor generally issues a PFX and password which is require to register in store, for registration of Certificate in store, we can take help of Certificate Import Wizard available in Internet Explorer Tools\Internet Options\Content\Certificates
After registering Certificate in store, here are few preliminary checks.
- Launch “AcSignApply.exe” Tool shipped with AutoCAD and available in ProgramFiles\AutoDesk\AutoCAD XXX\. And check if your Digital Certificate is available.
- Interactively attach your Digital signature to DWG and check if drawing is getting signed.
In the below screen shot I have shown a Certificate issued by VeriSign which I used for testing.
If you are able to sign the drawings interactively the same should be possible using API, here is the code to do.
public void DWGSign() // This method can have any name
// The path to the certificate.
string PFXpath = "C:\\Sign\\Test.pfx";
/*password given by CA,
* this is same password which you enter while installing PFX in store*/
string pwd = "TestPassword";
// Load the certificate into an X509Certificate object.
X509Certificate2 cert = new X509Certificate2();
cert.Import(PFXpath, pwd, X509KeyStorageFlags.PersistKeySet);
bool verificationResult = cert.Verify();
/*Get the CommanName, CN of CA*/
issuer = cert.GetNameInfo(X509NameType.SimpleName, true);
subject = cert.GetNameInfo(X509NameType.SimpleName, false);
/*get serial number*/
serialNumber = cert.SerialNumber;
comment = "You can describe the Drawing info here";
/*If timeserver is null, application picks computer time*/
timeServer = "Natl Inst of Standards and Technology(time.nist.gov)";
/*Encyrption key size*/
keyLength = (uint)cert.PublicKey.Key.KeySize;
providerType = (uint)cert.Version;
string mainfullpath = "C:\\Temp\\Architectural - Metric.dwg";
using (tempDb = new Database(false, true))
SecurityParameters sp = new SecurityParameters(null,
mainfullpath = "C:\\Temp\\Signednew.dwg";
tempDb.SaveAs(mainfullpath, false, DwgVersion.Current, sp);
catch (SystemException ex)
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
After succeeding code, you would see a logo on the DWG thumbnail and when opened in AutoCAD you would get entire signing information of the drawing.