<CommandMethod("PwdProtect")> _
Public Shared Sub PwdProtectMethod()
Dim dwgFilePath As [String] = "C:\Test.dwg"
If Not System.IO.File.Exists(dwgFilePath) Then
Return
End If
Dim password As String = "Autodesk"
'Choose a provider name from the list of providers
'
http://msdn.microsoft.com/en-us/library/windows/desktop/ 'aa380243(v=vs.85).aspx
Dim providerName As String = "Microsoft Enhanced Cryptographic Provider v1.0"
Dim subject As String Is Nothing
Dim issuer As String Is Nothing
Dim serialNumber As String Is Nothing
Dim comment As String Is Nothing
Dim timeServer As String Is Nothing
Dim actions As SecurityActions = SecurityActions.EncryptData
Dim algorithm As SecurityAlgorithm = SecurityAlgorithm.RC4
' Find the default/min/max key length
' for the provider name used
'
http://msdn.microsoft.com/en-us/library/windows/desktop/ ' bb931357(v=vs.85).aspx
Dim keyLength As UInteger = 128
Dim providerType As UInteger = 1
Try
Using db As New Database(False, True)
db.ReadDwgFile(dwgFilePath, System.IO.FileShare.ReadWrite, True, "")
Dim sp As New SecurityParameters(password, providerName, subject, issuer, serialNumber, comment, _
timeServer, actions, algorithm, keyLength, providerType)
db.SaveAs(db.Filename, False, DwgVersion.Current, sp)
End Using
Catch ex As System.Exception
Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
ed.WriteMessage(ex.Message)
End Try
End Sub