★HWID Authorization System★

Heres your chance to share your own tutorials with the community. Just post them on here. If your lucky they may even be posted on the main site.
4 posts Page 1 of 1
Contributors
User avatar
Skillful
Skillful Coders
Skillful Coders
Posts: 969
Joined: Tue Nov 16, 2010 10:07 am

★HWID Authorization System★
Skillful
Hello. :)

Welcome to my new tutorial. :D

This tutorial will teach you how to use a combination of HWID to protect your application from leaker. 8-)

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: Select all
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 Class
So my class will look like this.
Image

Then we declare 3 variables to store 3 HWID by
Code: Select all
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: Select all
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: Select all
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: Select all
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 Function
And don't forget to add this in the Imports
Code: Select all
Imports System.IO
Imports System.Text
Then we add this to check that the file "TFC.lic" is existed or not
Code: Select all
If (File.Exists(Application.StartupPath & "\TFC.lic")) Then
And then add this to make a stream reader to read for our license key
Code: Select all
Dim stream_reader As New StreamReader(Application.StartupPath & "\TFC.LIC")
Then we decrypt the lic file to compare with our HWID with TFC as password
Code: Select all
Dim myMIDReader = rc4(stream_reader.ReadToEnd, "TFC")
stream_reader.close()
After that we put
Code: Select all
If (myMIDReader = TFC_MID) Then

    Else
    MsgBox("The license key is incorrect, please contact email@email.com 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 If
to check that the decrypted lic file is same as TFC_MID or not. If yes, the program run normal.
And 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
Image

The generator part
Create new project and add 1 textbox and 1 button as below.
Image

Then add
Code: Select all
Imports System.IO
Imports System.Text
And now for the RC4 Encryption Fucntion.
Code: Select all
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 Function

Now finally under the Button1_Click event add this code.
Code: Select all
Dim write_file As New StreamWriter(Application.StartupPath & "\TFC.lic", False)
  write_file.Write(rc4(TextBox1.Text, "TFC"))
  write_file.Close()
*Note that the password "TFC" must the same as your application and keep it private or else anyone can gen your lic file :D . You can freely change the order or salt . Don't forget to obfuscate your application to prevent viewing through reflector and keep your keygen private.

That's it! Have fun wahooo;

Please leave a thanks if you liked this tutorial.

Hope you liked it.

Regards,
Skillful
Last edited by Skillful on Wed Mar 21, 2012 2:36 pm, edited 1 time in total.
Instead of LOL use this -
LSIBMHBIWFETALOL

Which means -
Laughing silently in between my head because it wasn't funny enough to actually laugh out loud!
User avatar
Dummy1912
VIP - Donator
VIP - Donator
Posts: 1969
Joined: Sat Aug 21, 2010 2:17 pm

nice tut :lol:
no link? to download the tut :P
Last edited by Dummy1912 on Wed Mar 21, 2012 2:41 pm, edited 1 time in total.
visit us on:


http://www.softpedia.com/get/System/Lau ... -Run.shtml
Check it out ! http://www.softpedia.com/publisher/I-A- ... 90017.html
Check it out ! http://www.softpedia.com/get/Desktop-En ... lock.shtml
User avatar
Skillful
Skillful Coders
Skillful Coders
Posts: 969
Joined: Tue Nov 16, 2010 10:07 am

Link for what?
Instead of LOL use this -
LSIBMHBIWFETALOL

Which means -
Laughing silently in between my head because it wasn't funny enough to actually laugh out loud!
User avatar
Martin
Supreme VIP
Supreme VIP
Posts: 369
Joined: Sat Aug 01, 2009 12:26 pm

Re: ★HWID Authorization System★
Martin
What do it do? dose it generate a id for each pc?
Image
4 posts Page 1 of 1
Return to “Tutorials”