十年網(wǎng)站開發(fā)經(jīng)驗(yàn) + 多家企業(yè)客戶 + 靠譜的建站團(tuán)隊(duì)
量身定制 + 運(yùn)營維護(hù)+專業(yè)推廣+無憂售后,網(wǎng)站問題一站解決
自行編寫VB代碼對文件夾進(jìn)行加密。
在玉州等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供網(wǎng)站制作、網(wǎng)站設(shè)計(jì) 網(wǎng)站設(shè)計(jì)制作定制網(wǎng)站設(shè)計(jì),公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),成都品牌網(wǎng)站建設(shè),全網(wǎng)營銷推廣,成都外貿(mào)網(wǎng)站制作,玉州網(wǎng)站建設(shè)費(fèi)用合理。
單只是文件夾加密的話,例如:
在需要加密的文件夾路徑創(chuàng)建一個(gè)BUG文件夾,然后把需要加密的文件夾剪切進(jìn)去。
所謂的BUG文件夾,就是Windows環(huán)境下無法打開無法讀取無法刪除的文件夾。不過可以用命令提示符來創(chuàng)建、打開、刪除。
使用加密方式存儲即可實(shí)現(xiàn)別人無法查看內(nèi)容,加密的方式有很多,適用你這里使用的是可逆的算法,推薦你使用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?
'/?對字符串進(jìn)行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加密后的字符串進(jìn)行解密 ?
'/?/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?
'/?對文件內(nèi)容進(jìn)行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?
'/?對文件內(nèi)容進(jìn)行DES加密,加密后覆蓋掉原來的文件 ?
'/?/summary?
'/?param?name="sourceFile"待加密的文件的絕對路徑/param?
Overloads?Public?Sub?EncryptFile(sourceFile?As?String) ?
EncryptFile(sourceFile,?sourceFile) ?
End?Sub?'EncryptFile ?
'/?summary?
'/?對文件內(nèi)容進(jìn)行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?
'/?對文件內(nèi)容進(jìn)行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")
"采用DES算法"這個(gè)說法不明確,首先是使用多少位的DES進(jìn)行加密,通常是128位或192位,其次是,要先把主密鑰轉(zhuǎn)化成散列,才能供DES進(jìn)行加密,轉(zhuǎn)化的方法是什么沒有明確,通常是md5,所以有的銀行卡說是128位md5 3DS就是指用md5轉(zhuǎn)換主密鑰散列,用DES進(jìn)行加密,但是DES本身是64位(包含校驗(yàn)碼),2DES是128位,3DES是192位,但是沒有2DES的叫法,所以128位、192位統(tǒng)稱3DES
要完整的md5+3DS實(shí)例,需要100分以上,要不到我的空間中查找相關(guān)的文章
1、由于采用二進(jìn)制讀取文件的方式,因此加密時(shí)一般可以不考慮文件類型。
2、這里只進(jìn)行一次異或運(yùn)算,如有需要可以進(jìn)行多次異或運(yùn)算。
3、此加密算法速度快,當(dāng)然加密強(qiáng)度也低 ;
參考代碼如下:
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
'-----------------------------------------------------------------------
'函數(shù)說明: 使用異或運(yùn)算加密文件(可加密大部分文件)
'參數(shù)說明: 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
'打開文件并保存在二進(jìn)制數(shù)組中
inputFileNo = FreeFile
Open fileName For Binary As #inputFileNo
length = LOF(inputFileNo)
If length = 0 Then
MsgBox "退出加密:文件內(nèi)容為空!", vbInformation, "提示"
Exit Function
End If
ReDim fileBytes(length - 1) As Byte
Get inputFileNo, , fileBytes()
Close #inputFileNo
'將該二進(jìn)制數(shù)組進(jìn)行異或加密
Dim i As Long
For i = LBound(fileBytes) To UBound(fileBytes)
fileBytes(i) = fileBytes(i) Xor key
Next
'將異或加密后的二進(jìn)制數(shù)組保存在新的文件中
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 "加密過程中出錯(cuò):" Err.Description, vbCritical, "錯(cuò)誤"
XOR_Encrypt = False
Resume Next
End If
End Function