你记住那些需要加密,哪些不需要加密噻,读取存储的时候需要加密的字段就加密解密一下,其他正常存储读取就成了。给你一个加密解密算法:' 加密过程,password:密钥,from_text:源字段,to_text:加密后字段 Private Sub Cipher(ByVal password As String, ByVal from_text As String, to_text As String) Const MIN_ASC = 32 ' Space. Const MAX_ASC = 126 ' ~. Const NUM_ASC = MAX_ASC - MIN_ASC + 1Dim offset As Long Dim str_len As Integer Dim i As Integer Dim ch As Integer to_text = "" ' Initialize the random number generator. offset = NumericPassword(password) Rnd -1 Randomize offset ' Encipher the string. str_len = Len(from_text) For i = 1 To str_len ch = Asc(Mid$(from_text, i, 1)) If ch >= MIN_ASC And ch <= MAX_ASC Then ch = ch - MIN_ASC offset = Int((NUM_ASC + 1) * Rnd) ch = ((ch + offset) Mod NUM_ASC) ch = ch + MIN_ASC to_text = to_text & Chr$(ch) End If Next i End Sub '同上,解密,from_text是加密后的文本 Private Sub Decipher(ByVal password As String, ByVal from_text As String, to_text As String) Const MIN_ASC = 32 ' Space. Const MAX_ASC = 126 ' ~. Const NUM_ASC = MAX_ASC - MIN_ASC + 1Dim offset As Long Dim str_len As Integer Dim i As Integer Dim ch As Integer to_text = "" ' Initialize the random number generator. offset = NumericPassword(password) Rnd -1 Randomize offset ' Encipher the string. str_len = Len(from_text) For i = 1 To str_len ch = Asc(Mid$(from_text, i, 1)) If ch >= MIN_ASC And ch <= MAX_ASC Then ch = ch - MIN_ASC offset = Int((NUM_ASC + 1) * Rnd) ch = ((ch - offset) Mod NUM_ASC) If ch < 0 Then ch = ch + NUM_ASC ch = ch + MIN_ASC to_text = to_text & Chr$(ch) End If Next i End Sub ' Translate a password into an offset value. Private Function NumericPassword(ByVal password As String) As Long Dim value As Long Dim ch As Long Dim shift1 As Long Dim shift2 As Long Dim i As Integer Dim str_len As Integer str_len = Len(password) For i = 1 To str_len ' Add the next letter. ch = Asc(Mid$(password, i, 1)) value = value Xor (ch * 2 ^ shift1) value = value Xor (ch * 2 ^ shift2) ' Change the shift offsets. shift1 = (shift1 + 7) Mod 19 shift2 = (shift2 + 13) Mod 23 Next i NumericPassword = value End Function
Private Sub Cipher(ByVal password As String, ByVal from_text As String, to_text As String)
Const MIN_ASC = 32 ' Space.
Const MAX_ASC = 126 ' ~.
Const NUM_ASC = MAX_ASC - MIN_ASC + 1Dim offset As Long
Dim str_len As Integer
Dim i As Integer
Dim ch As Integer
to_text = ""
' Initialize the random number generator.
offset = NumericPassword(password)
Rnd -1
Randomize offset ' Encipher the string.
str_len = Len(from_text)
For i = 1 To str_len
ch = Asc(Mid$(from_text, i, 1))
If ch >= MIN_ASC And ch <= MAX_ASC Then
ch = ch - MIN_ASC
offset = Int((NUM_ASC + 1) * Rnd)
ch = ((ch + offset) Mod NUM_ASC)
ch = ch + MIN_ASC
to_text = to_text & Chr$(ch)
End If
Next i
End Sub
'同上,解密,from_text是加密后的文本
Private Sub Decipher(ByVal password As String, ByVal from_text As String, to_text As String)
Const MIN_ASC = 32 ' Space.
Const MAX_ASC = 126 ' ~.
Const NUM_ASC = MAX_ASC - MIN_ASC + 1Dim offset As Long
Dim str_len As Integer
Dim i As Integer
Dim ch As Integer
to_text = ""
' Initialize the random number generator.
offset = NumericPassword(password)
Rnd -1
Randomize offset ' Encipher the string.
str_len = Len(from_text)
For i = 1 To str_len
ch = Asc(Mid$(from_text, i, 1))
If ch >= MIN_ASC And ch <= MAX_ASC Then
ch = ch - MIN_ASC
offset = Int((NUM_ASC + 1) * Rnd)
ch = ((ch - offset) Mod NUM_ASC)
If ch < 0 Then ch = ch + NUM_ASC
ch = ch + MIN_ASC
to_text = to_text & Chr$(ch)
End If
Next i
End Sub
' Translate a password into an offset value.
Private Function NumericPassword(ByVal password As String) As Long
Dim value As Long
Dim ch As Long
Dim shift1 As Long
Dim shift2 As Long
Dim i As Integer
Dim str_len As Integer str_len = Len(password)
For i = 1 To str_len
' Add the next letter.
ch = Asc(Mid$(password, i, 1))
value = value Xor (ch * 2 ^ shift1)
value = value Xor (ch * 2 ^ shift2) ' Change the shift offsets.
shift1 = (shift1 + 7) Mod 19
shift2 = (shift2 + 13) Mod 23
Next i
NumericPassword = value
End Function