求VB.NET生成TET文件的加密方法使用加密方式存储即可实现别人无法查看内容,加密的方式有很多,适用你这里使用的是可逆的算法,推荐你使用DES加密
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.IO
Imports System.Security
Imports System.Security.Cryptography
Namespace ZU14
NotInheritable Public Class DES
Private iv As String = "1234的yzo"
Private key As String = "123在yzo"
'/ summary
'/ DES加密偏移量,必须是=8位长的字符串
'/ /summary
Public Property IV() As String
Get
Return iv
End Get
Set
iv = value
End Set
End Property
'/ summary
'/ DES加密的私钥 , 必须是8位长的字符串
'/ /summary
Public Property Key() As String
Get
Return key
End Get
Set
key = value
End Set
End Property
'/ summary
'/ 对字符串进行DES加密
'/ /summary
'/ param name="sourceString"待加密的字符串/param
'/ returns加密后的BASE64编码的字符串/returns
Public Function Encrypt(sourceString As String) As String
Dim btKey As Byte() = Encoding.Default.GetBytes(key)
Dim btIV As Byte() = Encoding.Default.GetBytes(iv)
Dim des As New DESCryptoServiceProvider()
Dim ms As New MemoryStream()
Try
Dim inData As Byte() = Encoding.Default.GetBytes(sourceString)
Try
Dim cs As New CryptoStream(ms, des.CreateEncryptor(btKey, btIV), CryptoStreamMode.Write)
Try
cs.Write(inData, 0, inData.Length)
cs.FlushFinalBlock()
Finally
cs.Dispose()
End Try
Return Convert.ToBase64String(ms.ToArray())
Catch
End Try
Finally
ms.Dispose()
End Try
End Function 'Encrypt
'/ summary
'/ 对DES加密后的字符串进行解密
'/ /summary
'/ param name="encryptedString"待解密的字符串/param
'/ returns解密后的字符串/returns
Public Function Decrypt(encryptedString As String) As String
Dim btKey As Byte() = Encoding.Default.GetBytes(key)
Dim btIV As Byte() = Encoding.Default.GetBytes(iv)
Dim des As New DESCryptoServiceProvider()
Dim ms As New MemoryStream()
Try
Dim inData As Byte() = Convert.FromBase64String(encryptedString)
Try
Dim cs As New CryptoStream(ms, des.CreateDecryptor(btKey, btIV), CryptoStreamMode.Write)
Try
cs.Write(inData, 0, inData.Length)
cs.FlushFinalBlock()
Finally
cs.Dispose()
End Try
Return Encoding.Default.GetString(ms.ToArray())
Catch
End Try
Finally
ms.Dispose()
End Try
End Function 'Decrypt
'/ summary
'/ 对文件内容进行DES加密
'/ /summary
'/ param name="sourceFile"待加密的文件绝对路径/param
'/ param name="destFile"加密后的文件保存的绝对路径/param
Overloads Public Sub EncryptFile(sourceFile As String, destFile As String)
If Not File.Exists(sourceFile) Then
Throw New FileNotFoundException("指定的文件路径不存在!", sourceFile)
End If
Dim btKey As Byte() = Encoding.Default.GetBytes(key)
Dim btIV As Byte() = Encoding.Default.GetBytes(iv)
Dim des As New DESCryptoServiceProvider()
Dim btFile As Byte() = File.ReadAllBytes(sourceFile)
Dim fs As New FileStream(destFile, FileMode.Create, FileAccess.Write)
Try
Try
Dim cs As New CryptoStream(fs, des.CreateEncryptor(btKey, btIV), CryptoStreamMode.Write)
Try
cs.Write(btFile, 0, btFile.Length)
cs.FlushFinalBlock()
Finally
cs.Dispose()
End Try
Catch
Finally
fs.Close()
End Try
Finally
fs.Dispose()
End Try
End Sub 'EncryptFile
'/ summary
'/ 对文件内容进行DES加密,加密后覆盖掉原来的文件
'/ /summary
'/ param name="sourceFile"待加密的文件的绝对路径/param
Overloads Public Sub EncryptFile(sourceFile As String)
EncryptFile(sourceFile, sourceFile)
End Sub 'EncryptFile
'/ summary
'/ 对文件内容进行DES解密
'/ /summary
'/ param name="sourceFile"待解密的文件绝对路径/param
'/ param name="destFile"解密后的文件保存的绝对路径/param
Overloads Public Sub DecryptFile(sourceFile As String, destFile As String)
If Not File.Exists(sourceFile) Then
Throw New FileNotFoundException("指定的文件路径不存在!", sourceFile)
End If
Dim btKey As Byte() = Encoding.Default.GetBytes(key)
Dim btIV As Byte() = Encoding.Default.GetBytes(iv)
Dim des As New DESCryptoServiceProvider()
Dim btFile As Byte() = File.ReadAllBytes(sourceFile)
Dim fs As New FileStream(destFile, FileMode.Create, FileAccess.Write)
Try
Try
Dim cs As New CryptoStream(fs, des.CreateDecryptor(btKey, btIV), CryptoStreamMode.Write)
Try
cs.Write(btFile, 0, btFile.Length)
cs.FlushFinalBlock()
Finally
cs.Dispose()
End Try
Catch
Finally
fs.Close()
End Try
Finally
fs.Dispose()
End Try
End Sub 'DecryptFile
'/ summary
'/ 对文件内容进行DES解密,加密后覆盖掉原来的文件
'/ /summary
'/ param name="sourceFile"待解密的文件的绝对路径/param
Overloads Public Sub DecryptFile(sourceFile As String)
DecryptFile(sourceFile, sourceFile)
End Sub 'DecryptFile
End Class 'DES
End Namespace 'ZU14
对文本文件加密
Dim des As New ZU14.DES()
des.IV = "abcd哈哈笑"
des.Key = "必须八位"
'加密
des.EncryptFile("d:\a.txt", "d:\b.txt")
'解密
des.DecryptFile("d:\b.txt")
如何用vb对文件夹进行加密自行编写VB代码对文件夹进行加密 。
单只是文件夹加密vb.net文本夹加密的话vb.net文本夹加密,例如vb.net文本夹加密:
在需要加密的文件夹路径创建一个BUG文件夹vb.net文本夹加密,然后把需要加密的文件夹剪切进去 。
所谓的BUG文件夹vb.net文本夹加密,就是Windows环境下无法打开无法读取无法删除的文件夹 。不过可以用命令提示符来创建、打开、删除 。
怎样用VB给文件夹进行密码加密文件或文件夹vb.net文本夹加密的加密、解密
'此方法对 WinXP 系统有效,Win98 没试验过 。小心vb.net文本夹加密:不能用于系统文件或文件夹,否则会使系统瘫痪 。
'加密:利用 API 函数在文件或文件夹名称末尾添上字符“..\” 。比如 , 将文件夹“MyPath”更名为“MyPath..\”,在vb.net文本夹加密我vb.net文本夹加密的电脑中显示vb.net文本夹加密的名称就是“MyPath.” 。系统会无法识别,此文件或文件夹就无法打开和修改 , 也无法删除 。著名的病毒 Autorun 就是玩的这个小把戏 。
'解密:去掉文件或文件夹名称末尾的字符“..\”
'将以下代码复制到 VB 的窗体代码窗口即可
'例子需控件:Command1、Command2、Text1,均采用默认属性设置
Private Const MAX_PATH = 260
Private Type FileTime' 8 Bytes
LTime As Long
HTime As Long
End Type
Private Type Win32_Find_Data
dwFileAttributes As Long
ftCreationTime As FileTime
ftLastAccessTime As FileTime
ftLastWriteTime As FileTime
nFileSizeHigh As Long
nFileSizeLow As Long
dwReserved0 As Long
dwReserved1 As Long
cNameFile As String * MAX_PATH
cAlternate As String * 14
End Type
Private Declare Function MoveFileEx Lib "kernel32" Alias "MoveFileExA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal dwFlags As Long) As Long
Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
Private Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (ByVal lpNameFile As String, lpFindFileData As Win32_Find_Data) As Long
Private Declare Function FindNextFile Lib "kernel32" Alias "FindNextFileA" (ByVal hFindFile As Long, lpFindFileData As Win32_Find_Data) As Long
Private Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As Long
Private Sub Form_Load()
Text1.Text = "C:\MyPath"
Command1.Caption = "解密": Command2.Caption = "加密"
Me.Caption = "目录或文件的加解密"
End Sub
Private Sub Command1_Click()
Call SetPathName(False) '解密
End Sub
Private Sub Command2_Click()
Call SetPathName(True)'加密
End Sub
Private Sub SetPathName(SetMi As Boolean)
Dim nName As String, NewName As String, nSort As String, nCap As String, dl As Long
nName = Trim(Text1.Text)
If Right(nName, 3) = "..\" Then nName = Left(nName, Len(nName) - 3)
If Right(nName, 1) = "\" Then nName = Left(nName, Len(nName) - 1)
If SetMi Then
NewName = nName"..\"
Else
NewName = nName
nName = nName"..\"
End If
If SetMi Then nCap = "加密" Else nCap = "解密"
nSort = GetShortName(nName) '转变其中的 ..\
If nSort = "" Then
MsgBox "文件没有找到:"vbCrLfnName, vbCritical, nCap
Exit Sub
End If
If MoveFileEx(nSort, NewName, 0) = 0 Then Exit Sub'文件更名:非零表示成功,支持只读文件
MsgBox nCap"成功:"vbCrLfnName, vbInformation, nCap
End Sub
Public Function GetShortName(F As String, Optional ShortAll As Boolean) As String
'转变为短文件名,如果目录或文件不存在就返回空 。可用于判断某目录或文件是否存在
'不能直接用 API 函数 GetShortPathName, 因它不支持 ..\
'ShortAll=T 表示全部转变为短名称,否则只转变其中的点点杠“..\”
Dim FondID As Long, ID1 As Long, S As Long, nPath As String
Dim nF As String, InfoF As Win32_Find_Data, qF As String, hF As String
Dim nName As String, nName1 As String
nF = F
Do
S = InStr(nF, "..\")
If S = 0 Then Exit Do
qF = Left(nF, S2): hF = Mid(nF, S3) '分为前后两部分
CutPathName qF, nPath, nName
nName = LCase(nName)
qF = nPath"\""*."
FondID = FindFirstFile(qF, InfoF) '-1表示失败 。查找所有文件(夹)
ID1 = FondID
Do
If FondID = Find_Err Or ID1 = 0 Then GoTo Exit1'没有找到符合条件的条目
nName1 = LCase(CutChr0(InfoF.cNameFile))'文件(夹)名称
If nName1".\" = nName Then
nName1 = CutChr0(InfoF.cAlternate) '用短文件名代替
If hF = "" Then nF = nPath"\"nName1 Else nF = nPath"\"nName1"\"hF
Exit Do
End If
ID1 = FindNextFile(FondID, InfoF) '查找下一个,0表示失败
Loop
FindClose FondID
Loop
Exit1:
FindClose FondID
S = MAX_PATH: nName = String(S, vbNullChar)
ID1 = GetShortPathName(nF, nName, S) '返回实际字节数,0表示失败
If ID1 = 0 Then Exit Function
If ShortAll Then
If ID1S Then
S = ID1: nName = String(S, vbNullChar)
ID1 = GetShortPathName(nF, nName, S) '返回实际字节数
End If
GetShortName = CutChr0(nName)
Else
GetShortName = nF
End If
End Function
Public Sub CutPathName(ByVal F As String, nPath As String, nName As String)
Dim I As Long, LenS As Long
LenS = Len(F)
For I = LenS - 1 To 2 Step -1
If Mid(F, I, 1) = "\" Then
nPath = Left(F, I - 1): nName = Mid(F, I1)
GoTo Exit1
End If
Next
nPath = F: nName = ""
Exit1:
If Right(nPath, 2) = ".." Then
nPath = nPath"\"
Else
If Right(nPath, 1) = "\" Then nPath = Left(nPath, Len(nPath) - 1)
End If
If Right(nName, 1) = "\" And Right(nName, 3)"..\" Then nName = Left(nName, Len(nName) - 1)
End Sub
Private Function CutChr0(xx As String) As String
Dim S As Long
S = InStr(xx, vbNullChar)
If S0 Then CutChr0 = Left(xx, S - 1) Else CutChr0 = xx
End Function
'参考资料见下
用VB.net编写一个加密解密软件"采用DES算法"这个说法不明确,首先是使用多少位的DES进行加密 , 通常是128位或192位,其次是,要先把主密钥转化成散列,才能供DES进行加密 , 转化的方法是什么没有明确,通常是md5,所以有的银行卡说是128位md5 3DS就是指用md5转换主密钥散列 , 用DES进行加密,但是DES本身是64位(包含校验码),2DES是128位,3DES是192位,但是没有2DES的叫法,所以128位、192位统称3DES
要完整的md5 3DS实例,需要100分以上,要不到我的空间中查找相关的文章
vb.net文本框设置密码如何隐藏你是说如何把密码框输入的内容变成类似“*”?
在视图窗口,点击文本框 , 在右侧的属性栏里有一个属性是“passwordChar”
你给设置成想要的隐藏的字符就行,类似于“*”
希望能对你有帮助 。
怎么用VB给文件夹加密1、由于采用二进制读取文件的方式vb.net文本夹加密,因此加密时一般可以不考虑文件类型 。
2、这里只进行一次异或运算vb.net文本夹加密,如有需要可以进行多次异或运算 。
3、此加密算法速度快 , 当然加密强度也低 vb.net文本夹加密;
参考代码如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
'-----------------------------------------------------------------------
'函数说明: 使用异或运算加密文件(可加密大部分文件)
'参数说明: key - 密钥
'fileName - 普通文件名,
'encryptFileName - 加密后的文件名
'返回值:true - 成功,false - 失败
'-----------------------------------------------------------------------
Private Function XOR_Encrypt(key As Integer, fileName As String, encryptFileName As String) As Boolean
On Error GoTo errHandler
Dim inputFileNo As Integer
Dim fileBytes() As Byte
Dim length As Long
XOR_Encrypt = False
'打开文件并保存在二进制数组中
inputFileNo = FreeFile
Open fileName For Binary As #inputFileNo
length = LOF(inputFileNo)
If length = 0 Then
MsgBox "退出加密:文件内容为空vb.net文本夹加密!", vbInformation, "提示"
Exit Function
End If
ReDim fileBytes(length - 1) As Byte
Get inputFileNo, , fileBytes()
Close #inputFileNo
'将该二进制数组进行异或加密
Dim i As Long
For i = LBound(fileBytes) To UBound(fileBytes)
fileBytes(i) = fileBytes(i) Xor key
Next
'将异或加密后的二进制数组保存在新的文件中
Dim outputFileNo As Integer
outputFileNo = FreeFile
Open encryptFileName For Binary As #outputFileNo
Put outputFileNo, , fileBytes
Close #outputFileNo
XOR_Encrypt = True
errHandler:
If Err.Number Then
MsgBox "加密过程中出错:"Err.Description, vbCritical, "错误"
XOR_Encrypt = False
Resume Next
End If
End Function
【vb.net文本夹加密 vb加密程序代码】vb.net文本夹加密的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于vb加密程序代码、vb.net文本夹加密的信息别忘了在本站进行查找喔 。
推荐阅读
- 包含sqlserverbulkinsert的词条
- 以太坊锁算力显卡怎么破解,以太坊显卡算力收益计算
- 怎么在开机时检测修复硬盘,电脑硬盘检测修复命令
- linux命令行下载文件 命令行下载文件到本地
- init.d运行python,python init py
- 一号虚拟主机管理系统,虚拟总机一号通
- 做无人直播实操,无人直播怎么赚钱的
- java代码实现排序 java中排序的代码
- c语言如何加入子程序,c语言调用汇编子程序