当前位置: 代码迷 >> C语言 >> 求助,高手请进
  详细解决方案

求助,高手请进

热度:187   发布时间:2005-12-30 17:54:00.0
求助,高手请进
谁能帮我把这个vb程序用c++类进行封装吗,谢了 qq 105805019
Option Strict On
Option Explicit On

Imports System.Security.Cryptography

Public Class MD5
Public Shared Function MD5Hash(ByVal str As String) As String

Dim len As Integer = util.StrLen(str)
Dim buf(len - 1), buf2() As Byte
Dim i, c As Integer

util.S2B(str, buf, str.Length())

Dim Crypto As New MD5CryptoServiceProvider()
buf2 = Crypto.ComputeHash(buf)

MD5Hash = ""
For i = 0 To buf2.Length - 1

c = CType((buf2(i) And &HF0) / 16, Integer)
If c 〈 10 Then
c += 48
Else
c += 87
End If
MD5Hash += Chr(c)

c = buf2(i) And &HF
If c 〈 10 Then
c += 48
Else
c += 87
End If
MD5Hash += Chr(c)

Next

End Function

End Class


Public Shared Sub S2B(ByVal str As String, ByRef buf As Byte(), ByVal len As Integer)

Dim i, p, ch As Integer

p = 0
For i = 0 To len - 1
ch = Asc(str.Chars(i))
If ch 〉 126 Or ch 〈 0 Then
buf(p) = CType((ch And &HFF00) / 256, Byte)
p += 1
buf(p) = CType(ch And &HFF, Byte)
Else
buf(p) = CType(ch, Byte)
End If
p += 1
Next
End Sub


----------------解决方案--------------------------------------------------------
  相关解决方案