ini存储SQL账户密码 加密算法
小弟现在有一数据库账户密码,存放在ini文件中连接数据库时读取ini里账号密码
为了防止其它人知道密码访问数据库,所以想给ini 密码转换下
思路是,ini密码存的是乱码,或者加密后的文字
读取数据库时读密码 然后转换成正确的 连接成功
汗!!说的好而且还不知道思路对不对,可实在是一种算法也不会啊,也不知道如何写这段代码
大哥们 可否帮帮我,写一段代码。
我知道这又很多种,哪怕给种最简单的也好啊,谢谢大伙了 。 --------------------编程问答-------------------- 谢谢大伙了 。 --------------------编程问答-------------------- 网上找一下加密解密的例子,有很多,如AES、DES等 --------------------编程问答-------------------- base64 的算法网上很多
--------------------编程问答-------------------- --------------------编程问答-------------------- 在需要的时候,还是需要解密啊...一解密,问题就来了,还照样可以动态调试到,可以被破解的.
我也在搞这个问题...烦死了
暂时在数据库中使用了安全模型
数据库的密码是软件启动的时候,由服务端(Winsock)发送给客户端的,
即使数据库密码修改了,也不用去通知各个客户端去修改ini文件,这样灵活性大点.... --------------------编程问答-------------------- 1,base64
2,RSA(64位)
3,还有一种常见的简单的方法:是程序里写死一个密钥串,然后用它按位异或要加密字串得到暗文,将暗文与密钥串再按位异或就得到明文。
--------------------编程问答-------------------- ' Base 64
'
' RFC 1341MIME: Multipurpose Internet Mail ExtensionsJune 1992
'
' Table 1: The Base64 Alphabet
'
' Value Encoding Value Encoding Value Encoding Value
' encoding
' 0 A 17 R 34 i 51 z
' 1 B 18 S 35 j 52 0
' 2 C 19 T 36 k 53 1
' 3 D 20 U 37 l 54 2
' 4 E 21 V 38 m 55 3
' 5 F 22 W 39 n 56 4
' 6 G 23 X 40 o 57 5
' 7 H 24 Y 41 p 58 6
' 8 I 25 Z 42 q 59 7
' 9 J 26 a 43 r 60 8
' 10 K 27 b 44 s 61 9
' 11 L 28 c 45 t 62 +
' 12 M 29 d 46 u 63 /
' 13 N 30 e 47 v
' 14 O 31 f 48 w (pad) =
' 15 P 32 g 49 x
' 16 Q 33 h 50 y
'
Private Const BASE64_STR As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
' +------------------------------------------------------------------------+
' | 十进制转化为二进制,参数类型为长整形。返回一个表示二进制的字符串。|
' +------------------------------------------------------------------------+
Public Function DecToBin(DecNum As Long) As String
Dim I As Long
Dim BinStr As String '用于暂存表示二进制的字符串
While (DecNum > 0)
I = DecNum Mod 2
DecNum = DecNum \ 2
BinStr = CStr(I) & BinStr
Wend
DecToBin = Right("00000000" & BinStr, 8)
End Function
' +------------------------------------------------------------------------+
' | 二进制转化为十进制,参数类型为表示二进制的字符串。返回一个长整形。|
' +------------------------------------------------------------------------+
Public Function BinToDec(BinStr As String) As Long
Dim I As Long
Dim DecSum As Long
BinStr = Right("00000000" & BinStr, 8)
For I = 1 To 7
DecSum = (DecSum + CLng(Mid(BinStr, I, 1))) * 2
Next
DecSum = DecSum + CLng(Mid(BinStr, 8, 1))
BinToDec = DecSum
End Function
Public Function DecToHex(DecNum As Long) As String
End Function
Public Function HexToDec(HexStr As String) As Long
End Function
Public Function Base64Chr(DecNum As Long) As String
Base64Chr = Mid(BASE64_STR, DecNum + 1, 1)
End Function
'+------------------------------------------------------------------------------+
'| 原文的字节最后不够3个的地方用0来补足,转换时Base64编码用=号来代替。 |
'| |
'+------------------------------------------------------------------------------+
Public Function Base64Extent(Textstr As String) As String
Dim I As Long, J As Long, N As Long, TempStr As String
Dim BinStr As String
For I = 1 To Len(Textstr)
BinStr = BinStr & DecToBin(Asc(Mid(Textstr, I, 1)))
Next
N = Len(Textstr) Mod 3 '原文的字节最后不够3个的地方用0来补足
BinStr = BinStr & Right("000000000000000000000000", N * 8)
If N = 0 Then
For I = 1 To Len(Textstr) * 8 '这里不处理结尾; Len(Textstr) * 8 + N - 6
TempStr = TempStr & Base64Chr(BinToDec(Mid(BinStr, I, 6)))
I = I + 5
Next
ElseIf N <> 0 Then '结尾处理
If (Len(Textstr) - N) * 8 > 0 Then
For I = 1 To (Len(Textstr) - N) * 8 '这里不处理结尾; Len(Textstr) * 8 + N - 6
TempStr = TempStr & Base64Chr(BinToDec(Mid(BinStr, I, 6)))
I = I + 5
Next
For J = I To Len(BinStr)
If BinToDec(Mid(BinStr, J, 6)) = 0 Then
TempStr = TempStr & "="
J = J + 5
Else
TempStr = TempStr & Base64Chr(BinToDec(Mid(BinStr, J, 6)))
J = J + 5
End If
Next
Else
For J = 1 To Len(BinStr)
If BinToDec(Mid(BinStr, J, 6)) = 0 Then
TempStr = TempStr & "="
J = J + 5
Else
TempStr = TempStr & Base64Chr(BinToDec(Mid(BinStr, J, 6)))
J = J + 5
End If
Next
End If
End If
Base64Extent = TempStr
End Function
'+------------------------------------------------------------------------------+
'| 先将Base64编码的字符串转化为0~64的十进制数,再翻译为正常的字符串。 |
'+------------------------------------------------------------------------------+
Public Function Base64Reduce(Base64str As String) As String
Dim I As Long, BinStr As String
Dim TmpStr As String
Dim N As Long
For I = 1 To Len(Base64str)
If Asc(Mid(Base64str, I, 1)) >= Asc("A") And Asc(Mid(Base64str, I, 1)) <= Asc("Z") Then
BinStr = BinStr & Right(DecToBin(Asc(Mid(Base64str, I, 1)) - Asc("A")), 6)
ElseIf Asc(Mid(Base64str, I, 1)) >= Asc("a") And Asc(Mid(Base64str, I, 1)) <= Asc("z") Then
BinStr = BinStr & Right(DecToBin(Asc(Mid(Base64str, I, 1)) - Asc("a") + 26), 6)
ElseIf Asc(Mid(Base64str, I, 1)) >= Asc("0") And Asc(Mid(Base64str, I, 1)) <= Asc("9") Then
BinStr = BinStr & Right(DecToBin(Asc(Mid(Base64str, I, 1)) - Asc("0") + 52), 6)
ElseIf Mid(Base64str, I, 1) = "+" Then
BinStr = BinStr & Right(DecToBin(62), 6)
ElseIf Mid(Base64str, I, 1) = "/" Then
BinStr = BinStr & Right(DecToBin(63), 6)
ElseIf Mid(Base64str, I, 1) = "=" Then
' BinStr = BinStr & "000000"
End If
Next
If Right(Base64str, 1) <> "=" Then
For I = 1 To Len(BinStr)
TmpStr = TmpStr & Chr(BinToDec(Mid(BinStr, I, 8)))
I = I + 7
Next
Else
N = Len(BinStr) \ 8
BinStr = Left(BinStr & "0000", (N + 1) * 8)
For I = 1 To Len(BinStr)
TmpStr = TmpStr & Chr(BinToDec(Mid(BinStr, I, 8)))
I = I + 7
Next
End If
Base64Reduce = TmpStr
End Function
补充:VB , 数据库(包含打印,安装,报表)