Da ich festgestellt habe, dass ich nur einen Teil des Programms kopiert hatte, hier nur die komplette Fassung:
Option Explicit
Private Declare PtrSafe Function CryptAcquireContext Lib "advapi32.dll" _
Alias "CryptAcquireContextA" ( _
ByRef phProv As Long, _
ByVal pszContainer As String, _
ByVal pszProvider As String, _
ByVal dwProvType As Long, _
ByVal dwFlags As Long) As Long
Private Declare PtrSafe Function CryptReleaseContext Lib "advapi32.dll" ( _
ByVal hProv As Long, _
ByVal dwFlags As Long) As Long
Private Declare PtrSafe Function CryptCreateHash Lib "advapi32.dll" ( _
ByVal hProv As Long, _
ByVal Algid As Long, _
ByVal hKey As Long, _
ByVal dwFlags As Long, _
ByRef phHash As Long) As Long
Private Declare PtrSafe Function CryptDestroyHash Lib "advapi32.dll" ( _
ByVal hHash As Long) As Long
Private Declare PtrSafe Function CryptHashData Lib "advapi32.dll" ( _
ByVal hHash As Long, _
pbData As Byte, _
ByVal dwDataLen As Long, _
ByVal dwFlags As Long) As Long
Private Declare PtrSafe Function CryptGetHashParam Lib "advapi32.dll" ( _
ByVal hHash As Long, _
ByVal dwParam As Long, _
pbData As Any, _
pdwDataLen As Long, _
ByVal dwFlags As Long) As Long
Private Const ALG_CLASS_HASH As Long = (4 * 2 ^ 13)
Private Const ALG_SID_HMAC As Long = 9
Private Const ALG_SID_MD2 As Long = 1
Private Const ALG_SID_MD4 As Long = 2
Private Const ALG_SID_MD5 As Long = 3
Private Const ALG_SID_SHA As Long = 4
Private Const ALG_SID_SHA1 As Long = 4
Private Const ALG_TYPE_ANY As Long = 0
Private Const CALG_MD2 As Long = (ALG_CLASS_HASH Or ALG_TYPE_ANY Or ALG_SID_MD2)
Private Const CALG_MD4 As Long = (ALG_CLASS_HASH Or ALG_TYPE_ANY Or ALG_SID_MD4)
Private Const CALG_MD5 As Long = (ALG_CLASS_HASH Or ALG_TYPE_ANY Or ALG_SID_MD5)
Private Const CALG_SHA1 As Long = (ALG_CLASS_HASH Or ALG_TYPE_ANY Or ALG_SID_SHA1)
Enum Algorithmus
md2 = CALG_MD2
md4 = CALG_MD4
md5 = CALG_MD5
SHA1 = CALG_SHA1
End Enum
Function Crypt(Text As String, Art As Algorithmus) As String
Dim AcquireContext As Long
Dim HashHandle As Long
Dim result As Long
Dim ByteText() As Byte
Dim LängeResult As Long
Dim ByteResult() As Byte
Dim Zähler As Integer
ByteText() = StrConv(Text, vbFromUnicode)
result = CryptAcquireContext(AcquireContext, vbNullString, vbNullString, 1, 0)
If result = 0 And Err.LastDllError = &H80090016 Then _
result = CryptAcquireContext(AcquireContext, vbNullString, vbNullString, 1, &H8)
result = CryptCreateHash(AcquireContext, Art, 0, 0, HashHandle)
result = CryptHashData(HashHandle, ByteText(0), Len(Text), 0)
result = CryptGetHashParam(HashHandle, 4, LängeResult, 4, 0)
ReDim ByteResult(0 To LängeResult - 1) As Byte
result = CryptGetHashParam(HashHandle, 2, ByteResult(0), LängeResult, 0)
For Zähler = 0 To UBound(ByteResult)
Crypt = Crypt & Right$("0" & Hex$(ByteResult(Zähler)), 2)
Next
CryptDestroyHash HashHandle
CryptReleaseContext AcquireContext, 0
End Function
Private Sub CommandButton1_Click()
Unload Gültigkeitsprüfung
Eingabemaske.Show
End Sub
Private Sub CommandButton2_Click()
Unload Gültigkeitsprüfung
End Sub
Private Sub CommandButton3_Click()
If TextBox1.Value <> vbNullString Then
Worksheets("Tabelle1").Range("B86").Value = Crypt(TextBox1.Value, md5)
Dim result As Integer
result = StrComp(Worksheets("Tabelle1").Range("B86").Value, Worksheets("Tabelle1").Range("B84").Value, vbTextCompare)
If result = 0 Then
Worksheets("Tabelle1").Range("B85").Value = "x"
Worksheets("Tabelle1").Range("B87").Value = Environ("Username")
MsgBox "Der eingegebene Lizenzschlüssel ist korrekt."
Unload Gültigkeitsprüfung
Eingabemaske.Show
Else
MsgBox "Ungültiger Lizenzschlüssel"
End If
Else
MsgBox "Bitte geben Sie einen Lizenzschlüssel ein."
End If
End Sub
Private Sub Label1_Click()
End Sub
Private Sub UserForm_Initialize()
If Date > Worksheets("Tabelle1").Range("B82").Value Then
CommandButton1.Enabled = False
Label1.Caption = "Diese Testversion ist abgelaufen." & vbCrLf & vbCrLf & "Bitte geben Sie einen gültigen Lizenzschlüssel ein."
Else
CommandButton1.Enabled = True
Label1.Caption = "Diese Testversion ist noch bis zum " & Worksheets("Tabelle1").Range("B82").Value & " gültig." & vbCrLf & "Danach benötigen Sie einen Lizenzschlüssel."
End If
End Sub
|