将VB.NET代码转换为PHP

时间:2014-10-13 04:00:09

标签: php vb.net md5

我在VB.Net中有代码到MD5字符串,但我想将它转换为具有相同值返回值的php
VB.Net代码:

Public Shared Function ConverFileName(ByVal FileName As String) As String
        Dim str2 As String = ""
        Dim provider As New MD5CryptoServiceProvider
        Try 
            Dim buffer As Byte() = provider.ComputeHash(Encoding.Default.GetBytes(FileName))
            Dim num2 As Integer = (buffer.Length - 1)
            Dim i As Integer = 0
            Do While (i <= num2)
                str2 = (str2 & StringType.FromByte(buffer(i)))
                i += 1
            Loop
        Catch exception1 As Exception
            ProjectData.SetProjectError(exception1)
            Dim exception As Exception = exception1
            ProjectData.ClearProjectError
        End Try
        Return str2
    End Function

2 个答案:

答案 0 :(得分:0)

已经有一个内置函数来计算PHP中MD5 Hash文件。

md5_file($filename)

示例#1 md5_file()

的使用示例
<?php
$file = 'php-5.3.0alpha2-Win32-VC9-x64.zip';

echo 'MD5 file hash of ' . $file . ': ' . md5_file($file);
?>

或者如果您需要找到MD5 Has for a string

http://php.net/manual/en/function.md5.php

<?php
$str = 'apple';

echo 'MD5 hash of ' . $str. ': ' . md5($str);
?>

答案 1 :(得分:0)

您能帮忙从vb net更改为php

Function Enkrip(pwd As String) As String
    Dim s As String
    s = ""
    For i = 1 To Len(pwd)
        s = s + Chr(Asc(Mid(pwd, i, 1)) + 32)
    Next i
    Enkrip = s
End Function