我想在文件上加密码,这样没有人可以在没有他们许可的情况下打开
答案 0 :(得分:0)
除非您对zip文件有密码保护,否则似乎没有简短的答案。
但是,您可以测试一些vba代码并使用可见性。它不会保证文档的安全性,因为Visio没有灵活性来保存为支持宏的绘图......限制了您使用VBA真正保护它的能力。
然而,你可以通过隐藏所有页面来煽动不受欢迎的用户阅读/观看的混乱......如果你愿意的话,默默无闻的安全......除非他们启用宏,否则他们仍然可以理想地做任何他们想做的事情这就是为什么你应该使用加密的zip软件和密码保护文件的文件。
无论如何......如果你还在为这个疯狂的实验做游戏我试过......
启用开发人员视图。然后进入查看代码。所以这是如何工作的...首先你需要生成你的密码哈希。然后,一旦创建了密码哈希...删除整个
看到弹出窗口后,按Ctrl + V并将内容粘贴到记事本中。你会得到这样的效果。
---------------------------
Your Password Hash
---------------------------
78F56C460A6CA4B15554E5FE5469AA036FB21EFA7151E991D6F9A9FDA4548F79
---------------------------
OK
---------------------------
获得哈希后,将私有变量设置为您自己的唯一哈希值。
mypassword = "78F56C460A6CA4B15554E5FE5469AA036FB21EFA7151E991D6F9A9FDA4548F79"
但有一点需要注意,您必须为您的HidePages脚本创建一个按钮...或者为热键组合创建一个键捕获事件并使用它添加一些额外的vba代码来保存,HidePages ,然后关闭visio。
Private Sub Document_DocumentOpened(ByVal doc As IVDocument)
Unauthenticated = True
myPassword = ""
Do While Unauthenticated
'Add number of tries
tries = tries + 1
'Prompt Password
TryPassword = InputBox("Enter the password", "Password Required!")
'Hash Password attempt and compare to Current Hash
If Sha256Hash(TryPassword) = myPassword Then
'Escape the loop
Unauthenticated = False
Call ShowPages
Else
If ((tries > 2) And (Unauthenticated = True)) Then KillVisio
End If
Loop
End Sub
Private Sub Document_DocumentOpened(ByVal doc As IVDocument)
Unauthenticated = True
myPassword = "6DA6F219DAC977DA75F2F2894F33ABAD5052AF2A60AE9219AF0E302EDDD5BBC4"
Do While Unauthenticated
'Add number of tries
tries = tries + 1
'Prompt Password
TryPassword = InputBox("Enter the password", "Password Required!")
'Hash Password attempt and compare to Current Hash
If Sha256Hash(TryPassword) = myPassword Then
'Escape the loop
Unauthenticated = False
Call ShowPages
Else
If ((tries > 2) And (Unauthenticated = True)) Then KillVisio
End If
Loop
End Sub
Sub KillVisio()
Set WShshell = CreateObject("WScript.Shell")
strcommand = "C:\windows\system32\taskkill /im visio.exe -f"
WShshell.Run ("cmd /c " & strcommand)
End Sub
Sub GenMyPwd()
MsgBox Sha256Hash("P@ssw0rd"), vbExclamation, "Your Password Hash"
End Sub
Sub ShowPages()
Set vPages = ThisDocument.Pages
For i = 1 To vPages.Count
Set Visibility = vPages(i).PageSheet.CellsU("UIVisibility")
If Visibility = 1 Then
Visibility.FormulaU = 0
End If
Next
End Sub
Sub HidePages()
Set vPages = ThisDocument.Pages
For i = 1 To vPages.Count
Set Visibility = vPages(i).PageSheet.CellsU("UIVisibility")
If Visibility = 0 Then
Visibility.FormulaU = 1
End If
Next
End Sub
Function Sha256Hash(str)
Dim b() As Byte
b = str
Sha256Hash = BytesToHex(Sha256HashBytes(b))
End Function
Function MD5HashBytes(aBytes)
Set objsha256 = CreateObject("System.Security.Cryptography.MD5CryptoServiceProvider")
s = objsha256.Initialize()
MD5HashBytes = objsha256.ComputeHash_2((aBytes))
End Function
Function Sha256HashBytes(aBytes)
'Set objsha256 = CreateObject("System.Security.Cryptography.MD5CryptoServiceProvider")
Set objsha256 = CreateObject("System.Security.Cryptography.SHA256Managed")
With objsha256
s = .Initialize()
Sha256HashBytes = .ComputeHash_2((aBytes))
End With
End Function
Function StringtoUTFBytes(aString)
Set UTF8 = CreateObject("System.Text.UTF8Encoding")
StringtoUTFBytes = UTF8.GetBytes_4(aString)
End Function
Function BytesToHex(aBytes)
For x = 1 To LenB(aBytes)
hexStr = Hex(AscB(MidB((aBytes), x, 1)))
If Len(hexStr) = 1 Then hexStr = "0" & hexStr
BytesToHex = BytesToHex & hexStr
Next
End Function
答案 1 :(得分:0)
Visio 2016包括权限管理支持。此功能基本上允许您保护文档并指定谁可以对该文档执行哪些操作。
也许这就是你追求的目标?