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

📄 frmencfiles.frm

📁 程序加密算法
💻 FRM
📖 第 1 页 / 共 2 页
字号:
VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "Comdlg32.ocx"
Begin VB.Form frmEncFiles 
   BorderStyle     =   1  'Fixed Single
   ClientHeight    =   4800
   ClientLeft      =   1560
   ClientTop       =   1845
   ClientWidth     =   5565
   Icon            =   "frmEncFiles.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   4800
   ScaleWidth      =   5565
   Begin VB.Frame Frame1 
      Caption         =   "Cipher Algorithm"
      Height          =   540
      Left            =   150
      TabIndex        =   13
      Top             =   825
      Width           =   5265
      Begin VB.OptionButton optCipher 
         Caption         =   "RC4"
         Height          =   240
         Index           =   0
         Left            =   225
         TabIndex        =   18
         Top             =   225
         Value           =   -1  'True
         Width           =   765
      End
      Begin VB.OptionButton optCipher 
         Caption         =   "RC2"
         Height          =   240
         Index           =   1
         Left            =   1050
         TabIndex        =   17
         Top             =   225
         Width           =   765
      End
      Begin VB.OptionButton optCipher 
         Caption         =   "DES"
         Height          =   240
         Index           =   2
         Left            =   2025
         TabIndex        =   16
         Top             =   225
         Width           =   765
      End
      Begin VB.OptionButton optCipher 
         Caption         =   "3DES"
         Height          =   240
         Index           =   3
         Left            =   2925
         TabIndex        =   15
         Top             =   225
         Width           =   765
      End
      Begin VB.OptionButton optCipher 
         Caption         =   " 3DES-112"
         Height          =   240
         Index           =   4
         Left            =   3900
         TabIndex        =   14
         Top             =   225
         Width           =   1140
      End
   End
   Begin VB.TextBox txtData 
      Height          =   315
      Index           =   0
      Left            =   180
      TabIndex        =   0
      Top             =   1755
      Width           =   5235
   End
   Begin MSComDlg.CommonDialog CD 
      Left            =   4980
      Top             =   3075
      _ExtentX        =   847
      _ExtentY        =   847
      _Version        =   393216
   End
   Begin VB.TextBox txtData 
      BackColor       =   &H00FFFFC0&
      Height          =   315
      Index           =   3
      Left            =   180
      Locked          =   -1  'True
      TabIndex        =   11
      TabStop         =   0   'False
      Top             =   3795
      Width           =   4635
   End
   Begin VB.TextBox txtData 
      BackColor       =   &H00FFFFC0&
      Height          =   315
      Index           =   2
      Left            =   180
      Locked          =   -1  'True
      TabIndex        =   9
      TabStop         =   0   'False
      Top             =   3135
      Width           =   4635
   End
   Begin VB.CommandButton cmdChoice 
      Height          =   360
      Index           =   1
      Left            =   4980
      Picture         =   "frmEncFiles.frx":030A
      Style           =   1  'Graphical
      TabIndex        =   2
      Top             =   2475
      Width           =   435
   End
   Begin VB.TextBox txtData 
      Height          =   315
      Index           =   1
      Left            =   180
      TabIndex        =   1
      Top             =   2475
      Width           =   4635
   End
   Begin VB.CommandButton cmdChoice 
      Caption         =   "&Test"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Index           =   0
      Left            =   3360
      TabIndex        =   3
      Top             =   4275
      Width           =   975
   End
   Begin VB.CommandButton cmdChoice 
      Caption         =   "&Cancel"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Index           =   2
      Left            =   4440
      TabIndex        =   4
      Top             =   4275
      Width           =   975
   End
   Begin VB.Label Label1 
      BackStyle       =   0  'Transparent
      Caption         =   "Input a password / passphrase  (Default password used if left blank)"
      Height          =   195
      Index           =   1
      Left            =   240
      TabIndex        =   12
      Top             =   1515
      Width           =   5130
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      BackStyle       =   0  'Transparent
      Caption         =   "Name and location of decrypted file"
      Height          =   195
      Index           =   4
      Left            =   240
      TabIndex        =   10
      Top             =   3555
      Width           =   2505
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      BackStyle       =   0  'Transparent
      Caption         =   "Name and location of encrypted file"
      Height          =   195
      Index           =   3
      Left            =   240
      TabIndex        =   8
      Top             =   2895
      Width           =   2505
   End
   Begin VB.Label Label1 
      BackStyle       =   0  'Transparent
      Caption         =   "Enter full path\filename or browse for a file with the button on the right."
      Height          =   195
      Index           =   2
      Left            =   240
      TabIndex        =   7
      Top             =   2235
      Width           =   5010
   End
   Begin VB.Label lblMyLabel 
      BackStyle       =   0  'Transparent
      Height          =   420
      Left            =   180
      TabIndex        =   6
      Top             =   4275
      Width           =   2925
   End
   Begin VB.Label lblTitle 
      Alignment       =   2  'Center
      BackColor       =   &H00C00000&
      BorderStyle     =   1  'Fixed Single
      Caption         =   "Test File Encryption"
      BeginProperty Font 
         Name            =   "Times New Roman"
         Size            =   18
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   -1  'True
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00FFFFFF&
      Height          =   555
      Left            =   120
      TabIndex        =   5
      Top             =   120
      Width           =   5310
   End
