Dim strResult As String = BitConverter.ToString(bytResult)
strResult = strResult.Replace("-", "")
Return strResult
End Function
如果要计算文件的就把参数改成字节数组就可以了,然后获取文件GetBytes()传进去就可以了.
Private?Function?LShift(lValue,?iShiftBits)
If?iShiftBits?=?0?Then
LShift?=?lValue
Exit?Function
If?lValue?And?1?Then
Else
LShift?=?0
End?If
End?Function
Private?Function?RShift(lValue,?iShiftBits)
RShift?=?lValue
RShift?=?1
RShift?=?0
Private?Function?RotateLeft(lValue,?iShiftBits)
Private?Function?AddUnsigned(lX,?lY)
Dim?lResult
AddUnsigned?=?lResult
a?=?RotateLeft(a,?s)
a?=?AddUnsigned(a,?b)
End?Sub
Private?Function?ConvertToWordArray(sMessage)
Dim?lMessageLength
Dim?lNumberOfWords
Dim?lWordArray()
Dim?lBytePosition
Dim?lByteCount
Dim?lWordCount
lMessageLength?=?Len(sMessage)
lNumberOfWords?=?(((lMessageLength?+?((MODULUS_BITS?-?CONGRUENT_BITS)?\?BITS_TO_A_BYTE))?\?(MODULUS_BITS?\?BITS_TO_A_BYTE))?+?1)?*?(MODULUS_BITS?\?BITS_TO_A_WORD)
ReDim?lWordArray(lNumberOfWords?-?1)
lBytePosition?=?0
lByteCount?=?0
Do?Until?lByteCount?=?lMessageLength
lWordCount?=?lByteCount?\?BYTES_TO_A_WORD
lBytePosition?=?(lByteCount?Mod?BYTES_TO_A_WORD)?*?BITS_TO_A_BYTE
lWordArray(lWordCount)?=?lWordArray(lWordCount)?Or?LShift(Asc(Mid(sMessage,?lByteCount?+?1,?1)),?lBytePosition)
lByteCount?=?lByteCount?+?1
Loop
ConvertToWordArray?=?lWordArray
Private?Function?WordToHex(lValue)
Dim?lByte
Dim?lCount
lByte?=?RShift(lValue,?lCount?*?BITS_TO_A_BYTE)?And?m_lOnBits(BITS_TO_A_BYTE?-?1)
Next
m_lOnBits(0)?=?CLng(1)
Dim?x
Dim?k
Dim?AA
Dim?BB
Dim?CC
Dim?DD
Dim?a
Dim?b
Dim?c
Dim?d
x?=?ConvertToWordArray(sMessage)
AA?=?a
BB?=?b
CC?=?c
DD?=?d
a?=?AddUnsigned(a,?AA)
b?=?AddUnsigned(b,?BB)
c?=?AddUnsigned(c,?CC)
d?=?AddUnsigned(d,?DD)
'下面是测试代码
Sub?test()
下面是完整的类,可以设置任意密码
Imports?System.Security.Cryptography
Imports?System
Imports?System.Text
Imports?System.Web
'''?summary
'''?DES加密类
'''?/summary
'''?remarks/remarks
Public?Class?DESEncrypt
Public?Sub?DESEncrypt()
Public?Shared?Function?Encrypt(ByVal?Text?As?String)?As?String
Public?Shared?Function?Encrypt(ByVal?Text?As?String,?ByVal?sKey?As?String)?As?String
Dim?des?As?New?DESCryptoServiceProvider()
Dim?inputByteArray?As?Byte()
inputByteArray?=?Encoding.Default.GetBytes(Text)
Dim?ms?As?New?System.IO.MemoryStream()
Dim?cs?As?New?CryptoStream(ms,?des.CreateEncryptor(),?CryptoStreamMode.Write)
cs.Write(inputByteArray,?0,?inputByteArray.Length)
cs.FlushFinalBlock()
Dim?ret?As?New?StringBuilder()
Dim?b?As?Byte
For?Each?b?In?ms.ToArray()
Return?ret.ToString()
Public?Shared?Function?Decrypt(ByVal?Text?As?String)?As?String
Public?Shared?Function?Decrypt(ByVal?Text?As?String,?ByVal?sKey?As?String)?As?String
Dim?len?As?Integer
Dim?inputByteArray(len?-?1)?As?Byte
Dim?x,?i?As?Integer
For?x?=?0?To?len?-?1
inputByteArray(x)?=?CType(i,?Byte)
Dim?cs?As?New?CryptoStream(ms,?des.CreateDecryptor(),?CryptoStreamMode.Write)
Return?Encoding.Default.GetString(ms.ToArray())
End?Class
'以下是调用方法
Public?Class?Form1
Private?Sub?Button1_Click(ByVal?sender?As?System.Object,?ByVal?e?As?System.EventArgs)?Handles?Button1.Click?'加密
以上就是土嘎嘎小编大虾米为大家整理的相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!