开发者

PHP and Visual Basic 2008 Conversion

I need help converting this into PHP:

Public Function Encrypt(ByVal text As String) As String
        Dim charSet1 As String, charSet2 As String, i As Long
        Dim pos As Long, encryptedChar, encryptedText
        charSet1 = " ?!@#$%^&*()_+|0123456789abcdefghijklmnopqrstuvwxyz.,-~ABCDEFGHIJKLMNOPQRSTUVWXYZ¿¡²³ÀÁÂÃÄÅÒÓÔÕÖÙÛÜàáâãäåض§Ú¥"
        charSet2 = " ¿¡@#$%^&*()_+|01²³456789ÀbÁdÂÃghÄjklmÅÒÓqÔÕÖÙvwÛÜz.,-~AàáâãFGHäJKåMNضQR§TÚVWX¥Z?!23acefinoprstuxyBCDEILOPSUY"
        For i = 1 To Len(text)
            pos = InStr(charSet1, Mid(text, i, 1))
            If pos > 0 Then
                encryptedChar = Mid(charSet2, pos, 1)
                encryptedText = encryptedText + encryptedChar
            Else
                encryptedText = encryptedText + Mid(text, i, 1)
            End If
        Next
        Encrypt = encryptedText
    End Function

FROM VISUAL BASIC TO PHP...

I'm making a text to hash thing like开发者_JS百科 presented above but in PHP for my website.. The code above is home-made so its nothing like MD5 or SHA1. But if you guys do know a way to encrypt and decrypt MD5 in Visual basic 2008 please show me! (this must also work for PHP).


Rather than convert the above subroutine to PHP, here is a subroutine to convert a string to its MD5 Hash in VB.NET:

Function getMD5Hash(ByVal strToHash As String) As String

    Dim md5Obj As New Security.Cryptography.MD5CryptoServiceProvider

    Dim bytesToHash() As Byte = System.Text.Encoding.ASCII.GetBytes(strToHash)

    bytesToHash = md5Obj.ComputeHash(bytesToHash)

    Dim strResult As String = ""

    For Each b As Byte In bytesToHash

        strResult += b.ToString("x2")

    Next

    Return strResult

End Function

in PHP you can use the md5 function:

$hashedString = md5(strToHash);

By it's nature as a hash, you cannot decrypt a hash, you can only hash it and compare it to a stored hash.

Of course, I have to link to the Coding Horror post on Rainbow Tables and salting your hashes:

Coding Horror: Rainbow Hash Cracking

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