加密过程:字符串转换为字节加密,再转换为字符串,
解密过程:字符串到字节,解密,再转换为字符串。当然是这个过程。
上源代码,用异或加解密(107个a加密后解密正常,108个a解密就异常了。)
Public Function EnCryptStr(ByVal s As String) As String ’加密过程
Dim Bt() As Byte = Encoding.Unicode.GetBytes(s)
Dim i, j As Int32
Dim EnBt(Bt.Length - 1) As Byte '8位1111 1111=十进制数255
For i = 0 To Bt.Length - 1
j = i + 1
EnBt(i) = Bt(i) Xor (j Mod 255)
Next
Return Encoding.Unicode.GetString(EnBt)
End Function
Public Function DeCryptStr(ByVal s As String) As String ‘解密过程
Dim Bt() As Byte = Encoding.Unicode.GetBytes(s)
Dim i, j As Int32
Dim DeBt(Bt.Length - 1) As Byte
For i = 0 To Bt.Length - 1
j = i + 1
DeBt(i) = Bt(i) Xor (j Mod 255)
Next
Return Encoding.Unicode.GetString(DeBt)
End Function
Dim EnBt() As Byte = {182, 216}
Debug.Print(BitConverter.ToString(EnBt))
Dim s = Encoding.Unicode.GetString(EnBt)
Dim Bt() As Byte = Encoding.Unicode.GetBytes(s)
Debug.Print(BitConverter.ToString(Bt))
B6-D8
FD-FF
#9
换换编码格式即可
用Encoding.UTF8.GetBytes
#10
想了想用Encoding.UTF8.GetBytes也不是办法,
应该
Public Function EnCryptStr(ByVal s As String) As Byte() '加密过程
Dim Bt() As Byte = UTF8Encoding.UTF8.GetBytes(s)
Dim i, j As Int32
Dim EnBt(Bt.Length - 1) As Byte '8位1111 1111=十进制数255
For i = 0 To Bt.Length - 1
j = i + 1
EnBt(i) = Bt(i) Xor (j Mod 255)
Next
Return (EnBt)
End Function
Public Function DeCryptStr(ByVal Bt() As Byte) As String '解密过程
Dim i, j As Int32
Dim DeBt(Bt.Length - 1) As Byte
For i = 0 To Bt.Length - 1
j = i + 1
DeBt(i) = Bt(i) Xor (j Mod 255)
Next
Return UTF8Encoding.UTF8.GetString(DeBt)
End Function
加密过程:字符串转换为字节加密,再转换为字符串,
解密过程:字符串到字节,解密,再转换为字符串。当然是这个过程。
上源代码,用异或加解密(107个a加密后解密正常,108个a解密就异常了。)
Public Function EnCryptStr(ByVal s As String) As String ’加密过程
Dim Bt() As Byte = Encoding.Unicode.GetBytes(s)
Dim i, j As Int32
Dim EnBt(Bt.Length - 1) As Byte '8位1111 1111=十进制数255
For i = 0 To Bt.Length - 1
j = i + 1
EnBt(i) = Bt(i) Xor (j Mod 255)
Next
Return Encoding.Unicode.GetString(EnBt)
End Function
Public Function DeCryptStr(ByVal s As String) As String ‘解密过程
Dim Bt() As Byte = Encoding.Unicode.GetBytes(s)
Dim i, j As Int32
Dim DeBt(Bt.Length - 1) As Byte
For i = 0 To Bt.Length - 1
j = i + 1
DeBt(i) = Bt(i) Xor (j Mod 255)
Next
Return Encoding.Unicode.GetString(DeBt)
End Function
Dim EnBt() As Byte = {182, 216}
Debug.Print(BitConverter.ToString(EnBt))
Dim s = Encoding.Unicode.GetString(EnBt)
Dim Bt() As Byte = Encoding.Unicode.GetBytes(s)
Debug.Print(BitConverter.ToString(Bt))
B6-D8
FD-FF
#9
换换编码格式即可
用Encoding.UTF8.GetBytes
#10
想了想用Encoding.UTF8.GetBytes也不是办法,
应该
Public Function EnCryptStr(ByVal s As String) As Byte() '加密过程
Dim Bt() As Byte = UTF8Encoding.UTF8.GetBytes(s)
Dim i, j As Int32
Dim EnBt(Bt.Length - 1) As Byte '8位1111 1111=十进制数255
For i = 0 To Bt.Length - 1
j = i + 1
EnBt(i) = Bt(i) Xor (j Mod 255)
Next
Return (EnBt)
End Function
Public Function DeCryptStr(ByVal Bt() As Byte) As String '解密过程
Dim i, j As Int32
Dim DeBt(Bt.Length - 1) As Byte
For i = 0 To Bt.Length - 1
j = i + 1
DeBt(i) = Bt(i) Xor (j Mod 255)
Next
Return UTF8Encoding.UTF8.GetString(DeBt)
End Function