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

📄 descryptoserviceprovider.cls

📁 这是一个在vb下实现的各种加密程序,可以实现一般的文本加密和文件加密,但是很多算法都是已经被人破解过的.
💻 CLS
📖 第 1 页 / 共 2 页
字号:
' 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"))
    
    Set CreateCipher = New CryptoAPITransform
    Call CreateCipher.Init(CALG_DES, 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


'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'   DES Interface
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Property Let DES_BlockSize(ByVal RHS As Long)
    BlockSize = RHS
End Property

Private Property Get DES_BlockSize() As Long
    DES_BlockSize = BlockSize
End Property

Private Sub DES_Clear()
    Call Clear
End Sub

Private Function DES_CreateDecryptor(Optional ByRef RgbKey As Variant, Optional ByRef RgbIV As Variant) As ICryptoTransform
    Set DES_CreateDecryptor = CreateDecryptor(RgbKey, RgbIV)
End Function

Private Function DES_CreateEncryptor(Optional ByRef RgbKey As Variant, Optional ByRef RgbIV As Variant) As ICryptoTransform
    Set DES_CreateEncryptor = CreateEncryptor(RgbKey, RgbIV)
End Function

Private Function DES_Equals(Value As Variant) As Boolean
    DES_Equals = Equals(Value)
End Function

Private Property Let DES_FeedbackSize(ByVal RHS As Long)
    FeedbackSize = RHS
End Property

Private Property Get DES_FeedbackSize() As Long
    DES_FeedbackSize = FeedbackSize
End Property

Private Sub DES_GenerateIV()
    Call GenerateIV
End Sub

Private Sub DES_GenerateKey()
    Call GenerateKey
End Sub

Private Function DES_GetHashCode() As Long
    DES_GetHashCode = GetHashCode
End Function

Private Property Let DES_IV(RHS() As Byte)
    Call mBase.SetIV(RHS)
End Property

Private Property Get DES_IV() As Byte()
    DES_IV = IV
End Property

Private Property Let DES_Key(RHS() As Byte)
    Call mBase.SetKey(RHS)
End Property

Private Property Get DES_Key() As Byte()
    DES_Key = Key
End Property

Private Property Let DES_KeySize(ByVal RHS As Long)
    KeySize = RHS
End Property

Private Property Get DES_KeySize() As Long
    DES_KeySize = KeySize
End Property

Private Property Get DES_LegalBlockSizes() As KeySizes()
    DES_LegalBlockSizes = LegalBlockSizes
End Property

Private Property Get DES_LegalKeySizes() As KeySizes()
    DES_LegalKeySizes = LegalKeySizes
End Property

Private Property Let DES_Mode(ByVal RHS As CipherMode)
    Mode = RHS
End Property

Private Property Get DES_Mode() As CipherMode
    DES_Mode = Mode
End Property

Private Property Let DES_Padding(ByVal RHS As PaddingMode)
    Padding = RHS
End Property

Private Property Get DES_Padding() As PaddingMode
    DES_Padding = Padding
End Property

Private Function DES_ToString() As String
    DES_ToString = ToString
End Function

Private Function DES_ValidKeySize(ByVal BitLength As Long) As Boolean
    DES_ValidKeySize = ValidKeySize(BitLength)
End Function


'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'   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)
    With modStaticClasses.DES
        If .IsWeakKey(RgbKey) Then
            Set Ex = Cor.NewCryptographicException("Key cannot be weak.")
        ElseIf .IsSemiWeakKey(RgbKey) Then
            Set Ex = Cor.NewCryptographicException("Key cannot be semi-weak.")
        End If
    End With
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 ByRef RgbKey As Variant, Optional ByRef RgbIV As Variant) As ICryptoTransform
    Set SymmetricAlgorithm_CreateDecryptor = CreateDecryptor(RgbKey, RgbIV)
End Function

Private Function SymmetricAlgorithm_CreateEncryptor(Optional ByRef RgbKey As Variant, Optional ByRef 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

⌨️ 快捷键说明

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