⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rijndael.cls

📁 It use both RSA and AES for encry/decryption with fingerprint as Key.
💻 CLS
📖 第 1 页 / 共 5 页
字号:
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "cRijndael"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit

#Const COMPILE_CONSTANTS = 0 'Default=0
'COMPILE_CONSTANTS = 0 [Fast compile, small exe size]  Calculate tables during Class initialization
'COMPILE_CONSTANTS = 1 [Fast run time initialization]  Compile tables of constants

'These are arrays of constants.  They are initialized with the Class and do not change.
Private Te0(255)      As Long
Private Te1(255)      As Long
Private Te2(255)      As Long
Private Te3(255)      As Long
Private Te4(255)      As Long

Private Td0(255)      As Long
Private Td1(255)      As Long
Private Td2(255)      As Long
Private Td3(255)      As Long
Private Td4(255)      As Long

Private rco(9)        As Long

'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 = 4
        CopyMemory fkey(0), pass(0), 4& * i
        For j = 0 To 9
            CopyMemory s(0), fkey(i - 1), 4&
            fkey(i) = fkey(i - 4) 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 - 3) Xor fkey(i)
            fkey(i + 2) = fkey(i - 2) Xor fkey(i + 1)
            fkey(i + 3) = fkey(i - 1) Xor fkey(i + 2)
            i = i + 4
        Next j
        Nr = 10
    
    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

'Decrypt a 128 bit block.  ciphertext(q ... q+15) is input, plaintext(p ... p+15) is output.
'plaintext and ciphertext can be the same array.  Will crash if plaintext(p ... p+15) is not allocated.
Public Sub BlockDecrypt(plaintext() As Byte, ciphertext() As Byte, p As Long, q As Long)
    Dim i     As Long
    Dim k     As Long
    Dim t0    As Long
    Dim t1    As Long
    Dim t2    As Long
    Dim t3    As Long
    Dim s(15) As Byte

    CopyMemory t0, ciphertext(q + 0), 4&
    CopyMemory t1, ciphertext(q + 4), 4&
    CopyMemory t2, ciphertext(q + 8), 4&
    CopyMemory t3, ciphertext(q + 12), 4&

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -