vb@rchiv
VB Classic
VB.NET
ADO.NET
VBA
C#
sevAniGif - als kostenlose Vollversion auf unserer vb@rchiv CD Vol.5  
 vb@rchiv Quick-Search: Suche startenErweiterte Suche starten   Impressum  | Datenschutz  | vb@rchiv CD Vol.6  | Shop Copyright ©2000-2024
 
zurück

 Sie sind aktuell nicht angemeldet.Funktionen: Einloggen  |  Neu registrieren  |  Suchen

Fortgeschrittene Programmierung
Re: AES-256 Verschlüsselung 
Autor: Tomy41
Datum: 26.02.17 17:32

Hier ein Paar Zeilen Code:

'Key schedule arrays
Private Nr            As Long 'Number of rounds [For 128 bit block, Nr = {10, 
' 12, 14} for 128, 192, 256 bit cipher key]
Private fkey(59)      As Long 'Nb*(Nr + 1)
Private rkey(59)      As Long 'Nb*(Nr + 1)
 
'For file encryption, this is the maximum amount of memory (in bytes) allowed 
' for file data
Private Const MaxFileChunkSize As Long = 4000000
 
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" ( _
  Destination As Any, Source As Any, ByVal Length As Long)
 
'Decryption Key Scheduler.  Calculate rkey() decryption keys based on fkey() 
' and Nr.
'Nb is the number of 32 bit units in the block size.
Private Sub CreateDecryptionKeys(Nb As Long)
    Dim i    As Long
    Dim j    As Long
    Dim k    As Long
    Dim s(3) As Byte
 
    'Invert the order of the round keys
    i = 0
    j = Nb * Nr
    For k = 0 To Nr
        CopyMemory rkey(i), fkey(j), Nb * 4&
        i = i + Nb
        j = j - Nb
    Next k
 
    'Apply the inverse MixColumn transform to all round keys except the first 
    ' and the last
    For i = Nb To Nb * Nr - 1
        CopyMemory s(0), rkey(i), 4&
        rkey(i) = Td0(Te4(s(0)) And &HFF&) Xor _
                  Td1(Te4(s(1)) And &HFF&) Xor _
                  Td2(Te4(s(2)) And &HFF&) Xor _
                  Td3(Te4(s(3)) And &HFF&)
    Next i
End Sub
 
'Key Scheduler. Expand the cipher key into the encryption key schedule.
'pass(0 ... n-1) contains the cipher key, where n = {16, 20, 24, 28, 32} , 
' depending on KeyBits.
'If SUPPORT_LEVEL is non-zero, you must specify BlockBits for the block size 
' you will be using.
'Returns zero on success.
Public Function SetCipherKey(pass() As Byte, KeyBits As Long) As Long
    Dim i    As Long
    Dim j    As Long
    Dim s(3) As Byte
 
[...]
        i = 8
        j = 0
        CopyMemory fkey(0), pass(0), 4& * i
        Do
            CopyMemory s(0), fkey(i - 1), 4&
            fkey(i) = fkey(i - 8) Xor (Te4(s(0)) And &HFF000000) _
                                  Xor (Te4(s(3)) And &HFF0000) _
                                  Xor (Te4(s(2)) And &HFF00&) _
                                  Xor (Te4(s(1)) And &HFF&) _
                                  Xor rco(j)
            fkey(i + 1) = fkey(i - 7) Xor fkey(i)
            fkey(i + 2) = fkey(i - 6) Xor fkey(i + 1)
            fkey(i + 3) = fkey(i - 5) Xor fkey(i + 2)
            If j = 6 Then Exit Do
            CopyMemory s(0), fkey(i + 3), 4&
            fkey(i + 4) = fkey(i - 4) Xor (Te4(s(3)) And &HFF000000) _
                                      Xor (Te4(s(2)) And &HFF0000) _
                                      Xor (Te4(s(1)) And &HFF00&) _
                                      Xor (Te4(s(0)) And &HFF&)
            fkey(i + 5) = fkey(i - 3) Xor fkey(i + 4)
            fkey(i + 6) = fkey(i - 2) Xor fkey(i + 5)
            fkey(i + 7) = fkey(i - 1) Xor fkey(i + 6)
            i = i + 8
            j = j + 1
        Loop
        Nr = 14
 
    CreateDecryptionKeys 4
 
End Function
 
Public Function SetCipherKeyString(PassPhrase As String, KeyBits As Long) As _
  Long
    Dim pass() As Byte
 
    pass = StrConv(PassPhrase, vbFromUnicode)
    ReDim Preserve pass(31)
    SetCipherKeyString = SetCipherKey(pass, KeyBits)
End Function

bis später
Tomy

alle Nachrichten anzeigenGesamtübersicht  |  Zum Thema  |  Suchen

 ThemaViews  AutorDatum
AES-256 Verschlüsselung1.611Tomy4126.02.17 12:27
Re: AES-256 Verschlüsselung789Tomy4126.02.17 17:32

Sie sind nicht angemeldet!
Um auf diesen Beitrag zu antworten oder neue Beiträge schreiben zu können, müssen Sie sich zunächst anmelden.

Einloggen  |  Neu registrieren

Funktionen:  Zum Thema  |  GesamtübersichtSuchen 

nach obenzurück
 
   

Copyright ©2000-2024 vb@rchiv Dieter Otter
Alle Rechte vorbehalten.
Microsoft, Windows und Visual Basic sind entweder eingetragene Marken oder Marken der Microsoft Corporation in den USA und/oder anderen Ländern. Weitere auf dieser Homepage aufgeführten Produkt- und Firmennamen können geschützte Marken ihrer jeweiligen Inhaber sein.

Diese Seiten wurden optimiert für eine Bildschirmauflösung von mind. 1280x1024 Pixel