Mit dieser Klasse kann man die Gültgkeit und Echtheit eines Personalausweises berechnen. Es ist außerdem möglich eine Personalausweis ID zu generieren mit eigener Behördenkennzahl, Geburtsdatum und Ablaufdatum.
Public Class IdentityCard
''' <summary>
''' Information über den Aufbau eines deutschen Personalausweises:
''' 123412345XD--123456X-123456X-------X
''' | | || | | | | |_Prüfsumme von allen Ziffern (1 Ziffer)
''' | | || | | | |_________Prüfsumme des Ablaufdatums (1 Ziffer)
''' | | || | | |_______________Das Ablaufdatum des Ausweises im Format YYMMDD (6 Ziffern)
''' | | || | |_________________Prüfsumme des Geburtsdatums (1 Ziffer)
''' | | || |_______________________Eigenes Geburtsdatum im Format YYMMDD (6 Ziffern)
''' | | ||__________________________Nationalität (D für Deutschland)
''' | | |___________________________Prüfsumme der ersten 9 Ziffern (1 Ziffer)
''' | |________________________________Die fortlaufende Nummer der Behördenkennzahl (5 Ziffern)
''' |____________________________________Die Behördenkennzahl (4 Ziffern)
''' </summary>
Public Class Germany
Private mGovernmentClassification(3) As Integer
Private mCountNumber(4) As Integer
Private mBirthDate(5) As Integer
Private mExpirationDate(5) As Integer
Private ValidData As Integer = 0
Public Enum EnumPersonData
FirstResidenceCFC = 1
CountNumber = 2
BirthDate = 4
ExpirationDate = 8
End Enum
''' <summary>
''' Die Behördenkennzahl (Die ersten 4 Ziffern)
''' </summary>
Public WriteOnly Property GovernmentClassification() As String
Set(ByVal value As String)
ValidData = ValidData And Not CInt(EnumPersonData.FirstResidenceCFC)
If value.Length <> 4 Then Throw New ArgumentException("INVALID DATALENGTH. MUST BE 4")
For i As Integer = 0 To 3
mGovernmentClassification(i) = Int32.Parse(value(i).ToString)
Next
ValidData = ValidData Or CInt(EnumPersonData.FirstResidenceCFC)
End Set
End Property
''' <summary>
''' Die fortlaufende Nummer der Behördenkennzahl (Die nächsten 5 Ziffern nach der Behördenkennzahl)
''' </summary>
Public WriteOnly Property CountNumber() As String
Set(ByVal value As String)
ValidData = ValidData And Not CInt(EnumPersonData.CountNumber)
If value.Length <> 5 Then Throw New ArgumentException("INVALID DATALENGTH. MUST BE 5")
For i As Integer = 0 To 4
mCountNumber(i) = Int32.Parse(value(i).ToString)
Next
ValidData = ValidData Or CInt(EnumPersonData.CountNumber)
End Set
End Property
''' <summary>
''' Das eigene Geburtsdatum (Die ersten 6 Ziffern des zweiten Ziffernblocks im Format JJMMDD)
''' </summary>
Public WriteOnly Property BirthDate() As String
Set(ByVal value As String)
ValidData = ValidData And Not CInt(EnumPersonData.BirthDate)
If value.Length <> 6 Then Throw New ArgumentException("INVALID DATALENGTH. MUST BE 6")
For i As Integer = 0 To 5
mBirthDate(i) = Int32.Parse(value(i).ToString)
Next
ValidData = ValidData Or CInt(EnumPersonData.BirthDate)
End Set
End Property
''' <summary>
''' Das Ablaufdatum des Ausweises (Die ersten 6 Ziffern des dritten Ziffernblocks im Format JJMMDD)
''' </summary>
Public WriteOnly Property ExpirationDate() As String
Set(ByVal value As String)
ValidData = ValidData And Not CInt(EnumPersonData.ExpirationDate)
If value.Length <> 6 Then Throw New ArgumentException("INVALID DATALENGTH. MUST BE 6")
For i As Integer = 0 To 5
mExpirationDate(i) = Int32.Parse(value(i).ToString)
Next
ValidData = ValidData Or CInt(EnumPersonData.ExpirationDate)
End Set
End Property
''' <summary>
''' Diese Funktion prüft ob die angegebene Daten alle richtig sind.
''' </summary>
Public Function IsDataValid() As Boolean
Dim nValidIf As Integer = CInt(EnumPersonData.FirstResidenceCFC) Or _
CInt(EnumPersonData.CountNumber) Or _
CInt(EnumPersonData.BirthDate) Or _
CInt(EnumPersonData.ExpirationDate)
Return (nValidIf = ValidData)
End Function
Private Function HashData() As IDHASH
If Not IsDataValid() Then Return Nothing
Dim HashA, HashB, HashC, HashD As Integer
HashA = _
(mGovernmentClassification(0) * 7) + _
(mGovernmentClassification(1) * 3) + _
(mGovernmentClassification(2) * 1) + _
(mGovernmentClassification(3) * 7) + _
(mCountNumber(0) * 3) + _
(mCountNumber(1) * 1) + _
(mCountNumber(2) * 7) + _
(mCountNumber(3) * 3) + _
(mCountNumber(4) * 1)
HashB = _
(mBirthDate(0) * 7) + _
(mBirthDate(1) * 3) + _
(mBirthDate(2) * 1) + _
(mBirthDate(3) * 7) + _
(mBirthDate(4) * 3) + _
(mBirthDate(5) * 1)
HashC = _
(mExpirationDate(0) * 7) + _
(mExpirationDate(1) * 3) + _
(mExpirationDate(2) * 1) + _
(mExpirationDate(3) * 7) + _
(mExpirationDate(4) * 3) + _
(mExpirationDate(5) * 1)
HashD = _
(mGovernmentClassification(0) * 7) + _
(mGovernmentClassification(1) * 3) + _
(mGovernmentClassification(2) * 1) + _
(mGovernmentClassification(3) * 7) + _
(mCountNumber(0) * 3) + _
(mCountNumber(1) * 1) + _
(mCountNumber(2) * 7) + _
(mCountNumber(3) * 3) + _
(mCountNumber(4) * 1) + _
(HashA * 7) + _
(mBirthDate(0) * 3) + _
(mBirthDate(1) * 1) + _
(mBirthDate(2) * 7) + _
(mBirthDate(3) * 3) + _
(mBirthDate(4) * 1) + _
(mBirthDate(5) * 7) + _
(HashB * 3) + _
(mExpirationDate(0) * 1) + _
(mExpirationDate(1) * 7) + _
(mExpirationDate(2) * 3) + _
(mExpirationDate(3) * 1) + _
(mExpirationDate(4) * 7) + _
(mExpirationDate(5) * 3) + _
(HashC * 1)
Return New IDHASH(HashA Mod 10, HashB Mod 10, HashC Mod 10, HashD Mod 10)
End Function
''' <summary>
''' Diese Funktion erstellt eine gültige Personalausweis ID
''' </summary>
''' <param name="nGovernmentClassification">4-Stellige Behördenkennzahl (kann irgendeine Nummer sein oder eine aus den offiziellen Listen zu findem im Internet).</param>
''' <param name="nCountNumber">5-Stellige fortlaufende Nummer der Behördenkennzahl (kann irgendeine Nummer sein).</param>
''' <param name="nBirthDate">Geburtsdatum</param>
''' <param name="nExpirationDate">Ablaufdatum</param>
Public Function CreateFullID(ByVal nGovernmentClassification As String, ByVal nCountNumber As String, ByVal nBirthDate As Date, ByVal nExpirationDate As Date) As FULLID
Dim TmpBirthDate As String = nBirthDate.Year.ToString.Substring(2, 2) & Format(nBirthDate.Month, "0#") & Format(nBirthDate.Day, "0#")
Dim TmpExpDate As String = nExpirationDate.Year.ToString.Substring(2, 2) & Format(nExpirationDate.Month, "0#") & Format(nExpirationDate.Day, "0#")
GovernmentClassification = nGovernmentClassification
CountNumber = nCountNumber
BirthDate = TmpBirthDate
ExpirationDate = TmpExpDate
Dim HashValues As IDHASH = HashData()
Dim NewFullID As FULLID
NewFullID.GovernmentClassification = nGovernmentClassification
NewFullID.CountNumber = nCountNumber
NewFullID.BirthDate = TmpBirthDate
NewFullID.ExpirationDate = TmpExpDate
NewFullID.HashValues = HashValues
Return NewFullID
End Function
Public Structure FULLID
Public GovernmentClassification As String
Public CountNumber As String
Public BirthDate As String
Public ExpirationDate As String
Public HashValues As IDHASH
Public Overrides Function ToString() As String
Return GovernmentClassification & CountNumber & HashValues.HashA.ToString & "D<<" & BirthDate & HashValues.HashB.ToString & "<" & ExpirationDate & HashValues.HashC.ToString & "<<<<<<" & HashValues.HashD.ToString
End Function
End Structure
Public Structure IDHASH
Public HashA As Integer
Public HashB As Integer
Public HashC As Integer
Public HashD As Integer
Sub New(ByVal A As Integer, ByVal B As Integer, ByVal C As Integer, ByVal D As Integer)
HashA = A
HashB = B
HashC = C
HashD = D
End Sub
End Structure
End Class
End Class
1 Kommentare zum Snippet