Created
February 6, 2024 12:22
-
-
Save vgashic/85e5bcdaae225d60bb58d87cb0b23423 to your computer and use it in GitHub Desktop.
Authorization data for JBKJS service
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
using System; | |
using System.Linq; | |
using System.Security.Cryptography; | |
using System.Text; | |
public class Program | |
{ | |
public static void Main() | |
{ | |
var usergroup = "guests"; | |
var username = "guest"; | |
var password = "guest"; | |
var authorizationHeader = "Basic " + $"{usergroup}-{username}".ToBase64String(); | |
SHA512 sha512 = new SHA512Managed(); | |
var apiKeyHash = sha512.ComputeHash(Encoding.UTF8.GetBytes(password)); | |
var apiKey = BitConverter | |
.ToString(apiKeyHash) | |
.Replace("-", "") | |
.ToLower() | |
.ToBase64String(); | |
Console.WriteLine(authorizationHeader); | |
Console.WriteLine(apiKey); | |
} | |
} | |
public static class Extensions | |
{ | |
public static string ToBase64String(this string value) => Convert.ToBase64String(value.ToByteArray()); | |
public static byte[] ToByteArray(this string str) | |
{ | |
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding(); | |
return encoding.GetBytes(str); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment