Software encryption with the serial number of the disk

zhaozj2021-02-11  191

Software encryption with the serial number of the disk

People who have used shared software know that general sharing software (especially foreign) will propose some "harsh" requirements after using a period of time, such as letting you enter the registration number, and so on. If you want to implement the "function" in the software, there are a lot. Here I introduce a kind of kind of high security is only for reference only.

Everyone knows that when you type the "DIR" instruction in the command line, the system will read a hexadecimal number called Serial Number. This number has hundreds of millions of possibilities, and it is difficult to find two serial numbers. This is the theoretical basis of my registration method, determines the registration number of the machine by judging the serial number of the specified disk.

To implement this feature, how to get the serial number of the specified disk is the most critical. In Windows, there is a getVolumeInformation API function, we can use this function.

Below is the code required to implement this feature:

Private Declare Function GetVolumeInformation & Lib "kernel32" _

Alias ​​"getVolumeInformationa" (byval lprootpathname as string, _

Byval PvolumenameBuffer As String, Byval Nvolumenamesize As Long, _

LPVolumeSerialNumber As Long, LPMAXIMUMComponentlength As long, _

Lpfilesystemflags as long, byval lpfilesystemnamebuffer as string, _

Byval nfilesystemnamesize as long

Private const Max_filename_len = 256

Public Function Driveserial (Byval SDRV AS String) As Long

'Usage:

'DIM DS As long

'DS = Driveserial ("C")

DIM RETVAL AS Long

DIM STR AS STRING * MAX_FILENAME_LEN

DIM STR2 AS STRING * MAX_FILENAME_LEN

DIM A as long

DIM B AS Long

GetVolumeInformation SDRV & ": /", Str, Max_FileName_len, RetVal, _

A, B, STR2, MAX_FILENAME_LEN

Driveserial = RETVAL

END FUNCTION

If we need a serial number of a disk, as long as DriverSerial (the disk of the disk) can be. Such as DriveraSerialNumber = DriverSerial ("a"). Below, we can use the returned disk serial number to encrypt and need some mathematical knowledge. Here I use the encryption algorithm of the Russian code table to encrypt the serial number of mathematical transformation. Below is the code of the registration code verification section:

Public Function isvalidate (Byval src as stay) AS Boolean

Dim SourceString As String

Dim Newsrc As Long

FOR i = 0 to 30

IF (src and 2 ^ i) = 2 ^ I Then

SourceString = SourceString "1"

Else

SourceString = SourceString "0" end if

Next i

IF SRC <0 THEN

SourceString = SourceString "1"

Else

SourceString = SourceString "0"

END IF

DIM TABLE AS STRING

DIM TableIndex as in

'==================================================== ================================

'This is a cryptographic table, replaced according to your requirements, but the length should be consistent

'==================================================== ================================

'Note: After the password table here, the corresponding registration number generator's password table must be completely consistent to generate the correct registration number.

Table = "JSDJFKLUWRUOISDH; KSADJKLWQ; Abcdefhihl; Kladshkjagfwiherqowrlqh"

'==================================================== ================================

Dim Result As String

Dim Midword As String

Dim MidWordValue as Byte

Dim ResultValue as Bytefor T = 1 to 1

For i = 1 to len (SourceString)

MidWord = MID (SourceString, I, 1)

MidWordValue = ASC (MidWord)

TableIndex = TableIndex 1

If TableIndex> Len (Table) THEN TABLEDEX = 1

ResultValue = ASC (MID (Table, TableIndex, 1)) MOD MIDWORDVALUE

Result = Result HEX (ResultValue)

Next i

SourceString = result

Next T

Dim BitTorool As INTEGER

FOR T = 1 to Len (CSTR (SRC))

BitTorool = SRC and 2 ^ T

For i = 1 to BitTorool

SourceString = Right (SourceString, 1) _

Left (SourceString, Len (SourceString) - 1)

Next i

Next T

IF SourceString = Value the isvalidate = TRUE

END FUNCTION

Due to the longer code, there are some partial code omitted here, you can go to my website (http://vbtechnology.yeah.net) download the source program.

Finally, we can use these subroutines to encrypt.

转载请注明原文地址:https://www.9cbs.com/read-4890.html

New Post(0)