Use the serial number of the disk for Software Encryption

Source: Internet
Author: User

 
People who have used shared software know that common shared software (especially those outside China) will
Put forward some "demanding" requirements, such as asking you to enter the registration number and so on. If you want to implement this function in the software"
There are many methods. Here I will introduce one that I think is highly secure for your reference only.
As we all know, when you type the "dir" command in the command line, the system will read
The hexadecimal Number of Number. This number is theoretically hundreds of millions, and it is difficult to find two serial numbers at the same time.
The same hard disk. This is the theoretical basis of my registration method. It is determined by determining the serial number of the specified disk.
The registration number of the device.
To implement this function, it is critical to obtain the serial number of a specified disk. In Windows, there is a Get
The VolumeInformation API function can be implemented using this function.
The following code is required to implement this function:

The following is a code snippet:
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 the serial number of a disk, just DriverSerial (the drive letter of the disk. For example
DriverASerialNumber = DriverSerial ("").
Next, we can use the returned disk serial number for encryption, which requires some mathematical knowledge. Here
I used the encryption algorithm of the Russian password table to encrypt the serial number of the mathematical transformation. The following is the registration code
Verification Code:

The following is a code snippet:
Public Function IsValidate (ByVal SRC As Long, ByVal Value As String)
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 Integer
 

 

'================================================ ======================================
'Here is the password table. Change it to another table based on your requirements, but the length must be the same.
'================================================ ======================================

'Note: After the password table changes here, the password table of the corresponding registration number generator must be completely consistent to generate
Correct registration number

The following is a code snippet:
Table = "JSDJFKLUWRUOISDH; KSADJKLWQ; ABCDEFHIHL; kladshkjarfwiherqowrlqh"
'================================================ ======================================
Dim Result As String
Dim MidWord As String
Dim MidWordValue As Byte
Dim ResultValue As Byte
For 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 TableIndex = 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 Then IsValidate = True
End Function
 

Because the code is long and some code is omitted here, you can go to my website (http: // vbtech
Nology.yeah.net) to download the source program.
Finally, we can use these subroutines for encryption.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.