加密,解密我刚刚做了一个东东放在昨天的帖子中
http://www.csdn.net/expert/topic/496/496920.shtm
二进制都可以,文本更是没问题了!
另外文本文件的读取,不要参照加密读取,那个是二进制读取

解决方案 »

  1.   

    Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
    Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
    Dim strFileName As String
    Dim i As Long
    Dim Databuff() As Byte
    Dim Addbuff() As Byte
    Dim Password() As Byte
    Dim Code As String
    Dim A As String
    Private Sub Command1_Click()
    Code = InputBox("请再输入一次:", "密码核定")
    If Text1.Text = Val(Code) Then
    Dim j As Integer
    Dim Password_len As Integer
    Password_len = Len(Text1.Text)
    ReDim Password(Password_len) As Byte
    For i = 0 To Password_len - 1
    Password(i) = Asc(Mid(Text1.Text, i + 1, 1))
    Next
    If strFileName = "" Then
    Exit Sub
    End If
    Open strFileName For Binary As #1
    ReDim Databuff(LOF(1))
    Get #1, , Databuff
    Close #1
    ReDim Addbuff(UBound(Databuff)) As Byte
    For i = 0 To UBound(Databuff)
    If j >= Password_len Then
       j = 0
    Else
       j = j + 1
    End If
    Addbuff(i) = Databuff(i) Xor Password(j)
    Next
    Open strFileName For Binary As #1
    Put #1, , Addbuff
    Close #1
    A = A + 1
    WritePrivateProfileString "加密", "密码" + A, strFileName + "_" + Code, App.Path + "\" + "code.CID"
    WritePrivateProfileString "加密", "记数", A, App.Path + "\" + "code.CID"
    Text1.Text = ""
    Else
    Text1.Text = MsgBox("密码错误!", 16, "错误")
    End If
    End SubPrivate Sub Command2_Click()
    End
    End SubPrivate Sub Dir1_Change()
    File1.Path = Dir1.Path
    strFileName = Dir1.Path
    If Right$(strFileName, 1) <> "\" Then
    strFileName = strFileName + "\" + File1.FileName
    Else
    strFileName = strFileName + File1.FileName
    End If
    End SubPrivate Sub Drive1_Change()
    Dir1.Path = Drive1.Drive
    End SubPrivate Sub File1_Click()
    strFileName = Dir1.Path
    If Right$(strFileName, 1) <> "\" Then
    strFileName = strFileName + "\" + File1.FileName
    Else
    strFileName = strFileName + File1.FileName
    End If
    Open strFileName For Binary As #1
    ReDim Databuff(LOF(1))
    Get #1, , Databuff
    Close #1
    End Sub
    Private Sub Form_Load()
    Dim Length As Long
    Dim S As String
    S = String(1024, 0)
    Length = GetPrivateProfileString("加密", "记数", "000", S, Len(S), App.Path + "\" + "code.CID")
    A = Val(Left(S, Length))
    End Sub
    加密/解密的,还不错.
    不过,无法对FLASH生成的EXE文件加密
      

  2.   

    Private Sub Command1_Click()
    Dim bytI As Byte
    Dim lngI As Long
    Dim intI As Integer
    Dim bytMid() As Byte
    Open "d:\test.txt" For Binary As #1   '要加密或解密的文件  这一句打开文件
    Open "d:\test1.txt" For Binary As #2  '要加密或解密后的文件lngI = LOF(1)
    ReDim bytMid(LOF(1) - 1)
    For intI = 0 To LOF(1) - 1
      Get #1, intI + 1, bytI
      bytMid(intI) = Not bytI
    Next
    Put #2, 1, bytMidClose #1
    Close #2
    MsgBox "加密成功"End Sub