End
Attribute VB_Name = "frmEncFiles"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
  
' ===========================================================================
'    DATE      NAME                      DESCRIPTION
' -----------  ------------------------  ------------------------------------
' 30-DEC-2000  Kenneth Ives              Written by kenaso@home.com
' ---------------------------------------------------------------------------
' Define module level constants
' ---------------------------------------------------------------------------
  Private m_intCipher       As Integer  ' Added 09-Sep-2001 KCI
  Private m_strFilename     As String
  Private m_strEncryptName  As String
  Private m_strDecryptName  As String
  Private arData()          As Byte     ' added 08-Jan-2001 KCI
  Private arPWord()         As Byte     ' added 08-Jan-2001 KCI

Private Sub Process_File()

' ***************************************************************************
' Routine:       Process_File
'
' Description:   First, test to see if the file exists and it is not empty.
'                Then encrypt and decrypt the file.
'
' ===========================================================================
'    DATE      NAME / eMAIL
'              DESCRIPTION
' -----------  --------------------------------------------------------------
' 08-JAN-2001  Kenneth Ives  kenaso@home.com
'              Converted data to byte array and then encrypt/decrypt the data.
'              Resolves the erroneous displays I sometimes encounter.  Thanks
'              to Haakan Gustavsson for pointing me in the right direction.
' 18-JAN-2001  Kenneth Ives  kenaso@home.com
'              The decoded file wwas be one byte larger than the source.  To
'              fix this, subtract 1 from the file size to accomodate the zero
'              based array.
'              Fix suggested by Harbinder Gill  hgill@altavista.net
' 21-JAN-2001  Kenneth Ives  kenaso@home.com
'              Found that when you use PUT to write a byte array to a
'              file, the last character is converted to a NULL.   To get
'              around this quirk, I converted the decrypted byte array to
'              a text string and then PUT it in the output file.
' ***************************************************************************

' ---------------------------------------------------------------------------
' Define local variables
' ---------------------------------------------------------------------------
  Dim lngFileSize  As Long
  Dim hFile        As Integer
  Dim strText      As String
  Dim cCrypto      As CryptKci.clsCryptoAPI
  
' ---------------------------------------------------------------------------
' Make sure that the file exists and is not empty.
' ---------------------------------------------------------------------------
  Set cCrypto = New CryptKci.clsCryptoAPI
  On Error Resume Next
  
  lngFileSize = FileLen(m_strFilename)
  
  If Err <> 0 Or lngFileSize = 0 Then
      MsgBox "Cannot locate: " & vbCrLf & _
             m_strFilename & vbCrLf & "or this is an empty file.", _
             vbOKOnly, "File not found"
      Clear_Variables
      Exit Sub
  End If
  On Error GoTo 0     ' nullify the previous "On Error"
              
  On Error GoTo Process_File_Errors
' ---------------------------------------------------------------------------
' resize the data array to accommodate the file contents
'
' For encrypting, leave one extra element in the array to handle the last
' NULL appended to the excrypted file
' ---------------------------------------------------------------------------
  ReDim arData(lngFileSize)
              
' ---------------------------------------------------------------------------
' Create empty receiving files
' ---------------------------------------------------------------------------
  hFile = FreeFile  ' get first free file handle
  Open m_strEncryptName For Output As #hFile
  Close #hFile
                  
  Open m_strDecryptName For Output As #hFile
  Close #hFile
                             
' ---------------------------------------------------------------------------
' load the byte array with the file contents from the input file using one
' command then close file.
' ---------------------------------------------------------------------------
  Open m_strFilename For Binary Access Read As #hFile
  Get hFile, , arData
  Close #hFile

' ---------------------------------------------------------------------------
' See if there is a password
' ---------------------------------------------------------------------------
  If Len(Trim$(txtData(0).Text)) = 0 Then
      ReDim arPWord(0)
  Else
      arPWord = cCrypto.StringToByteArray(txtData(0).Text)
      cCrypto.Password = arPWord()
  End If
              
' ---------------------------------------------------------------------------
' set up parameters prior to encryption
' ---------------------------------------------------------------------------
  cCrypto.InputData = arData()
  cCrypto.EnhancedProvider = g_blnEnhancedProvider
  
' ---------------------------------------------------------------------------
' Encrypt the data and return in a byte array
' ---------------------------------------------------------------------------
  If cCrypto.Encrypt(g_intHashType, m_intCipher) Then
      arData = cCrypto.OutputData
  Else
      GoTo CleanUp
  End If
  

⌨️ 快捷键说明

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