forked from 5l1v3r1/KeyAuth-VB-Example-Chats
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKeyAuth.vb
More file actions
851 lines (703 loc) · 34.3 KB
/
KeyAuth.vb
File metadata and controls
851 lines (703 loc) · 34.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
Imports System
Imports System.Security.Cryptography
Imports System.Collections.Specialized
Imports System.Text
Imports System.IO
Imports System.Runtime.Serialization.Json
Imports System.Diagnostics
Imports System.Security.Principal
Imports System.Threading
Imports System.Collections.Generic
Imports System.Net
Imports System.Runtime.Serialization
Namespace KeyAuth
Public Class api
Public name, ownerid, secret, version As String
''' <summary>
''' Set up your application credentials in order to use keyauth
''' </summary>
''' <paramname="name">Application Name</param>
''' <paramname="ownerid">Your OwnerID, can be found in your account settings.</param>
''' <paramname="secret">Application Secret</param>
''' <paramname="version">Application Version, if version doesnt match it will open the download link you set up in your application settings and close the app, if empty the app will close</param>
Public Sub New(ByVal name As String, ByVal ownerid As String, ByVal secret As String, ByVal version As String)
If String.IsNullOrWhiteSpace(name) OrElse String.IsNullOrWhiteSpace(ownerid) OrElse String.IsNullOrWhiteSpace(secret) OrElse String.IsNullOrWhiteSpace(version) Then
[error]("Application not setup correctly. Please watch video link found in Program.cs")
Environment.Exit(0)
End If
Me.name = name
Me.ownerid = ownerid
Me.secret = secret
Me.version = version
End Sub
#Region "structures"
<DataContract>
Private Class response_structure
<DataMember>
Public Property success As Boolean
<DataMember>
Public Property sessionid As String
<DataMember>
Public Property contents As String
<DataMember>
Public Property response As String
<DataMember>
Public Property message As String
<DataMember>
Public Property download As String
<DataMember(IsRequired:=False, EmitDefaultValue:=False)>
Public Property info As user_data_structure
<DataMember(IsRequired:=False, EmitDefaultValue:=False)>
Public Property appinfo As app_data_structure
<DataMember>
Public Property messages As List(Of msg)
End Class
Public Class msg
Public Property message As String
Public Property author As String
Public Property timestamp As String
End Class
<DataContract>
Private Class user_data_structure
<DataMember>
Public Property username As String
<DataMember>
Public Property ip As String
<DataMember>
Public Property hwid As String
<DataMember>
Public Property createdate As String
<DataMember>
Public Property lastlogin As String
<DataMember>
Public Property subscriptions As List(Of Data) ' array of subscriptions (basically multiple user ranks for user with individual expiry dates
End Class
<DataContract>
Private Class app_data_structure
<DataMember>
Public Property numUsers As String
<DataMember>
Public Property numOnlineUsers As String
<DataMember>
Public Property numKeys As String
<DataMember>
Public Property version As String
<DataMember>
Public Property customerPanelLink As String
<DataMember>
Public Property downloadLink As String
End Class
#End Region
Private sessionid, enckey As String
Private initzalized As Boolean
''' <summary>
''' Initializes the connection with keyauth in order to use any of the functions
''' </summary>
Public Sub init()
enckey = sha256(iv_key())
Dim init_iv = sha256(iv_key())
Dim values_to_upload = New NameValueCollection From {
{"type", byte_arr_to_str(Encoding.Default.GetBytes("init"))},
{"ver", encrypt(version, secret, init_iv)},
{"hash", checksum(Process.GetCurrentProcess().MainModule.FileName)},
{"enckey", encrypt(enckey, secret, init_iv)},
{"name", byte_arr_to_str(Encoding.Default.GetBytes(name))},
{"ownerid", byte_arr_to_str(Encoding.Default.GetBytes(ownerid))},
{"init_iv", init_iv}
}
Dim response = req(values_to_upload)
If Equals(response, "KeyAuth_Invalid") Then
[error]("Application not found")
Environment.Exit(0)
End If
response = decrypt(response, secret, init_iv)
Dim json = response_decoder.string_to_generic(Of response_structure)(response)
load_response_struct(json)
If json.success Then
load_app_data(json.appinfo)
sessionid = json.sessionid
initzalized = True
ElseIf Equals(json.message, "invalidver") Then
app_data.downloadLink = json.download
End If
End Sub
#Region "Checkinit"
Public Shared ReadOnly Property IsDebugRelease As Boolean
Get
#If DEBUG Then
Return True
#Else
Return False
#End If
End Get
End Property
Public Shared Property SurroundingClass As Object
Public Sub Checkinit()
If Not initzalized Then
If IsDebugRelease Then
[error]("Not initialized Check if KeyAuthApp.init() does exist")
Else
[error]("Please initialize first")
End If
End If
End Sub
#End Region
''' <summary>
''' Registers the user using a license and gives the user a subscription that matches their license level
''' </summary>
''' <paramname="username">Username</param>
''' <paramname="pass">Password</param>
''' <paramname="key">License</param>
Public Sub register(ByVal username As String, ByVal pass As String, ByVal key As String)
Checkinit()
Dim hwid As String = WindowsIdentity.GetCurrent().User.Value
Dim init_iv = sha256(iv_key())
Dim values_to_upload = New NameValueCollection From {
{"type", byte_arr_to_str(Encoding.Default.GetBytes("register"))},
{"username", encrypt(username, enckey, init_iv)},
{"pass", encrypt(pass, enckey, init_iv)},
{"key", encrypt(key, enckey, init_iv)},
{"hwid", encrypt(hwid, enckey, init_iv)},
{"sessionid", byte_arr_to_str(Encoding.Default.GetBytes(sessionid))},
{"name", byte_arr_to_str(Encoding.Default.GetBytes(name))},
{"ownerid", byte_arr_to_str(Encoding.Default.GetBytes(ownerid))},
{"init_iv", init_iv}
}
Dim response = req(values_to_upload)
response = decrypt(response, enckey, init_iv)
Dim json = response_decoder.string_to_generic(Of response_structure)(response)
load_response_struct(json)
If json.success Then load_user_data(json.info)
End Sub
''' <summary>
''' Authenticates the user using their username and password
''' </summary>
''' <paramname="username">Username</param>
''' <paramname="pass">Password</param>
Public Sub login(ByVal username As String, ByVal pass As String)
Checkinit()
Dim hwid As String = WindowsIdentity.GetCurrent().User.Value
Dim init_iv = sha256(iv_key())
Dim values_to_upload = New NameValueCollection From {
{"type", byte_arr_to_str(Encoding.Default.GetBytes("login"))},
{"username", encrypt(username, enckey, init_iv)},
{"pass", encrypt(pass, enckey, init_iv)},
{"hwid", encrypt(hwid, enckey, init_iv)},
{"sessionid", byte_arr_to_str(Encoding.Default.GetBytes(sessionid))},
{"name", byte_arr_to_str(Encoding.Default.GetBytes(name))},
{"ownerid", byte_arr_to_str(Encoding.Default.GetBytes(ownerid))},
{"init_iv", init_iv}
}
Dim response = req(values_to_upload)
response = decrypt(response, enckey, init_iv)
Dim json = response_decoder.string_to_generic(Of response_structure)(response)
load_response_struct(json)
If json.success Then load_user_data(json.info)
End Sub
''' <summary>
''' Gives the user a subscription that has the same level as the key
''' </summary>
''' <paramname="username">Username of the user thats going to get upgraded</param>
''' <paramname="key">License with the same level as the subscription you want to give the user</param>
Public Sub upgrade(ByVal username As String, ByVal key As String)
Checkinit()
Dim hwid As String = WindowsIdentity.GetCurrent().User.Value
Dim init_iv = sha256(iv_key())
Dim values_to_upload = New NameValueCollection From {
{"type", byte_arr_to_str(Encoding.Default.GetBytes("upgrade"))},
{"username", encrypt(username, enckey, init_iv)},
{"key", encrypt(key, enckey, init_iv)},
{"sessionid", byte_arr_to_str(Encoding.Default.GetBytes(sessionid))},
{"name", byte_arr_to_str(Encoding.Default.GetBytes(name))},
{"ownerid", byte_arr_to_str(Encoding.Default.GetBytes(ownerid))},
{"init_iv", init_iv}
}
Dim response = req(values_to_upload)
response = decrypt(response, enckey, init_iv)
Dim json = response_decoder.string_to_generic(Of response_structure)(response)
json.success = False
load_response_struct(json)
End Sub
''' <summary>
''' Authenticate without using usernames and passwords
''' </summary>
''' <paramname="key">Licence used to login with</param>
Public Sub license(ByVal key As String)
Checkinit()
Dim hwid As String = WindowsIdentity.GetCurrent().User.Value
Dim init_iv = sha256(iv_key())
Dim values_to_upload = New NameValueCollection From {
{"type", byte_arr_to_str(Encoding.Default.GetBytes("license"))},
{"key", encrypt(key, enckey, init_iv)},
{"hwid", encrypt(hwid, enckey, init_iv)},
{"sessionid", byte_arr_to_str(Encoding.Default.GetBytes(sessionid))},
{"name", byte_arr_to_str(Encoding.Default.GetBytes(name))},
{"ownerid", byte_arr_to_str(Encoding.Default.GetBytes(ownerid))},
{"init_iv", init_iv}
}
Dim response = req(values_to_upload)
response = decrypt(response, enckey, init_iv)
Dim json = response_decoder.string_to_generic(Of response_structure)(response)
load_response_struct(json)
If json.success Then load_user_data(json.info)
End Sub
''' <summary>
''' checks if the current session is validated or not
''' </summary>
Public Sub check()
Checkinit()
Dim init_iv = sha256(iv_key())
Dim values_to_upload = New NameValueCollection From {
{"type", byte_arr_to_str(Encoding.Default.GetBytes("check"))},
{"sessionid", byte_arr_to_str(Encoding.Default.GetBytes(sessionid))},
{"name", byte_arr_to_str(Encoding.Default.GetBytes(name))},
{"ownerid", byte_arr_to_str(Encoding.Default.GetBytes(ownerid))},
{"init_iv", init_iv}
}
Dim response = req(values_to_upload)
response = decrypt(response, enckey, init_iv)
Dim json = response_decoder.string_to_generic(Of response_structure)(response)
load_response_struct(json)
End Sub
''' <summary>
''' Change the data of an existing user variable, *User must be logged in*
''' </summary>
''' <paramname="var">User variable name</param>
''' <paramname="data">The content of the variable</param>
Public Sub setvar(ByVal var As String, ByVal data As String)
Checkinit()
Dim init_iv = sha256(iv_key())
Dim values_to_upload = New NameValueCollection From {
{"type", byte_arr_to_str(Encoding.Default.GetBytes("setvar"))},
{"var", encrypt(var, enckey, init_iv)},
{"data", encrypt(data, enckey, init_iv)},
{"sessionid", byte_arr_to_str(Encoding.Default.GetBytes(sessionid))},
{"name", byte_arr_to_str(Encoding.Default.GetBytes(name))},
{"ownerid", byte_arr_to_str(Encoding.Default.GetBytes(ownerid))},
{"init_iv", init_iv}
}
Dim response = req(values_to_upload)
response = decrypt(response, enckey, init_iv)
Dim json = response_decoder.string_to_generic(Of response_structure)(response)
load_response_struct(json)
End Sub
''' <summary>
''' Gets the an existing user variable
''' </summary>
''' <paramname="var">User Variable Name</param>
''' <returns>The content of the user variable</returns>
Public Function getvar(ByVal var As String) As String
Checkinit()
Dim init_iv = sha256(iv_key())
Dim values_to_upload = New NameValueCollection From {
{"type", byte_arr_to_str(Encoding.Default.GetBytes("getvar"))},
{"var", encrypt(var, enckey, init_iv)},
{"sessionid", byte_arr_to_str(Encoding.Default.GetBytes(sessionid))},
{"name", byte_arr_to_str(Encoding.Default.GetBytes(name))},
{"ownerid", byte_arr_to_str(Encoding.Default.GetBytes(ownerid))},
{"init_iv", init_iv}
}
Dim response = req(values_to_upload)
response = decrypt(response, enckey, init_iv)
Dim json = response_decoder.string_to_generic(Of response_structure)(response)
load_response_struct(json)
If json.success Then Return json.response
Return Nothing
End Function
''' <summary>
''' Bans the current logged in user
''' </summary>
Public Sub ban()
Checkinit()
Dim init_iv = sha256(iv_key())
Dim values_to_upload = New NameValueCollection From {
{"type", byte_arr_to_str(Encoding.Default.GetBytes("ban"))},
{"sessionid", byte_arr_to_str(Encoding.Default.GetBytes(sessionid))},
{"name", byte_arr_to_str(Encoding.Default.GetBytes(name))},
{"ownerid", byte_arr_to_str(Encoding.Default.GetBytes(ownerid))},
{"init_iv", init_iv}
}
Dim response = req(values_to_upload)
response = decrypt(response, enckey, init_iv)
Dim json = response_decoder.string_to_generic(Of response_structure)(response)
load_response_struct(json)
End Sub
''' <summary>
''' Gets an existing global variable
''' </summary>
''' <paramname="varid">Variable ID</param>
''' <returns>The content of the variable</returns>
Public Function var(ByVal varid As String) As String
Checkinit()
Dim hwid As String = WindowsIdentity.GetCurrent().User.Value
Dim init_iv = sha256(iv_key())
Dim values_to_upload = New NameValueCollection From {
{"type", byte_arr_to_str(Encoding.Default.GetBytes("var"))},
{"varid", encrypt(varid, enckey, init_iv)},
{"sessionid", byte_arr_to_str(Encoding.Default.GetBytes(sessionid))},
{"name", byte_arr_to_str(Encoding.Default.GetBytes(name))},
{"ownerid", byte_arr_to_str(Encoding.Default.GetBytes(ownerid))},
{"init_iv", init_iv}
}
Dim response = req(values_to_upload)
response = decrypt(response, enckey, init_iv)
Dim json = response_decoder.string_to_generic(Of response_structure)(response)
load_response_struct(json)
If json.success Then Return json.message
Return Nothing
End Function
''' <summary>
''' Gets the last 20 sent messages of that channel
''' </summary>
''' <paramname="channelname">The channel name</param>
''' <returns>the last 20 sent messages of that channel</returns>
Public Function chatget(ByVal channelname As String) As List(Of msg)
Checkinit()
Dim init_iv = sha256(iv_key())
Dim values_to_upload = New NameValueCollection From {
{"type", byte_arr_to_str(Encoding.Default.GetBytes("chatget"))},
{"channel", encrypt(channelname, enckey, init_iv)},
{"sessionid", byte_arr_to_str(Encoding.Default.GetBytes(sessionid))},
{"name", byte_arr_to_str(Encoding.Default.GetBytes(name))},
{"ownerid", byte_arr_to_str(Encoding.Default.GetBytes(ownerid))},
{"init_iv", init_iv}
}
Dim response = req(values_to_upload)
response = decrypt(response, enckey, init_iv)
Dim json = response_decoder.string_to_generic(Of response_structure)(response)
load_response_struct(json)
If json.success Then Return json.messages
Return Nothing
End Function
''' <summary>
''' Sends a message to the given channel name
''' </summary>
''' <paramname="msg">Message</param>
''' <paramname="channelname">Channel Name</param>
''' <returns>If the message was sent successfully, it returns true if not false</returns>
Public Function chatsend(ByVal msg As String, ByVal channelname As String) As Boolean
Checkinit()
Dim init_iv = sha256(iv_key())
Dim values_to_upload = New NameValueCollection From {
{"type", byte_arr_to_str(Encoding.Default.GetBytes("chatsend"))},
{"message", encrypt(msg, enckey, init_iv)},
{"channel", encrypt(channelname, enckey, init_iv)},
{"sessionid", byte_arr_to_str(Encoding.Default.GetBytes(sessionid))},
{"name", byte_arr_to_str(Encoding.Default.GetBytes(name))},
{"ownerid", byte_arr_to_str(Encoding.Default.GetBytes(ownerid))},
{"init_iv", init_iv}
}
Dim response = req(values_to_upload)
response = decrypt(response, enckey, init_iv)
Dim json = response_decoder.string_to_generic(Of response_structure)(response)
load_response_struct(json)
If json.success Then Return True
Return False
End Function
''' <summary>
''' Checks if the current ip address/hwid is blacklisted
''' </summary>
''' <returns>If found blacklisted returns true if not false</returns>
Public Function checkblack() As Boolean
Checkinit()
Dim hwid As String = WindowsIdentity.GetCurrent().User.Value
Dim init_iv = sha256(iv_key())
Dim values_to_upload = New NameValueCollection From {
{"type", byte_arr_to_str(Encoding.Default.GetBytes("checkblacklist"))},
{"hwid", encrypt(hwid, enckey, init_iv)},
{"sessionid", byte_arr_to_str(Encoding.Default.GetBytes(sessionid))},
{"name", byte_arr_to_str(Encoding.Default.GetBytes(name))},
{"ownerid", byte_arr_to_str(Encoding.Default.GetBytes(ownerid))},
{"init_iv", init_iv}
}
Dim response = req(values_to_upload)
response = decrypt(response, enckey, init_iv)
Dim json = response_decoder.string_to_generic(Of response_structure)(response)
load_response_struct(json)
If json.success Then Return True
Return False
End Function
''' <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>
''' <paramname="webid">Webhook ID</param>
''' <paramname="param">Parameters</param>
''' <paramname="body">Body of the request, empty by default</param>
''' <paramname="conttype">Content type, empty by default</param>
''' <returns>the webhook's response</returns>
Public Function webhook(ByVal webid As String, ByVal param As String, ByVal Optional body As String = "", ByVal Optional conttype As String = "") As String
Checkinit()
Dim init_iv = sha256(iv_key())
Dim values_to_upload = New NameValueCollection From {
{"type", byte_arr_to_str(Encoding.Default.GetBytes("webhook"))},
{"webid", encrypt(webid, enckey, init_iv)},
{"params", encrypt(param, enckey, init_iv)},
{"body", encrypt(body, enckey, init_iv)},
{"conttype", encrypt(conttype, enckey, init_iv)},
{"sessionid", byte_arr_to_str(Encoding.Default.GetBytes(sessionid))},
{"name", byte_arr_to_str(Encoding.Default.GetBytes(name))},
{"ownerid", byte_arr_to_str(Encoding.Default.GetBytes(ownerid))},
{"init_iv", init_iv}
}
Dim response = req(values_to_upload)
response = decrypt(response, enckey, init_iv)
Dim json = response_decoder.string_to_generic(Of response_structure)(response)
load_response_struct(json)
If json.success Then Return json.response
Return Nothing
End Function
''' <summary>
''' KeyAuth acts as proxy and downlods the file in a secure way
''' </summary>
''' <paramname="fileid">File ID</param>
''' <returns>The bytes of the download file</returns>
Public Function download(ByVal fileid As String) As Byte()
Checkinit()
Dim init_iv = encryption.sha256(encryption.iv_key())
''' Cannot convert LocalDeclarationStatementSyntax, System.InvalidCastException: Unable to cast object of type 'Microsoft.CodeAnalysis.VisualBasic.Syntax.EmptyStatementSyntax' to type 'Microsoft.CodeAnalysis.VisualBasic.Syntax.ExpressionSyntax'.
''' at ICSharpCode.CodeConverter.VB.CommonConversions.RemodelVariableDeclaration(VariableDeclarationSyntax declaration) in D:\GitWorkspace\CodeConverter\CodeConverter\VB\CommonConversions.cs:line 471
''' at ICSharpCode.CodeConverter.VB.MethodBodyExecutableStatementVisitor.VisitLocalDeclarationStatement(LocalDeclarationStatementSyntax node) in D:\GitWorkspace\CodeConverter\CodeConverter\VB\MethodBodyExecutableStatementVisitor.cs:line 52
''' at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor`1.Visit(SyntaxNode node)
''' at ICSharpCode.CodeConverter.VB.CommentConvertingMethodBodyVisitor.DefaultVisit(SyntaxNode node) in D:\GitWorkspace\CodeConverter\CodeConverter\VB\CommentConvertingMethodBodyVisitor.cs:line 16
'''
''' Input:
'''
''' var values_to_upload = new NameValueCollection
''' {
'''
''' ["type"] = encryption.byte_arr_to_str(System.Text.Encoding.Default.GetBytes("file")),
''' ["fileid"] = encryption.encrypt(fileid, enckey, init_iv),
''' ["sessionid"] = encryption.byte_arr_to_str(System.Text.Encoding.Default.GetBytes(sessionid)),
''' ["name"] = encryption.byte_arr_to_str(System.Text.Encoding.Default.GetBytes(name)),
''' ["ownerid"] = encryption.byte_arr_to_str(System.Text.Encoding.Default.GetBytes(ownerid)),
''' ["init_iv"] = init_iv
''' };
'''
'''
Dim response = req(values_to_upload)
response = encryption.decrypt(response, enckey, init_iv)
Dim json = response_decoder.string_to_generic(Of response_structure)(response)
load_response_struct(json)
If json.success Then Return encryption.str_to_byte_arr(json.contents)
Return Nothing
End Function
''' <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>
''' <paramname="message">Message</param>
Public Sub log(ByVal message As String)
Checkinit()
Dim init_iv = sha256(iv_key())
Dim values_to_upload = New NameValueCollection From {
{"type", byte_arr_to_str(Encoding.Default.GetBytes("log"))},
{"pcuser", encrypt(Environment.UserName, enckey, init_iv)},
{"message", encrypt(message, enckey, init_iv)},
{"sessionid", byte_arr_to_str(Encoding.Default.GetBytes(sessionid))},
{"name", byte_arr_to_str(Encoding.Default.GetBytes(name))},
{"ownerid", byte_arr_to_str(Encoding.Default.GetBytes(ownerid))},
{"init_iv", init_iv}
}
req(values_to_upload)
End Sub
Public Shared Function checksum(ByVal filename As String) As String
Dim result As String
Using md As MD5 = MD5.Create()
Using fileStream = File.OpenRead(filename)
Dim value = md.ComputeHash(fileStream)
result = BitConverter.ToString(value).Replace("-", "").ToLowerInvariant()
End Using
End Using
Return result
End Function
Public Shared Sub [error](ByVal message As String)
Call Process.Start(New ProcessStartInfo("cmd.exe", $"/c start cmd /C ""color b && title Error && echo {message} && timeout /t 5""") With {
.CreateNoWindow = True,
.RedirectStandardOutput = True,
.RedirectStandardError = True,
.UseShellExecute = False
})
Environment.Exit(0)
End Sub
Private Shared Function req(ByVal post_data As NameValueCollection) As String
Try
Using client As WebClient = New WebClient()
Dim raw_response = client.UploadValues("https://keyauth.win/api/1.0/", post_data)
Return Encoding.Default.GetString(raw_response)
End Using
Catch webex As WebException
Dim response = CType(webex.Response, HttpWebResponse)
Select Case response.StatusCode
Case CType(429, HttpStatusCode) ' client hit our rate limit
Thread.Sleep(1000)
Return SurroundingClass.req(post_data) ' site won't resolve. you should use keyauth.uk domain since it's not blocked by any ISPs
Case Else
[error]("Connection failure. Please try again, or contact us for help.")
Environment.Exit(0)
Return ""
End Select
End Try
End Function
Private Shared Function raw_response() As Byte()
Throw New NotImplementedException()
End Function
#Region "app_data"
Public app_data As app_data_class = New app_data_class()
Public Class app_data_class
Public Property numUsers As String
Public Property numOnlineUsers As String
Public Property numKeys As String
Public Property version As String
Public Property customerPanelLink As String
Public Property downloadLink As String
End Class
Private Sub load_app_data(ByVal data As app_data_structure)
app_data.numUsers = data.numUsers
app_data.numOnlineUsers = data.numOnlineUsers
app_data.numKeys = data.numKeys
app_data.version = data.version
app_data.customerPanelLink = data.customerPanelLink
End Sub
#End Region
#Region "user_data"
Public user_data As user_data_class = New user_data_class()
Public Class user_data_class
Public Property username As String
Public Property ip As String
Public Property hwid As String
Public Property createdate As String
Public Property lastlogin As String
Public Property subscriptions As List(Of Data) ' array of subscriptions (basically multiple user ranks for user with individual expiry dates
End Class
Public Class Data
Public Property subscription As String
Public Property expiry As String
Public Property timeleft As String
End Class
Private Sub load_user_data(ByVal data As user_data_structure)
user_data.username = data.username
user_data.ip = data.ip
user_data.hwid = data.hwid
user_data.createdate = data.createdate
user_data.lastlogin = data.lastlogin
user_data.subscriptions = data.subscriptions ' array of subscriptions (basically multiple user ranks for user with individual expiry dates
End Sub
#End Region
Public Function expirydaysleft() As String
Checkinit()
Dim dtDateTime As Date = New DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Local)
dtDateTime = dtDateTime.AddSeconds(Long.Parse(user_data.subscriptions(0).expiry)).ToLocalTime()
Dim difference = dtDateTime - Date.Now
Return Convert.ToString(difference.Days & " Days " & difference.Hours & " Hours Left")
End Function
#Region "response_struct"
Public response As response_class = New response_class()
Public Class response_class
Public Property success As Boolean
Public Property message As String
End Class
Private Sub load_response_struct(ByVal data As response_structure)
response.success = data.success
response.message = data.message
End Sub
#End Region
Private response_decoder As json_wrapper = New json_wrapper(New response_structure())
Private values_to_upload As NameValueCollection
End Class
Public Module encryption
Public Function byte_arr_to_str(ByVal ba As Byte()) As String
Dim hex As StringBuilder = New StringBuilder(ba.Length * 2)
For Each b In ba
hex.AppendFormat("{0:x2}", b)
Next
Return hex.ToString()
End Function
Public Function str_to_byte_arr(ByVal hex As String) As Byte()
Try
Dim NumberChars = hex.Length
Dim bytes = New Byte(NumberChars / 2 - 1) {}
For i = 0 To NumberChars - 1 Step 2
bytes(i / 2) = Convert.ToByte(hex.Substring(i, 2), 16)
Next
Return bytes
Catch
Console.WriteLine(vbLf & vbLf & " The session has ended, open program again.")
Thread.Sleep(3500)
Environment.Exit(0)
Return Nothing
End Try
End Function
Public Function encrypt_string(ByVal plain_text As String, ByVal key As Byte(), ByVal iv As Byte()) As String
Dim encryptor As Aes = Aes.Create()
encryptor.Mode = CipherMode.CBC
encryptor.Key = key
encryptor.IV = iv
Using mem_stream As MemoryStream = New MemoryStream()
Using aes_encryptor As ICryptoTransform = encryptor.CreateEncryptor()
Using crypt_stream As CryptoStream = New CryptoStream(mem_stream, aes_encryptor, CryptoStreamMode.Write)
Dim p_bytes = Encoding.Default.GetBytes(plain_text)
crypt_stream.Write(p_bytes, 0, p_bytes.Length)
crypt_stream.FlushFinalBlock()
Dim c_bytes As Byte() = mem_stream.ToArray()
Return byte_arr_to_str(c_bytes)
End Using
End Using
End Using
End Function
Public Function decrypt_string(ByVal cipher_text As String, ByVal key As Byte(), ByVal iv As Byte()) As String
Dim encryptor As Aes = Aes.Create()
encryptor.Mode = CipherMode.CBC
encryptor.Key = key
encryptor.IV = iv
Using mem_stream As MemoryStream = New MemoryStream()
Using aes_decryptor As ICryptoTransform = encryptor.CreateDecryptor()
Using crypt_stream As CryptoStream = New CryptoStream(mem_stream, aes_decryptor, CryptoStreamMode.Write)
Dim c_bytes = str_to_byte_arr(cipher_text)
crypt_stream.Write(c_bytes, 0, c_bytes.Length)
crypt_stream.FlushFinalBlock()
Dim p_bytes As Byte() = mem_stream.ToArray()
Return Encoding.Default.GetString(p_bytes, 0, p_bytes.Length)
End Using
End Using
End Using
End Function
Public Function iv_key() As String
Return Guid.NewGuid().ToString().Substring(0, Guid.NewGuid().ToString().IndexOf("-", StringComparison.Ordinal))
End Function
Public Function sha256(ByVal r As String) As String
Return byte_arr_to_str(New SHA256Managed().ComputeHash(Encoding.Default.GetBytes(r)))
End Function
Public Function encrypt(ByVal message As String, ByVal enc_key As String, ByVal iv As String) As String
Dim _key = Encoding.Default.GetBytes(sha256(enc_key).Substring(0, 32))
Dim _iv = Encoding.Default.GetBytes(sha256(iv).Substring(0, 16))
Return encrypt_string(message, _key, _iv)
End Function
Public Function decrypt(ByVal message As String, ByVal enc_key As String, ByVal iv As String) As String
Dim _key = Encoding.Default.GetBytes(sha256(enc_key).Substring(0, 32))
Dim _iv = Encoding.Default.GetBytes(sha256(iv).Substring(0, 16))
Return decrypt_string(message, _key, _iv)
End Function
End Module
Public Class json_wrapper
Public Shared Function is_serializable(ByVal to_check As Type) As Boolean
Return to_check.IsSerializable OrElse to_check.IsDefined(GetType(DataContractAttribute), True)
End Function
Public Sub New(ByVal obj_to_work_with As Object)
current_object = obj_to_work_with
Dim object_type = current_object.GetType()
serializer = New DataContractJsonSerializer(object_type)
If Not is_serializable(object_type) Then Throw New Exception($"the object {current_object} isn't a serializable")
End Sub
Public Function string_to_object(ByVal json As String) As Object
Dim buffer = Encoding.Default.GetBytes(json)
'SerializationException = session expired
Using mem_stream = New MemoryStream(buffer)
Return serializer.ReadObject(mem_stream)
End Using
End Function
Public Function string_to_generic(Of T)(ByVal json As String) As T
Return string_to_object(json)
End Function
Private serializer As DataContractJsonSerializer
Private current_object As Object
End Class
End Namespace