add LicenseManager from DD_LIB_STANDARD
This commit is contained in:
parent
e2fa252c07
commit
a2b0959f22
@ -74,9 +74,12 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="LicenseCreator.vb" />
|
||||
<Compile Include="LicenseFile.vb" />
|
||||
<Compile Include="LicenseLegacy.vb" />
|
||||
<Compile Include="LicenseManagerLegacy.vb" />
|
||||
<Compile Include="LicenseSchema.vb">
|
||||
<DependentUpon>LicenseSchema.xsd</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="LicensesLegacy.vb" />
|
||||
<Compile Include="My Project\AssemblyInfo.vb" />
|
||||
<Compile Include="My Project\Application.Designer.vb">
|
||||
<AutoGen>True</AutoGen>
|
||||
|
||||
44
Modules.License/LicenseLegacy.vb
Normal file
44
Modules.License/LicenseLegacy.vb
Normal file
@ -0,0 +1,44 @@
|
||||
Public Class LicenseLegacy
|
||||
' ++++++++++++++++++++++++++++++++++++++++++++++ Methoden ++++++++++++++++++++++++++++++++++++++++++++++
|
||||
|
||||
''' <summary>
|
||||
''' Konstruktor der Lizenz
|
||||
''' </summary>
|
||||
Sub New(ByVal _ModuleName As String, ByVal _Expires As Date, ByVal _Type As String, ByVal _AnzProfile As String)
|
||||
Modulename = _ModuleName
|
||||
Expires = _Expires
|
||||
Type = _Type
|
||||
Anz_Profile = _AnzProfile
|
||||
End Sub
|
||||
|
||||
' ++++++++++++++++++++++++++++++++++++++++++++++ Properties ++++++++++++++++++++++++++++++++++++++++++++++
|
||||
|
||||
''' <summary>
|
||||
''' Liefert oder setzt den Namen des Moduls für diese Lizenz
|
||||
''' </summary>
|
||||
Public Property Modulename() As String
|
||||
''' <summary>
|
||||
''' Liefert oder setzt das Gültigkeitsdatum der Lizenz für das Modul
|
||||
''' </summary>
|
||||
Public Property Expires() As Date
|
||||
''' <summary>
|
||||
''' Liefert den Typen der Lizenz
|
||||
''' </summary>
|
||||
Public Property Type() As String
|
||||
''' <summary>
|
||||
''' Liefert die Anzahl der Profile
|
||||
''' </summary>
|
||||
Public Property Anz_Profile() As String
|
||||
''' <summary>
|
||||
''' Liefert ob die Lizenz schon abgelaufen ist
|
||||
''' </summary>
|
||||
Public ReadOnly Property IsExpired()
|
||||
Get
|
||||
If Date.Today > Expires Then
|
||||
Return True
|
||||
Else
|
||||
Return False
|
||||
End If
|
||||
End Get
|
||||
End Property
|
||||
End Class
|
||||
228
Modules.License/LicenseManagerLegacy.vb
Normal file
228
Modules.License/LicenseManagerLegacy.vb
Normal file
@ -0,0 +1,228 @@
|
||||
Imports System.Security.Cryptography
|
||||
Imports System.Text
|
||||
Imports DigitalData.Modules.Logging
|
||||
|
||||
Public Class LicenseManagerLegacy
|
||||
Public Shared _licenses As LicensesLegacy
|
||||
Private _Logger As Logger
|
||||
Private _LogConfig As LogConfig
|
||||
|
||||
Public LicenseString As String
|
||||
Public LicenseStringArray(,) As String
|
||||
|
||||
' ++++++++++++++++++++++++++++++++++++++++++++++ Methoden ++++++++++++++++++++++++++++++++++++++++++++++
|
||||
|
||||
''' <summary>
|
||||
''' Konstruktor für den Lizenz-Manager
|
||||
''' </summary>
|
||||
''' <param name="_Password">Passwort zum Entschlüsseln des Lizenzkeys</param>
|
||||
''' <param name="_Key">verschlüsselter Lizenzkey</param>
|
||||
''' <remarks></remarks>
|
||||
Sub New(LogConfig As LogConfig, ByVal _Password As String, ByVal _Key As String)
|
||||
_LogConfig = LogConfig
|
||||
_Logger = LogConfig.GetLogger
|
||||
|
||||
Password = _Password
|
||||
Key = _Key
|
||||
|
||||
LicenseString = DecodeLicenseKey(Key)
|
||||
LicenseStringArray = SplitLicenseString(LicenseString)
|
||||
|
||||
LoadLicenses()
|
||||
End Sub
|
||||
''' <summary>
|
||||
''' Konstruktor für den Lizenz-Manager ohne License load
|
||||
''' </summary>
|
||||
''' <param name="password">Passwort zum Entschlüsseln des Lizenzkeys</param>
|
||||
Sub New(ByVal password As String)
|
||||
Me.Password = password
|
||||
End Sub
|
||||
''' <summary>
|
||||
''' Lädt alle Lizenzen aus dem Lizenz-Array
|
||||
''' </summary>
|
||||
''' <remarks></remarks>
|
||||
Public Sub LoadLicenses()
|
||||
_licenses = New LicensesLegacy(_LogConfig, LicenseStringArray)
|
||||
End Sub
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' Codiert eine Zeichenkette
|
||||
''' </summary>
|
||||
''' <param name="str">zu verschlüsselnde Zeichenkette</param>
|
||||
''' <param name="password">das zur Verschlüsselung verwendete Passwort</param>
|
||||
''' <returns>liefert eine verschlüsselte Zeichenkette</returns>
|
||||
''' <remarks></remarks>
|
||||
Public Function EncodeLicenseKey(ByVal str As String, ByVal password As String)
|
||||
Dim oRijndael As New RijndaelManaged
|
||||
|
||||
Dim oMD5 As New MD5CryptoServiceProvider
|
||||
Dim oKey() As Byte = oMD5.ComputeHash(Encoding.UTF8.GetBytes(password))
|
||||
|
||||
oMD5.Clear()
|
||||
oRijndael.Key = oKey
|
||||
oRijndael.GenerateIV()
|
||||
|
||||
Dim oInitialVector() As Byte = oRijndael.IV
|
||||
Dim oStream As New IO.MemoryStream
|
||||
|
||||
oStream.Write(oInitialVector, 0, oInitialVector.Length)
|
||||
|
||||
Dim oCryptoStream As New CryptoStream(oStream, oRijndael.CreateEncryptor, CryptoStreamMode.Write)
|
||||
Dim oData() As Byte = Encoding.UTF8.GetBytes(str)
|
||||
|
||||
oCryptoStream.Write(oData, 0, oData.Length)
|
||||
oCryptoStream.FlushFinalBlock()
|
||||
|
||||
Dim oEncodedData() As Byte = oStream.ToArray()
|
||||
Dim oResult As String = Convert.ToBase64String(oEncodedData)
|
||||
oCryptoStream.Close()
|
||||
oRijndael.Clear()
|
||||
|
||||
Return oResult
|
||||
End Function
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' Decodiert den verschlüsselten Lizenzkey
|
||||
''' </summary>
|
||||
''' <param name="licenseCodeStr">verschlüsselter Lizenzkey</param>
|
||||
''' <returns></returns>
|
||||
''' <remarks></remarks>
|
||||
Public Function DecodeLicenseKey(ByVal licenseCodeStr As String)
|
||||
Try
|
||||
Dim oRijndael As New RijndaelManaged
|
||||
Dim oIVLength As Integer = 16
|
||||
Dim oMD5 As New MD5CryptoServiceProvider
|
||||
Dim oKey() As Byte = oMD5.ComputeHash(Encoding.UTF8.GetBytes(Me.Password))
|
||||
|
||||
oMD5.Clear()
|
||||
|
||||
Dim oEncodedData() As Byte
|
||||
Dim oStream
|
||||
Dim oInitialVector(15) As Byte
|
||||
Dim oCryptoStream As CryptoStream
|
||||
Dim oData() As Byte
|
||||
|
||||
Try
|
||||
oEncodedData = Convert.FromBase64String(licenseCodeStr)
|
||||
oStream = New IO.MemoryStream(oEncodedData)
|
||||
|
||||
oStream.Read(oInitialVector, 0, oIVLength)
|
||||
oRijndael.IV = oInitialVector
|
||||
oRijndael.Key = oKey
|
||||
|
||||
oCryptoStream = New CryptoStream(oStream, oRijndael.CreateDecryptor, CryptoStreamMode.Read)
|
||||
|
||||
ReDim oData(oStream.Length - oIVLength)
|
||||
Catch ex As Exception
|
||||
Return Nothing
|
||||
End Try
|
||||
|
||||
Dim oInteger As Integer = 0
|
||||
|
||||
Try
|
||||
oInteger = oCryptoStream.Read(oData, 0, oData.Length)
|
||||
Dim oResult As String = Encoding.UTF8.GetString(oData, 0, oInteger)
|
||||
|
||||
oCryptoStream.Close()
|
||||
oRijndael.Clear()
|
||||
Return oResult
|
||||
|
||||
Catch ex As Exception
|
||||
' Falsches Passwort
|
||||
_Logger.Warn("DecodeLicenseKey: Password Incorrect")
|
||||
_Logger.Error(ex)
|
||||
|
||||
Return Nothing
|
||||
|
||||
End Try
|
||||
Catch ex As Exception
|
||||
' Falsches Passwort
|
||||
_Logger.Warn("DecodeLicenseKey: Password Incorrect")
|
||||
_Logger.Error(ex)
|
||||
End Try
|
||||
|
||||
Return Nothing
|
||||
End Function
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' Zerlegt den entschlüsselten Lizenzkey
|
||||
''' </summary>
|
||||
''' <param name="licenseStr">entschlüsselter Lizenzkey</param>
|
||||
''' <returns></returns>
|
||||
''' <remarks></remarks>
|
||||
Public Function SplitLicenseString(ByVal licenseStr As String) As String(,)
|
||||
|
||||
Try
|
||||
If licenseStr IsNot Nothing Then
|
||||
Dim licenseTemp() As String = licenseStr.Split(";")
|
||||
|
||||
Dim licenses(licenseTemp.Length, 3) As String
|
||||
|
||||
Dim i As Integer = 0
|
||||
|
||||
If licenseTemp IsNot Nothing Then
|
||||
For Each lizenz As String In licenseTemp
|
||||
|
||||
Dim temp() = lizenz.Split(":")
|
||||
|
||||
licenses(i, 0) = temp(0)
|
||||
licenses(i, 1) = temp(1)
|
||||
If temp.Length > 2 Then
|
||||
licenses(i, 2) = temp(2)
|
||||
licenses(i, 3) = temp(3)
|
||||
Dim expires As Date
|
||||
Date.TryParse(licenses(i, 1), expires)
|
||||
End If
|
||||
|
||||
|
||||
i += 1
|
||||
Next
|
||||
|
||||
Return licenses
|
||||
End If
|
||||
End If
|
||||
Catch ex As Exception
|
||||
_Logger.Warn("Error in SplitLicenseString")
|
||||
_Logger.Error(ex)
|
||||
End Try
|
||||
|
||||
Return Nothing
|
||||
End Function
|
||||
|
||||
|
||||
|
||||
' ++++++++++++++++++++++++++++++++++++++++++++++ Properties ++++++++++++++++++++++++++++++++++++++++++++++
|
||||
|
||||
''' <summary>
|
||||
''' Liefert das Passwort zum Entschlüsseln des Lizenzschlüssels
|
||||
''' </summary>
|
||||
''' <value></value>
|
||||
''' <returns></returns>
|
||||
''' <remarks></remarks>
|
||||
Public ReadOnly Property Password() As String
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' Liefert eine Sammlung von Lizenzobjekten
|
||||
''' </summary>
|
||||
''' <value></value>
|
||||
''' <returns></returns>
|
||||
''' <remarks></remarks>
|
||||
Public ReadOnly Property Licenses() As LicensesLegacy
|
||||
Get
|
||||
Return _licenses
|
||||
End Get
|
||||
End Property
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' Liefert oder setzt den Lizenzschlüssel
|
||||
''' </summary>
|
||||
''' <value></value>
|
||||
''' <returns></returns>
|
||||
''' <remarks></remarks>
|
||||
Public Property Key() As String
|
||||
End Class
|
||||
104
Modules.License/LicensesLegacy.vb
Normal file
104
Modules.License/LicensesLegacy.vb
Normal file
@ -0,0 +1,104 @@
|
||||
Imports DigitalData.Modules.Logging
|
||||
|
||||
Public Class LicensesLegacy
|
||||
Private _licenses() As LicenseLegacy
|
||||
Private _WDLizenz As String
|
||||
Private _Logger As Logger
|
||||
|
||||
' ++++++++++++++++++++++++++++++++++++++++++++++ Methoden ++++++++++++++++++++++++++++++++++++++++++++++
|
||||
|
||||
''' <summary>
|
||||
''' Konstruktor für die Lizenzen-Sammlung
|
||||
''' </summary>
|
||||
''' <param name="licenseStringArray">In Array übertragene Lizenzinformationen</param>
|
||||
Sub New(LogConfig As LogConfig, ByVal licenseStringArray(,) As String)
|
||||
Try
|
||||
_Logger = LogConfig.GetLogger()
|
||||
|
||||
If licenseStringArray IsNot Nothing Then
|
||||
Dim license1() As String = licenseStringArray(0, 1).Split("#")
|
||||
|
||||
If license1.Length > 1 Then
|
||||
Me.machine = license1(1)
|
||||
Else
|
||||
Me.machine = "all"
|
||||
End If
|
||||
Me.Company = license1(0) 'licenseStringArray(0, 1)
|
||||
Dim i As Integer
|
||||
For i = 1 To licenseStringArray.GetLength(0) - 2 ' minus 2, weil GetLength nicht null-basiert ist und das erste Element Firma ist
|
||||
Dim anzprof As String = licenseStringArray(i, 3)
|
||||
If anzprof.ToLower = "unlimited" Then
|
||||
anzprof = 99
|
||||
End If
|
||||
Me.Add(licenseStringArray(i, 0), licenseStringArray(i, 1), licenseStringArray(i, 2), anzprof)
|
||||
Next
|
||||
End If
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' Fügt der Lizenz-Sammlung eine Lizenz hinzu
|
||||
''' </summary>
|
||||
''' <param name="modulename">Name des Moduls, für das eine Lizenz angelegt werden soll</param>
|
||||
''' <param name="expires">Datum der Gültigkeit der Lizenz</param>
|
||||
Public Sub Add(ByVal modulename As String, ByVal expires As Date, ByVal type As String, ByVal anzprof As String)
|
||||
|
||||
If _licenses IsNot Nothing Then
|
||||
ReDim Preserve _licenses(_licenses.Length)
|
||||
Else
|
||||
ReDim Preserve _licenses(0)
|
||||
End If
|
||||
|
||||
_licenses(_licenses.Length - 1) = New LicenseLegacy(modulename, expires, type, anzprof)
|
||||
End Sub
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' Liefert eine Lizenz an Hand des Modulnamens
|
||||
''' </summary>
|
||||
''' <param name="modulename">Name des zu suchenden Moduls</param>
|
||||
''' <returns>liefert ein Lizenzobjekt</returns>
|
||||
Public Function GetLicense(ByVal modulename As String) As LicenseLegacy
|
||||
If _licenses IsNot Nothing Then
|
||||
For Each license As LicenseLegacy In _licenses
|
||||
If license.Modulename = modulename Then
|
||||
Return license
|
||||
End If
|
||||
Next
|
||||
End If
|
||||
|
||||
Return Nothing
|
||||
End Function
|
||||
|
||||
' ++++++++++++++++++++++++++++++++++++++++++++++ Properties ++++++++++++++++++++++++++++++++++++++++++++++
|
||||
|
||||
''' <summary>
|
||||
''' liefert eine Sammlung von Lizenzobjekten
|
||||
''' </summary>
|
||||
Public ReadOnly Property Licenses() As LicenseLegacy()
|
||||
Get
|
||||
Return _licenses
|
||||
End Get
|
||||
End Property
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' liefert eine Lizenz an Hand des Modulnamens
|
||||
''' </summary>
|
||||
''' <param name="modulename">Name des zu suchenden Moduls</param>
|
||||
Public ReadOnly Property License(ByVal modulename As String) As LicenseLegacy
|
||||
Get
|
||||
Return GetLicense(modulename)
|
||||
End Get
|
||||
End Property
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' Liefert oder setzt den Firmennamen des Lizenzeigentümers
|
||||
''' </summary>
|
||||
Public Property Company() As String
|
||||
Public Property machine() As String
|
||||
End Class
|
||||
Loading…
x
Reference in New Issue
Block a user