📄 tripledescryptoserviceprovider.cls
字号:
''
' Returns a psuedo-unique number used to help identify this
' object in memory. The current method is to return the value
' obtained from ObjPtr. If a different method needs to be impelmented
' then change the method here in this function.
'
' @return Returns a number identifing this instance.
'
Public Function GetHashCode() As Long
GetHashCode = ObjPtr(CUnk(Me))
End Function
''
' Returns a string representation of this object instance.
' The default method simply returns the application name
' and class name in which this class resides.
'
' @return Returns a string representation of this instance.
'
Public Function ToString() As String
ToString = Object.ToString(Me, App)
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Private Helpers
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Function CreateCipher(ByRef RgbKey As Variant, ByRef RgbIV As Variant, ByVal IsEncrypting As Boolean) As CryptoAPITransform
If IsMissing(RgbKey) <> IsMissing(RgbIV) Then _
Throw Cor.NewArgumentException("Argument is missing.", IIf(IsMissing(RgbKey), "RgbKey", "RgbIV"))
Dim Alg As Long
If mBase.KeySize = 128 Then
Alg = CALG_3DES_112
Else
Alg = CALG_3DES
End If
Set CreateCipher = New CryptoAPITransform
Call CreateCipher.Init(Alg, mBase.CloneRgbKey(RgbKey), mBase.CloneRgbIV(RgbIV), mBase, IsEncrypting)
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Class Events
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Sub Class_Initialize()
Set mBase = New SymmetricAlgorithmBase
With mBase
Call .AddLegalBlockSize(DEF_MINBLOCKSIZE, DEF_MAXBLOCKSIZE, DEF_BLOCKSKIPSIZE)
Call .AddLegalKeySize(DEF_MINKEYSIZE, DEF_MAXKEYSIZE, DEF_KEYSKIPSIZE)
.BlockSize = DEF_BLOCKSIZE
.KeySize = DEF_KEYSIZE
.FeedbackSize = DEF_FEEDBACKSIZE
.Mode = CipherMode.CBC
.Padding = PaddingMode.PKCS7
End With
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' IObject Interface
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Function IObject_Equals(Value As Variant) As Boolean
IObject_Equals = Equals(Value)
End Function
Private Function IObject_GetHashcode() As Long
IObject_GetHashcode = GetHashCode
End Function
Private Function IObject_ToString() As String
IObject_ToString = ToString
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' mBase Events
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Sub mBase_CheckForWeakKey(RgbKey() As Byte, Ex As Exception)
If modStaticClasses.TripleDES.IsWeakKey(RgbKey) Then
Set Ex = Cor.NewCryptographicException("Key cannot be weak.")
End If
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' SymmetricAlgorithm Interface
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Property Let SymmetricAlgorithm_BlockSize(ByVal RHS As Long)
BlockSize = RHS
End Property
Private Property Get SymmetricAlgorithm_BlockSize() As Long
SymmetricAlgorithm_BlockSize = BlockSize
End Property
Private Sub SymmetricAlgorithm_Clear()
Call Clear
End Sub
Private Function SymmetricAlgorithm_CreateDecryptor(Optional RgbKey As Variant, Optional RgbIV As Variant) As ICryptoTransform
Set SymmetricAlgorithm_CreateDecryptor = CreateDecryptor(RgbKey, RgbIV)
End Function
Private Function SymmetricAlgorithm_CreateEncryptor(Optional RgbKey As Variant, Optional RgbIV As Variant) As ICryptoTransform
Set SymmetricAlgorithm_CreateEncryptor = CreateEncryptor(RgbKey, RgbIV)
End Function
Private Function SymmetricAlgorithm_Equals(Value As Variant) As Boolean
SymmetricAlgorithm_Equals = Equals(Value)
End Function
Private Property Let SymmetricAlgorithm_FeedbackSize(ByVal RHS As Long)
FeedbackSize = RHS
End Property
Private Property Get SymmetricAlgorithm_FeedbackSize() As Long
SymmetricAlgorithm_FeedbackSize = FeedbackSize
End Property
Private Sub SymmetricAlgorithm_GenerateIV()
Call GenerateIV
End Sub
Private Sub SymmetricAlgorithm_GenerateKey()
Call GenerateKey
End Sub
Private Function SymmetricAlgorithm_GetHashCode() As Long
SymmetricAlgorithm_GetHashCode = GetHashCode
End Function
Private Property Let SymmetricAlgorithm_IV(RHS() As Byte)
Call mBase.SetIV(RHS)
End Property
Private Property Get SymmetricAlgorithm_IV() As Byte()
SymmetricAlgorithm_IV = IV
End Property
Private Property Let SymmetricAlgorithm_Key(RHS() As Byte)
Call mBase.SetKey(RHS)
End Property
Private Property Get SymmetricAlgorithm_Key() As Byte()
SymmetricAlgorithm_Key = Key
End Property
Private Property Let SymmetricAlgorithm_KeySize(ByVal RHS As Long)
KeySize = RHS
End Property
Private Property Get SymmetricAlgorithm_KeySize() As Long
SymmetricAlgorithm_KeySize = KeySize
End Property
Private Property Get SymmetricAlgorithm_LegalBlockSizes() As KeySizes()
SymmetricAlgorithm_LegalBlockSizes = LegalBlockSizes
End Property
Private Property Get SymmetricAlgorithm_LegalKeySizes() As KeySizes()
SymmetricAlgorithm_LegalKeySizes = LegalKeySizes
End Property
Private Property Let SymmetricAlgorithm_Mode(ByVal RHS As CipherMode)
Mode = RHS
End Property
Private Property Get SymmetricAlgorithm_Mode() As CipherMode
SymmetricAlgorithm_Mode = Mode
End Property
Private Property Let SymmetricAlgorithm_Padding(ByVal RHS As PaddingMode)
Padding = RHS
End Property
Private Property Get SymmetricAlgorithm_Padding() As PaddingMode
SymmetricAlgorithm_Padding = Padding
End Property
Private Function SymmetricAlgorithm_ToString() As String
SymmetricAlgorithm_ToString = ToString
End Function
Private Function SymmetricAlgorithm_ValidKeySize(ByVal BitLength As Long) As Boolean
SymmetricAlgorithm_ValidKeySize = ValidKeySize(BitLength)
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' TripleDES Interface
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Property Let TripleDES_BlockSize(ByVal RHS As Long)
BlockSize = RHS
End Property
Private Property Get TripleDES_BlockSize() As Long
TripleDES_BlockSize = BlockSize
End Property
Private Sub TripleDES_Clear()
Call Clear
End Sub
Private Function TripleDES_CreateDecryptor(Optional RgbKey As Variant, Optional RgbIV As Variant) As ICryptoTransform
Set TripleDES_CreateDecryptor = CreateDecryptor(RgbKey, RgbIV)
End Function
Private Function TripleDES_CreateEncryptor(Optional RgbKey As Variant, Optional RgbIV As Variant) As ICryptoTransform
Set TripleDES_CreateEncryptor = CreateEncryptor(RgbKey, RgbIV)
End Function
Private Function TripleDES_Equals(Value As Variant) As Boolean
TripleDES_Equals = Equals(Value)
End Function
Private Property Let TripleDES_FeedbackSize(ByVal RHS As Long)
FeedbackSize = RHS
End Property
Private Property Get TripleDES_FeedbackSize() As Long
TripleDES_FeedbackSize = FeedbackSize
End Property
Private Sub TripleDES_GenerateIV()
Call GenerateIV
End Sub
Private Sub TripleDES_GenerateKey()
Call GenerateKey
End Sub
Private Function TripleDES_GetHashCode() As Long
TripleDES_GetHashCode = GetHashCode
End Function
Private Property Let TripleDES_IV(RHS() As Byte)
Call mBase.SetIV(RHS)
End Property
Private Property Get TripleDES_IV() As Byte()
TripleDES_IV = IV
End Property
Private Property Let TripleDES_Key(RHS() As Byte)
Call mBase.SetKey(RHS)
End Property
Private Property Get TripleDES_Key() As Byte()
TripleDES_Key = Key
End Property
Private Property Let TripleDES_KeySize(ByVal RHS As Long)
KeySize = RHS
End Property
Private Property Get TripleDES_KeySize() As Long
TripleDES_KeySize = KeySize
End Property
Private Property Get TripleDES_LegalBlockSizes() As KeySizes()
TripleDES_LegalBlockSizes = LegalBlockSizes
End Property
Private Property Get TripleDES_LegalKeySizes() As KeySizes()
TripleDES_LegalKeySizes = LegalKeySizes
End Property
Private Property Let TripleDES_Mode(ByVal RHS As CipherMode)
Mode = RHS
End Property
Private Property Get TripleDES_Mode() As CipherMode
TripleDES_Mode = Mode
End Property
Private Property Let TripleDES_Padding(ByVal RHS As PaddingMode)
Padding = RHS
End Property
Private Property Get TripleDES_Padding() As PaddingMode
TripleDES_Padding = Padding
End Property
Private Function TripleDES_ToString() As String
TripleDES_ToString = ToString
End Function
Private Function TripleDES_ValidKeySize(ByVal BitLength As Long) As Boolean
TripleDES_ValidKeySize = ValidKeySize(BitLength)
End Function
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -