douzuo0002 2019-01-31 13:28
浏览 56

VB.NET编码字符串为drupal7兼容密码字段字符串

hopefully someone can help.

I have to update a user's details in a MySQL Drupal environment from a VB.NET application/ASP.

So the user changes their password using classic ASP, this calls a .COM compliant DLL Class written in VB.NET

The instructions I have found are: (located from this site)

Here is an example hash from Drupal 7:

"pass" : "$S$Dxl65W9p07LfQU7jvy5CnsyDpMoLujiAgzy123khcg1OJi/P9pKS"

The characters 0-2 are the type ( $S$ is Drupal 7 )

The character 3 is the number of log2 rounds (X) based on the position of the char in this list: './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' So in our example 'D' would map to 15 The characters 4-11 are the SALT The rest is a SHA512 hash using 2^X rounds. The binary result is then converted to a string using base64.

$count = 1 << $count_log2;
$hash = hash($algo, $salt . $password, TRUE);
do { $hash = hash($algo, $hash . $password, TRUE);
} while (--$count);

Not being a cryptographer of any sort or understanding PHP, I found a bit of code that could do the SHA512 encryption and tried decyphering the PHP to VB.NET - I think this is what the PHP code above is doing, to encrypt a string.

Private Function EncryptSHA512Managed(ByVal ClearString As String) As String
       Dim uEncode As New UnicodeEncoding()
       Dim bytClearString() As Byte = uEncode.GetBytes(ClearString)
       Dim sha As New System.Security.Cryptography.SHA512Managed()
       Dim hash() As Byte = sha.ComputeHash(bytClearString)
       Dim Z as Integer = 0

       For Z = 1 To HowManyTimes - 1
           hash2 = sha.ComputeHash(hash)
           hash = hash2
       Next

       Return Convert.ToBase64String(hash2)
   End Function

So from what I understand about the PHP explanation (and I have never used PHP) I would do something like this:

   Private Function EncryptionStringForDrupal() As String
         Dim EncStr As String = "apassword"

 ' Going to use TestSale as my salt test.

         Return "$S$DTestSalt" & EncryptSHA512Managed("TestSalt" & EncStr)

   End Function

With The "D" in the example PHP text, thats 15^2 and it comes out as 32,768 encryption loops and the resulting drupal encrypted password comes out as

$S$DTestSaltTjmIXDexvVOnQDA4ojamH2PFxVrfIKJLJBKNtclZaxs/LHiF8Wxx2kMb03qeo+FUK7prxEiKfToY50ZG0SQ3QA==

But its still wrong -.-

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 java如何提取出pdf里的文字?
    • ¥100 求三轴之间相互配合画圆以及直线的算法
    • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
    • ¥15 名为“Product”的列已属于此 DataTable
    • ¥15 安卓adb backup备份应用数据失败
    • ¥15 eclipse运行项目时遇到的问题
    • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
    • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
    • ¥15 自己瞎改改,结果现在又运行不了了
    • ¥15 链式存储应该如何解决