KeyAuth API Initialization Guide
KeyAuth API Initialization Guide
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link].X509Certificates;
using [Link];
using [Link];
using Cryptographic;
using [Link];
namespace KeyAuth
{
public class api
{
[DllImport("[Link]", SetLastError = true)]
private static extern bool TerminateProcess(IntPtr hProcess, uint
uExitCode);
[Link] = name;
[Link] = ownerid;
[Link] = version;
[Link] = path;
}
#region structures
[DataContract]
private class response_structure
{
[DataMember]
public bool success { get; set; }
[DataMember]
public bool newSession { get; set; }
[DataMember]
public string sessionid { get; set; }
[DataMember]
public string contents { get; set; }
[DataMember]
public string response { get; set; }
[DataMember]
public string message { get; set; }
[DataMember]
public string ownerid { get; set; }
[DataMember]
public string download { get; set; }
[DataMember]
public List<msg> messages { get; set; }
[DataMember]
public List<users> users { get; set; }
[DataContract]
private class user_data_structure
{
[DataMember]
public string username { get; set; }
[DataMember]
public string ip { get; set; }
[DataMember]
public string hwid { get; set; }
[DataMember]
public string createdate { get; set; }
[DataMember]
public string lastlogin { get; set; }
[DataMember]
public List<Data> subscriptions { get; set; } // array of subscriptions
(basically multiple user ranks for user with individual expiry dates
}
[DataContract]
private class app_data_structure
{
[DataMember]
public string numUsers { get; set; }
[DataMember]
public string numOnlineUsers { get; set; }
[DataMember]
public string numKeys { get; set; }
[DataMember]
public string version { get; set; }
[DataMember]
public string customerPanelLink { get; set; }
[DataMember]
public string downloadLink { get; set; }
}
#endregion
private static string sessionid, enckey;
bool initialized;
/// <summary>
/// Initializes the connection with keyauth in order to use any of the
functions
/// </summary>
public void init()
{
Random random = new Random();
// Generate a random length for the string (let's assume between 5 and
50 characters)
int length = [Link](5, 51); // Min length: 5, Max length: 50
seed = [Link]();
checkAtom();
if ()
{
values_to_upload.Add("token", [Link](path));
values_to_upload.Add("thash", TokenHash(path));
}
if (response == "KeyAuth_Invalid")
{
error("Application not found");
TerminateProcess(GetCurrentProcess(), 1);
}
var json =
response_decoder.string_to_generic<response_structure>(response);
if ([Link] == ownerid)
{
load_response_struct(json);
if ([Link])
{
sessionid = [Link];
initialized = true;
}
else if ([Link] == "invalidver")
{
app_data.downloadLink = [Link];
}
}
else
{
TerminateProcess(GetCurrentProcess(), 1);
}
}
void checkAtom()
{
Thread atomCheckThread = new Thread(() =>
{
while (true)
{
[Link](60000); // give people 1 minute to login
/// <summary>
/// Converts Unix time to Days,Months,Hours
///</summary>
/// <param name="subscription">Subscription Number</param>
/// <param name="Type">You can choose between Days,Hours,Months </param>
public string expirydaysleft(string Type,int subscription)
{
CheckInit();
/// <summary>
/// Registers the user using a license and gives the user a subscription
that matches their license level
/// </summary>
/// <param name="username">Username</param>
/// <param name="pass">Password</param>
/// <param name="key">License key</param>
public void register(string username, string pass, string key, string email
= "")
{
CheckInit();
var json =
response_decoder.string_to_generic<response_structure>(response);
if ([Link] == ownerid)
{
GlobalAddAtom(seed);
GlobalAddAtom(ownerid);
load_response_struct(json);
if ([Link])
load_user_data([Link]);
}
else
{
TerminateProcess(GetCurrentProcess(), 1);
}
}
/// <summary>
/// Allow users to enter their account information and recieve an email to
reset their password.
/// </summary>
/// <param name="username">Username</param>
/// <param name="email">Email address</param>
public void forgot(string username, string email)
{
CheckInit();
var json =
response_decoder.string_to_generic<response_structure>(response);
load_response_struct(json);
}
/// <summary>
/// Authenticates the user using their username and password
/// </summary>
/// <param name="username">Username</param>
/// <param name="pass">Password</param>
public void login(string username, string pass, string code = null)
{
CheckInit();
var json =
response_decoder.string_to_generic<response_structure>(response);
if ([Link] == ownerid)
{
GlobalAddAtom(seed);
GlobalAddAtom(ownerid);
load_response_struct(json);
if ([Link])
load_user_data([Link]);
}
else
{
TerminateProcess(GetCurrentProcess(), 1);
}
}
var json =
response_decoder.string_to_generic<response_structure>(response);
if ([Link] == ownerid)
{
load_response_struct(json);
}
else
{
TerminateProcess(GetCurrentProcess(), 1);
}
}
start:
outputten = "handshake";
outputten = "[Link] + outputten + "/";
[Link](outputten);
[Link]();
if ([Link] == "OPTIONS")
{
[Link] = (int)[Link];
[Link](1); // without this, the response doesn't return to
the website, and the web buttons can't be shown
[Link]();
goto start;
}
[Link] = [Link];
[Link] = true;
[Link] = true;
datastore = datastore2;
var json =
response_decoder.string_to_generic<response_structure>(response);
bool success = true;
if ([Link] == ownerid)
{
GlobalAddAtom(seed);
GlobalAddAtom(ownerid);
load_response_struct(json);
if ([Link])
{
load_user_data([Link]);
[Link] = 420;
[Link] = "SHEESH";
}
else
{
[Link]([Link]);
[Link] = (int)[Link];
[Link] = [Link];
success = false;
}
}
else
{
TerminateProcess(GetCurrentProcess(), 1);
}
responsepp.ContentLength64 = [Link];
Stream output = [Link];
[Link](buffer, 0, [Link]);
[Link](1); // without this, the response doesn't return to the
website, and the web buttons can't be shown
[Link]();
if (!success)
TerminateProcess(GetCurrentProcess(), 1);
/// <summary>
/// Use Buttons from KeyAuth Customer Panel
/// </summary>
/// <param name="button">Button Name</param>
string output;
output = button;
output = "[Link] + output + "/";
[Link](output);
[Link]();
[Link] = 420;
[Link] = "SHEESH";
[Link] = [Link];
[Link] = true;
[Link] = true;
[Link]();
}
/// <summary>
/// Gives the user a subscription that has the same level as the key
/// </summary>
/// <param name="username">Username of the user thats going to get
upgraded</param>
/// <param name="key">License with the same level as the subscription you
want to give the user</param>
public void upgrade(string username, string key)
{
CheckInit();
var json =
response_decoder.string_to_generic<response_structure>(response);
if ([Link] == ownerid)
{
[Link] = false;
load_response_struct(json);
}
else
{
TerminateProcess(GetCurrentProcess(), 1);
}
}
/// <summary>
/// Authenticate without using usernames and passwords
/// </summary>
/// <param name="key">Licence used to login with</param>
public void license(string key, string code = null)
{
CheckInit();
var json =
response_decoder.string_to_generic<response_structure>(response);
if ([Link] == ownerid)
{
GlobalAddAtom(seed);
GlobalAddAtom(ownerid);
load_response_struct(json);
if ([Link])
load_user_data([Link]);
}
else
{
TerminateProcess(GetCurrentProcess(), 1);
}
}
/// <summary>
/// Checks if the current session is validated or not
/// </summary>
public void check()
{
CheckInit();
var json =
response_decoder.string_to_generic<response_structure>(response);
if ([Link] == ownerid)
{
load_response_struct(json);
}
else
{
TerminateProcess(GetCurrentProcess(), 1);
}
}
/// <summary>
/// Disable two factor authentication (2fa)
/// </summary>
public void disable2fa(string code)
{
CheckInit();
var json =
response_decoder.string_to_generic<response_structure>(response);
load_response_struct(json);
[Link]([Link]);
}
/// <summary>
/// Enable two factor authentication (2fa)
/// </summary>
public void enable2fa(string code = null)
{
CheckInit();
var json =
response_decoder.string_to_generic<response_structure>(response);
load_response_struct(json);
if ([Link])
{
if (code == null)
{
[Link]($"Your 2FA Secret is:
{[Link]}");
var json =
response_decoder.string_to_generic<response_structure>(response);
if ([Link] == ownerid)
{
load_response_struct(json);
}
else
{
TerminateProcess(GetCurrentProcess(), 1);
}
}
/// <summary>
/// Gets the an existing user variable
/// </summary>
/// <param name="var">User Variable Name</param>
/// <returns>The content of the user variable</returns>
public string getvar(string var)
{
CheckInit();
var json =
response_decoder.string_to_generic<response_structure>(response);
if ([Link] == ownerid)
{
load_response_struct(json);
if ([Link])
return [Link];
}
else
{
TerminateProcess(GetCurrentProcess(), 1);
}
return null;
}
/// <summary>
/// Bans the current logged in user
/// </summary>
public void ban(string reason = null)
{
CheckInit();
var json =
response_decoder.string_to_generic<response_structure>(response);
if ([Link] == ownerid)
{
load_response_struct(json);
}
else
{
TerminateProcess(GetCurrentProcess(), 1);
}
}
/// <summary>
/// Gets an existing global variable
/// </summary>
/// <param name="varid">Variable ID</param>
/// <returns>The content of the variable</returns>
public string var(string varid)
{
CheckInit();
var json =
response_decoder.string_to_generic<response_structure>(response);
load_response_struct(json);
if ([Link])
return [Link];
return null;
}
/// <summary>
/// Fetch app statistic counts
/// </summary>
public void fetchStats()
{
CheckInit();
var json =
response_decoder.string_to_generic<response_structure>(response);
load_response_struct(json);
if ([Link])
load_app_data([Link]);
}
/// <summary>
/// Gets the last 50 sent messages of that channel
/// </summary>
/// <param name="channelname">The channel name</param>
/// <returns>the last 50 sent messages of that channel</returns>
public List<msg> chatget(string channelname)
{
CheckInit();
var json =
response_decoder.string_to_generic<response_structure>(response);
load_response_struct(json);
if ([Link])
{
return [Link];
}
return null;
}
/// <summary>
/// Sends a message to the given channel name
/// </summary>
/// <param name="msg">Message</param>
/// <param name="channelname">Channel Name</param>
/// <returns>If the message was sent successfully, it returns true if not
false</returns>
public bool chatsend(string msg, string channelname)
{
CheckInit();
var json =
response_decoder.string_to_generic<response_structure>(response);
load_response_struct(json);
if ([Link])
return true;
return false;
}
/// <summary>
/// Checks if the current ip address/hwid is blacklisted
/// </summary>
/// <returns>If found blacklisted returns true if not false</returns>
public bool checkblack()
{
CheckInit();
string hwid = [Link]().[Link];
var json =
response_decoder.string_to_generic<response_structure>(response);
if ([Link] == ownerid)
{
load_response_struct(json);
if ([Link])
return true;
else
return false;
}
else
{
TerminateProcess(GetCurrentProcess(), 1);
}
return true; // return yes blacklisted if the OwnerID is spoofed
}
/// <summary>
/// Sends a request to a webhook that you've added in the dashboard in a
safe way without it being showed for example a http debugger
/// </summary>
/// <param name="webid">Webhook ID</param>
/// <param name="param">Parameters</param>
/// <param name="body">Body of the request, empty by default</param>
/// <param name="conttype">Content type, empty by default</param>
/// <returns>the webhook's response</returns>
public string webhook(string webid, string param, string body = "", string
conttype = "")
{
CheckInit();
var json =
response_decoder.string_to_generic<response_structure>(response);
if ([Link] == ownerid)
{
load_response_struct(json);
if ([Link])
return [Link];
}
else
{
TerminateProcess(GetCurrentProcess(), 1);
}
return null;
}
/// <summary>
/// KeyAuth acts as proxy and downlods the file in a secure way
/// </summary>
/// <param name="fileid">File ID</param>
/// <returns>The bytes of the download file</returns>
public byte[] download(string fileid)
{
CheckInit();
["type"] = "file",
["fileid"] = fileid,
["sessionid"] = sessionid,
["name"] = name,
["ownerid"] = ownerid
};
var json =
response_decoder.string_to_generic<response_structure>(response);
load_response_struct(json);
if ([Link])
return encryption.str_to_byte_arr([Link]);
return null;
}
/// <summary>
/// Logs the IP address,PC Name with a message, if a discord webhook is set
up in the app settings, the log will get sent there and the dashboard if not set up
it will only be in the dashboard
/// </summary>
/// <param name="message">Message</param>
public void log(string message)
{
CheckInit();
req(values_to_upload);
}
/// <summary>
/// Change the username of a user, *User must be logged in*
/// </summary>
/// <param username="username">New username.</param>
public void changeUsername(string username)
{
CheckInit();
var json =
response_decoder.string_to_generic<response_structure>(response);
load_response_struct(json);
}
if ()
{
[Link](folder);
}
if ()
{
using (FileStream stream = [Link](file))
{
[Link](file, [Link] + " > This is the start
of your error logs file");
}
}
[Link] +=
assertSSL;
var raw_response =
[Link]("[Link] post_data);
[Link] =
delegate { return true; };
sigCheck([Link](raw_response),
[Link], post_data.Get(0));
[Link]([Link](raw_response) + "\
n");
return [Link](raw_response);
}
}
catch (WebException webex)
{
var response = (HttpWebResponse)[Link];
switch ([Link])
{
case (HttpStatusCode)429: // client hit our rate limit
error("You're connecting too fast to loader, slow down.");
[Link]("You're connecting too fast to loader, slow
down.");
TerminateProcess(GetCurrentProcess(), 1);
return "";
default: // site won't resolve. you should use [Link]
domain since it's not blocked by any ISPs
error("Connection failure. Please try again, or contact us
for help.");
[Link]("Connection failure. Please try again, or
contact us for help.");
TerminateProcess(GetCurrentProcess(), 1);
return "";
}
}
}
try
{
string signature = headers["x-signature-ed25519"];
string timestamp = headers["x-signature-timestamp"];
#region app_data
public app_data_class app_data = new app_data_class();
#region user_data
public user_data_class user_data = new user_data_class();
[DataContract]
private class TwoFactorData
{
[DataMember(Name = "secret_code")]
public string SecretCode { get; set; }
[DataMember(Name = "QRCode")]
public string QRCode { get; set; }
}
#region response_struct
public response_class response = new response_class();
string exeName =
[Link]([Link]().Loca
tion);
string logDirectory =
[Link]([Link]([Link]
ata), "KeyAuth", "debug", exeName);
if ()
{
[Link](logDirectory);
}
try
{
// Redact sensitive fields - Add more if you would like.
content = RedactField(content, "sessionid");
content = RedactField(content, "ownerid");
content = RedactField(content, "app");
content = RedactField(content, "version");
content = RedactField(content, "fileid");
content = RedactField(content, "webhooks");
content = RedactField(content, "nonce");
if (!is_serializable(object_type))
throw new Exception($"the object {current_object} isn't a
serializable");
}