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条回答

    报告相同问题?

    悬赏问题

    • ¥20 搭建pt1000三线制高精度测温电路
    • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况
    • ¥15 画两个图 python或R
    • ¥15 在线请求openmv与pixhawk 实现实时目标跟踪的具体通讯方法
    • ¥15 八路抢答器设计出现故障
    • ¥15 opencv 无法读取视频
    • ¥15 用matlab 实现通信仿真
    • ¥15 按键修改电子时钟,C51单片机
    • ¥60 Java中实现如何实现张量类,并用于图像处理(不运用其他科学计算库和图像处理库))
    • ¥20 5037端口被adb自己占了