将十六进制二进制转换为字符串python

时间:2019-07-15 20:12:56

标签: python sql-server encoding sitecore sha1

因此,我正在尝试反向工程以在此处找到正确的值。

我正在查看以下链接:http://sitecoreblog.blogspot.com/2012/05/reset-admin-passord.html

以及此链接:https://blogs.perficientdigital.com/2018/06/20/upgrading-the-password-hashing-algorithm-for-sitecore-9-installs/

UPDATE dbo.aspnet_Membership 
SET [Password]='qOvF8m8F2IcWMvfOBjJYHmfLABc=', [PasswordSalt]='OM5gu45RQuJ76itRvkSPFw==', 
[IsApproved] = '1', [IsLockedOut] = '0'

    while len(@Salt) < 16
    begin
    set @Salt = (@Salt + cast(cast(floor(rand() * 256) as tinyint) as binary(1)))
    end

这是Sitecore 7用于在SHA1中对密码进行编码和哈希处理的代码

-- Hash password
set @HashedPassword = HASHBYTES(@HashAlgorithm, @Salt + cast(@Password as varbinary(128)));

-- Convert hash and salt to BASE64
select @EncodedHash = cast(N'' as xml).value(
'xs:base64Binary(xs:hexBinary(sql:column("bin")))'
, 'varchar(max)'
) from (select @HashedPassword as [bin] ) T

select @EncodedSalt = cast(N'' as xml).value(
'xs:base64Binary(xs:hexBinary(sql:column("bin")))'
, 'VARCHAR(MAX)'
) from (select @Salt as [bin] ) T

因此,我有password = 'b'hashed_password = 'qOvF8m8F2IcWMvfOBjJYHmfLABc='password_salt = 'OM5gu45RQuJ76itRvkSPFw=='

整个原因是,我需要获取base64编码的salt以及base64编码的哈希密码才能迁移到另一个系统(Okta)。

如果我要用python反向工程,这段代码是什么样的?

import base64
import hashlib
import binascii

salt='OM5gu45RQuJ76itRvkSPFwi=='
password = 'b'

hashed_pw_salt = hashlib.sha1(hex_salt + password)
base64_hash = base64.b64encode(hashed_pw_salt.digest())
print base64_hash

我得到的哈希密码为“ VVNsI7GLzCRREOUcsha / + TbpGd8 =”。

使python代码与SQL代码匹配的最佳方法是什么?

0 个答案:

没有答案