Created
September 10, 2020 16:57
-
-
Save vrerabek/a30abd85c0f948d09ba948d774af941d to your computer and use it in GitHub Desktop.
PHP - Dayz player ID (44 characters long ID) from steam id
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This is how you get user id (bohemia id) like you see in .ADM files from steam id. | |
*/ | |
$steam_id = "{STEAM_ID}"; | |
$user_id = base64url_encode(hash('sha256', $steam_id, true)); | |
function base64url_encode($data) | |
{ | |
$b64 = base64_encode($data); | |
if ($b64 === false) { | |
return false; | |
} | |
$url = strtr($b64, '+/', '-_'); | |
return $url; | |
} |
Проблема была в том что hash нужно было считать не из байтов числа SteamID, а тупо из байтов строки которая представляет SteamID ...
Int64 SteamId = <UserSteamID>;
string sID = SteamId.ToString();
var chars = sID.ToCharArray();
byte[] bytes = new byte[chars.Length];
for (int i = 0; i < chars.Length; i++)
bytes[i] = (byte)chars[i];
var sha = new SHA256CryptoServiceProvider();
var binaryData = sha.ComputeHash(bytes);
long arrayLength = (long)((4.0d / 3.0d) * binaryData.Length);
if (arrayLength % 4 != 0)
{
arrayLength += 4 - arrayLength % 4;
}
char[] base64CharArray = new char[arrayLength];
System.Convert.ToBase64CharArray(binaryData,
0,
binaryData.Length,
base64CharArray,
0);
string DAYZID = string.Empty;
foreach (var c in base64CharArray)
DAYZID += c;
Console.WriteLine(SteamId);
Console.WriteLine(DAYZID);
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is there an implementation in C # ?. I'm dumb. I do not know PHP