★ HWID license file auth system ★
This tutorial will teach you how to use a combination of HWID to protect your application from leaker
First, you create new class , and add these HWID function to it in order to call it later. Don't forget to add a reference to System.Management
Code
Imports System.Management
Public Class clsComputerInfo
Public Shared Function GetProcessorId() As String
Dim strProcessorId As String = String.Empty
Dim query As New SelectQuery("Win32_processor")
Dim search As New ManagementObjectSearcher(query)
Dim info As ManagementObject
For Each info In search.Get()
strProcessorId = info("processorId").ToString()
Next
Return strProcessorId
End Function
Public Shared Function GetMACAddress() As String
Dim mc As ManagementClass = New ManagementClass("Win32_NetworkAdapterConfiguration")
Dim moc As ManagementObjectCollection = mc.GetInstances()
Dim MACAddress As String = String.Empty
For Each mo As ManagementObject In moc
If (MACAddress.Equals(String.Empty)) Then
If CBool(mo("IPEnabled")) Then MACAddress = mo("MacAddress").ToString()
mo.Dispose()
End If
MACAddress = MACAddress.Replace(":", String.Empty)
Next
Return MACAddress
End Function
Public Shared Function GetVolumeSerial(Optional ByVal strDriveLetter As String = "C") As String
Dim disk As ManagementObject = New ManagementObject(String.Format("win32_logicaldisk.deviceid=""{0}:""", strDriveLetter))
disk.Get()
Return disk("VolumeSerialNumber").ToString()
End Function
End ClassSo my class will look like this.
[img]http://upic.me/i/qg/4hl42.png[/img]
Then we declare 3 variables to store 3 HWID by
Code
Dim MyMacAddress As String = clsComputerInfo.GetMACAddress()
Dim MyProcessAddress As String = clsComputerInfo.GetProcessorId()
Dim MyVolumeAddress As String = clsComputerInfo.GetVolumeSerial()So MacAddress,ProcessorID,HDVolume will be stored.
Then we declare another variable to store the formatted HWID.
Code
Dim TFC_MID As String = "TFCZ-" & MyMacAddress.Substring(MyMacAddress.Length() - 4, 4) _
& "-" & MyProcessAddress.Substring(MyProcessAddress.Length() - 4, 4) & "-" & MyVolumeAddress.Substring(MyVolumeAddress.Length() - 4, 4)The above code will declare TFC_MID to be a string with TFCZ as salt followed by last 4 string of MACAddress , ProcessID , Volume.
The format will look like this
Code
TFCZ-XXXX-XXXX-XXXX*Note that you can change how to order those three above or change salt TFCZ into another name.
After that, we add RC4 encryption algorithm below the sub form1_load
Code
Public Shared Function rc4(ByVal message As String, ByVal password As String) As String
Dim i As Integer = 0
Dim j As Integer = 0
Dim cipher As New StringBuilder
Dim returnCipher As String = String.Empty
Dim sbox As Integer() = New Integer(256) {}
Dim key As Integer() = New Integer(256) {}
Dim intLength As Integer = password.Length
Dim a As Integer = 0
While a <= 255
Dim ctmp As Char = (password.Substring((a Mod intLength), 1).ToCharArray()(0))
key(a) = Microsoft.VisualBasic.Strings.Asc(ctmp)
sbox(a) = a
System.Math.Max(System.Threading.Interlocked.Increment(a), a - 1)
End While
Dim x As Integer = 0
Dim b As Integer = 0
While b <= 255
x = (x + sbox(b) + key(b)) Mod 256
Dim tempSwap As Integer = sbox(b)
sbox(b) = sbox(x)
sbox(x) = tempSwap
System.Math.Max(System.Threading.Interlocked.Increment(b), b - 1)
End While
a = 1
While a <= message.Length
Dim itmp As Integer = 0
i = (i + 1) Mod 256
j = (j + sbox(i)) Mod 256
itmp = sbox(i)
sbox(i) = sbox(j)
sbox(j) = itmp
Dim k As Integer = sbox((sbox(i) + sbox(j)) Mod 256)
Dim ctmp As Char = message.Substring(a - 1, 1).ToCharArray()(0)
itmp = Asc(ctmp)
Dim cipherby As Integer = itmp Xor k
cipher.Append(Chr(cipherby))
System.Math.Max(System.Threading.Interlocked.Increment(a), a - 1)
End While
returnCipher = cipher.ToString
cipher.Length = 0
Return returnCipher
End FunctionCode
Imports System.IO
Imports System.TextThen we add
Code
If (File.Exists(Application.StartupPath & "\TFC.lic")) ThenCode
Dim stream_reader As New StreamReader(Application.StartupPath & "\TFC.LIC")Code
Dim myMIDReader = rc4(stream_reader.ReadToEnd, "TFC")
stream_reader.close()Code
If (myMIDReader = TFC_MID) Then
Else
MsgBox("The license key is incorrect, please contact [email protected] for more information", MsgBoxStyle.Critical)
End
End If
Else
MsgBox("Your machine ID is : " & TFC_MID & vbCrLf & "Your machine ID is copied to clipboard, press ctrl+v to paste it!", MsgBoxStyle.Critical)
Clipboard.SetText(TFC_MID)
End
End IfAnd if it's not the same , it show the msgbox that the license key is incorrect and end the application.
The next else show the machine ID and copy it to clipboard in case the license key is not found.
This is the final code in form1_load()
[img]http://upic.me/i/fl/0rj63.png[/img]
[color=#FFD700]The keygen part
[img]http://upic.me/i/zd/ykh94.png[/img]
Create new project and add 1 textbox and 1 button as above.
then add
Code
Imports System.IO
Imports System.Textand add this RC4 encryption to the application
Code
Public Shared Function rc4(ByVal message As String, ByVal password As String) As String
Dim i As Integer = 0
Dim j As Integer = 0
Dim cipher As New StringBuilder
Dim returnCipher As String = String.Empty
Dim sbox As Integer() = New Integer(256) {}
Dim key As Integer() = New Integer(256) {}
Dim intLength As Integer = password.Length
Dim a As Integer = 0
While a <= 255
Dim ctmp As Char = (password.Substring((a Mod intLength), 1).ToCharArray()(0))
key(a) = Microsoft.VisualBasic.Strings.Asc(ctmp)
sbox(a) = a
System.Math.Max(System.Threading.Interlocked.Increment(a), a - 1)
End While
Dim x As Integer = 0
Dim b As Integer = 0
While b <= 255
x = (x + sbox(b) + key(b)) Mod 256
Dim tempSwap As Integer = sbox(b)
sbox(b) = sbox(x)
sbox(x) = tempSwap
System.Math.Max(System.Threading.Interlocked.Increment(b), b - 1)
End While
a = 1
While a <= message.Length
Dim itmp As Integer = 0
i = (i + 1) Mod 256
j = (j + sbox(i)) Mod 256
itmp = sbox(i)
sbox(i) = sbox(j)
sbox(j) = itmp
Dim k As Integer = sbox((sbox(i) + sbox(j)) Mod 256)
Dim ctmp As Char = message.Substring(a - 1, 1).ToCharArray()(0)
itmp = Asc(ctmp)
Dim cipherby As Integer = itmp Xor k
cipher.Append(Chr(cipherby))
System.Math.Max(System.Threading.Interlocked.Increment(a), a - 1)
End While
returnCipher = cipher.ToString
cipher.Length = 0
Return returnCipher
End Functionthen double click at the button and add this code
Code
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim write_file As New StreamWriter(Application.StartupPath & "\TFC.lic", False)
write_file.Write(rc4(TextBox1.Text, "TFC"))
write_file.Close()
End SubThat's it! Have fun :D


![[Image: wlQx51C.png]](https://i.imgur.com/wlQx51C.png)

![[Image: 0sW1RxG.gif]](https://i.imgur.com/0sW1RxG.gif)
