home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 September / Chip_2002-09_cd1.bin / zkuste / vbasic / Data / Utils / XZipComp.exe / XceedEncryption.Cab / F112955_Manager.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  2001-06-06  |  26.0 KB  |  593 lines

  1. VERSION 5.00
  2. Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
  3. Begin VB.Form frmManager 
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "Encrypt / Decrypt manager"
  6.    ClientHeight    =   4380
  7.    ClientLeft      =   150
  8.    ClientTop       =   720
  9.    ClientWidth     =   8280
  10.    LinkTopic       =   "Form1"
  11.    MaxButton       =   0   'False
  12.    OLEDropMode     =   1  'Manual
  13.    ScaleHeight     =   4380
  14.    ScaleWidth      =   8280
  15.    StartUpPosition =   3  'Windows Default
  16.    Begin VB.TextBox txtPassPhrase 
  17.       Height          =   285
  18.       IMEMode         =   3  'DISABLE
  19.       Left            =   1425
  20.       OLEDropMode     =   1  'Manual
  21.       TabIndex        =   0
  22.       Top             =   300
  23.       Width           =   6390
  24.    End
  25.    Begin VB.Frame Frame1 
  26.       Height          =   90
  27.       Left            =   -225
  28.       TabIndex        =   12
  29.       Top             =   0
  30.       Width           =   9090
  31.    End
  32.    Begin VB.CommandButton cmdDecrypt 
  33.       Caption         =   "Decrypt"
  34.       Height          =   375
  35.       Left            =   6900
  36.       TabIndex        =   6
  37.       Top             =   1575
  38.       Width           =   1290
  39.    End
  40.    Begin VB.CommandButton cmdSelectSourceFile 
  41.       Caption         =   "..."
  42.       Height          =   285
  43.       Left            =   7875
  44.       TabIndex        =   2
  45.       Top             =   675
  46.       Width           =   285
  47.    End
  48.    Begin VB.CommandButton cmdEncrypt 
  49.       Caption         =   "Encrypt"
  50.       Height          =   375
  51.       Left            =   5550
  52.       TabIndex        =   5
  53.       Top             =   1575
  54.       Width           =   1290
  55.    End
  56.    Begin VB.TextBox txtSourceFile 
  57.       Height          =   285
  58.       Left            =   1425
  59.       OLEDropMode     =   1  'Manual
  60.       TabIndex        =   1
  61.       Top             =   675
  62.       Width           =   6390
  63.    End
  64.    Begin VB.TextBox txtDestinationFile 
  65.       Height          =   285
  66.       Left            =   1425
  67.       OLEDropMode     =   2  'Automatic
  68.       TabIndex        =   3
  69.       Top             =   1050
  70.       Width           =   6390
  71.    End
  72.    Begin VB.CommandButton cmdSelectDestinationFile 
  73.       Caption         =   "..."
  74.       Height          =   285
  75.       Left            =   7875
  76.       TabIndex        =   4
  77.       Top             =   1050
  78.       Width           =   285
  79.    End
  80.    Begin MSComDlg.CommonDialog dlgCommon 
  81.       Left            =   75
  82.       Top             =   1425
  83.       _ExtentX        =   847
  84.       _ExtentY        =   847
  85.       _Version        =   393216
  86.    End
  87.    Begin VB.Frame Frame3 
  88.       Height          =   90
  89.       Left            =   -75
  90.       TabIndex        =   9
  91.       Top             =   2175
  92.       Width           =   8415
  93.    End
  94.    Begin VB.TextBox txtMessage 
  95.       Height          =   1665
  96.       Left            =   75
  97.       Locked          =   -1  'True
  98.       MultiLine       =   -1  'True
  99.       ScrollBars      =   2  'Vertical
  100.       TabIndex        =   7
  101.       Top             =   2625
  102.       Width           =   8115
  103.    End
  104.    Begin VB.Label lbl 
  105.       Caption         =   "Pass phrase"
  106.       Height          =   240
  107.       Index           =   0
  108.       Left            =   75
  109.       TabIndex        =   13
  110.       Top             =   300
  111.       Width           =   915
  112.    End
  113.    Begin VB.Label lbl 
  114.       Caption         =   "Source file"
  115.       Height          =   240
  116.       Index           =   2
  117.       Left            =   75
  118.       TabIndex        =   11
  119.       Top             =   675
  120.       Width           =   915
  121.    End
  122.    Begin VB.Label lbl 
  123.       Caption         =   "Destination file"
  124.       Height          =   240
  125.       Index           =   3
  126.       Left            =   75
  127.       TabIndex        =   10
  128.       Top             =   1050
  129.       Width           =   1215
  130.    End
  131.    Begin VB.Label lbl 
  132.       Caption         =   "Error / Warning message"
  133.       Height          =   240
  134.       Index           =   4
  135.       Left            =   75
  136.       TabIndex        =   8
  137.       Top             =   2400
  138.       Width           =   2565
  139.    End
  140.    Begin VB.Menu mnuFile 
  141.       Caption         =   "File"
  142.       Begin VB.Menu mnuQuit 
  143.          Caption         =   "Quit"
  144.       End
  145.    End
  146.    Begin VB.Menu mnuOption 
  147.       Caption         =   "Options"
  148.    End
  149. Attribute VB_Name = "frmManager"
  150. Attribute VB_GlobalNameSpace = False
  151. Attribute VB_Creatable = False
  152. Attribute VB_PredeclaredId = True
  153. Attribute VB_Exposed = False
  154. ' Xceed Encryption Library - Encryption Manager sample
  155. ' Copyright (c) 2001 Xceed Software Inc.
  156. ' [Manager.frm]
  157. ' This form module contains the main form's code. It demonstrates how to
  158. ' encrypt a file using different kinds of encryption methods, and decrypt an
  159. ' encryted file. It specifically uses:
  160. '  - The ProcessFile, SetSecretKeyFromPassPhrase and SetRandomInitVector method.
  161. '  - The EncryptionMode, PaddingMethod, HashingMethod properties.
  162. ' This file is part of the Xceed Encryption Library sample applications.
  163. ' The source code in this file is only intended as a supplement to Xceed
  164. ' Encryption Library's documentation, and is provided "as is", without
  165. ' warranty of any kind, either expressed or implied.
  166. Option Explicit
  167. 'The different encryption methods
  168. Public Enum enuEncryptionMethod
  169.     eemRijndael = 0
  170.     eemTwoFish = 1
  171. End Enum
  172. 'The different hashing methods
  173. Public Enum enuHashingMethod
  174.     ehmSHA = 0
  175.     ehmHaval = 1
  176. End Enum
  177. 'The values chosen by the user in the Option form
  178. Private m_eEncryptionMethod As enuEncryptionMethod
  179. Private m_eEncryptionMode As EXEEncryptionMode
  180. Private m_ePaddingMethod As EXEPaddingMethod
  181. Private m_eHashingMethod As enuHashingMethod
  182. Private m_lKeySize As Integer
  183. '====================================================================================
  184. ' EVENTS - triggered by the form and its controls
  185. '====================================================================================
  186. '------------------------------------------------------------------------------------
  187. 'Select the destination folder and file name that will be process when encrypting or
  188. 'decrypting
  189. '------------------------------------------------------------------------------------
  190. Private Sub cmdSelectDestinationFile_Click()
  191.     With dlgCommon
  192.         .FileName = ""
  193.         .DialogTitle = "Destination file"
  194.         .Filter = "Encrypted (*.aes;*.2fs)|*.aes;*.2fs|All type (*.*)|*.*"
  195.         .FilterIndex = 0
  196.         .Flags = cdlOFNExplorer
  197.         On Error Resume Next
  198.             Call .ShowSave
  199.             If Err.Number = 0 Then
  200.                 txtDestinationFile.Text = .FileName
  201.             End If
  202.         On Error GoTo 0
  203.     End With
  204. End Sub
  205. '------------------------------------------------------------------------------------
  206. 'Select the source folder and file name that will be process when encrypting or
  207. 'decrypting
  208. '------------------------------------------------------------------------------------
  209. Private Sub cmdSelectSourceFile_Click()
  210.     With dlgCommon
  211.         .FileName = ""
  212.         .DialogTitle = "Source file"
  213.         .Filter = "All type (*.*)|*.*"
  214.         .FilterIndex = 0
  215.         .Flags = cdlOFNExplorer
  216.         On Error Resume Next
  217.             Call .ShowOpen
  218.             If Err.Number = 0 Then
  219.                 txtSourceFile.Text = .FileName
  220.                 Call SetDestinationFileName
  221.             End If
  222.         On Error GoTo 0
  223.     End With
  224. End Sub
  225. '------------------------------------------------------------------------------------
  226. 'Encrypt the selected source file to the specified destination file
  227. '------------------------------------------------------------------------------------
  228. Private Sub cmdEncrypt_Click()
  229.     If EncryptFile(txtSourceFile.Text, txtDestinationFile.Text) Then
  230.         'If the encryption is successful, empty the source and destination
  231.         'text box to simplify subsequent encryption/decryption.
  232.         txtSourceFile.Text = ""
  233.         txtDestinationFile.Text = ""
  234.     End If
  235. End Sub
  236. '------------------------------------------------------------------------------------
  237. 'Decrypt the selected source file to the specified destination file
  238. '------------------------------------------------------------------------------------
  239. Private Sub cmdDecrypt_Click()
  240.     If DecryptFile(txtSourceFile.Text, txtDestinationFile.Text) Then
  241.         'If the decryption is successful, empty the source and destination
  242.         'text box to simplify subsequent encryption/decryption.
  243.         txtSourceFile.Text = ""
  244.         txtDestinationFile.Text = ""
  245.     End If
  246. End Sub
  247. '------------------------------------------------------------------------------------
  248. 'Initialize the default or last saved options
  249. '------------------------------------------------------------------------------------
  250. Private Sub Form_Load()
  251.     Call LoadOption
  252. End Sub
  253. '------------------------------------------------------------------------------------
  254. 'Allow a drag and drop of a file in the form
  255. '------------------------------------------------------------------------------------
  256. Private Sub Form_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
  257.     Call EncryptDragDrop(Data, Effect)
  258. End Sub
  259. Private Sub Form_OLEDragOver(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single, State As Integer)
  260.     Call EncryptDragOver(Data, Effect)
  261. End Sub
  262. '------------------------------------------------------------------------------------
  263. 'Display the options form, saving them if the user click OK
  264. '------------------------------------------------------------------------------------
  265. Private Sub mnuOption_Click()
  266.     Dim xFrmOption As frmOption
  267.     Set xFrmOption = New frmOption
  268.     If xFrmOption.ShowForm(m_eEncryptionMethod, m_eEncryptionMode, m_ePaddingMethod, m_eHashingMethod, m_lKeySize) Then
  269.         Call SaveOption
  270.     End If
  271.     Set xFrmOption = Nothing
  272. End Sub
  273. '------------------------------------------------------------------------------------
  274. 'Quit the sample application
  275. '------------------------------------------------------------------------------------
  276. Private Sub mnuQuit_Click()
  277.     End
  278. End Sub
  279. '------------------------------------------------------------------------------------
  280. 'Initialize the destination file to a default value if the destination
  281. 'text box is empty.
  282. '------------------------------------------------------------------------------------
  283. Private Sub txtSourceFile_LostFocus()
  284.     Call SetDestinationFileName
  285. End Sub
  286. '------------------------------------------------------------------------------------
  287. 'Allow a drag and drop of a file in the source text box
  288. '------------------------------------------------------------------------------------
  289. Private Sub txtSourceFile_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
  290.     Call EncryptDragDrop(Data, Effect)
  291. End Sub
  292. Private Sub txtSourceFile_OLEDragOver(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single, State As Integer)
  293.     Call EncryptDragOver(Data, Effect)
  294. End Sub
  295. '====================================================================================
  296. ' FUNCTIONS
  297. '====================================================================================
  298. '===============================================
  299. 'Utility functions
  300. '===============================================
  301. '------------------------------------------------------------------------------------
  302. 'Function that perform the actual encryption of a source file to a destination file
  303. '------------------------------------------------------------------------------------
  304. Private Function EncryptFile(ByVal sSourceFileName As String, _
  305.                              ByVal sEncryptedFileName As String) As Boolean
  306.     Dim xEncryptor As XceedEncryption      'Our XceedEncryption object
  307.     Dim lErrNumber As Long
  308.     Dim sErrDesc As String
  309.     Dim lBytesWritten As Long
  310.     Dim lBytesRead As Long
  311.     'By default, this function returns false, assuming that an error will occur
  312.     EncryptFile = False
  313.     Me.MousePointer = vbHourglass
  314.     'Create an instance of the Xceed encryption
  315.     Set xEncryptor = New XceedEncryption
  316.     'Clear the error message and status
  317.     txtMessage.Text = ""
  318.     lErrNumber = 0
  319.     'Create and prepare the encryption method
  320.     If CreateEncryptionMethod(xEncryptor) Then
  321.         ' Encrypt the file using On error... to catch any error thrown by the
  322.         ' encryptor or by COM
  323.         On Error Resume Next
  324.             If m_eEncryptionMode = emoChainedBlocks Then
  325.                 'User wants to encrypt in CBC mode. We set the initialization
  326.                 'vector to a random value.
  327.                 Call xEncryptor.EncryptionMethod.SetRandomInitVector
  328.             End If
  329.         
  330.             If Err.Number = 0 Then
  331.                 'Process the file specifying :
  332.                     'The source file name
  333.                     'We want to encrypt the entire file
  334.                     'Encrypt and it's the end of the data
  335.                     'The destination file name and overwrite it
  336.                     'The variable that will contain the number of bytes read
  337.                 lBytesWritten = xEncryptor.ProcessFile(sSourceFileName, _
  338.                                                        0, 0, _
  339.                                                        efpEncrypt, True, _
  340.                                                        sEncryptedFileName, False, _
  341.                                                        lBytesRead)
  342.             End If
  343.             
  344.             'Keep the eventual error code and description as it is reset by the
  345.             'On error goto 0
  346.             lErrNumber = Err.Number
  347.             sErrDesc = Err.Description
  348.         On Error GoTo 0
  349.         
  350.         If lErrNumber <> 0 Then
  351.             'Display the error that occured
  352.             txtMessage.Text = sSourceFileName & " fail to encrypt" & vbCrLf & vbCrLf & _
  353.                               sErrDesc & " (" & Hex(lErrNumber) & ")"
  354.         Else
  355.             'Display a message of success
  356.             EncryptFile = True
  357.             txtMessage.Text = sSourceFileName & " successfully encrypted in " & sEncryptedFileName
  358.         End If
  359.     End If
  360.     'Deallocate the Encryption object. The encryption object will free
  361.     'the EncryptionMethod object.
  362.     Set xEncryptor = Nothing
  363.         
  364.     Me.MousePointer = vbDefault
  365. End Function
  366. '------------------------------------------------------------------------------------
  367. 'Function that perform the actual decryption of a source file to a destination file
  368. '------------------------------------------------------------------------------------
  369. Private Function DecryptFile(ByVal sSourceFileName As String, _
  370.                              ByVal sDecryptedFileName As String) As Boolean
  371.     Dim xEncryptor As XceedEncryption   'Our XceedEncryption object
  372.     Dim lErrNumber As Long
  373.     Dim sErrDesc As String
  374.     Dim lBytesWritten As Long
  375.     Dim lBytesRead As Long
  376.     'By default, this function returns false, assuming that an error will occur
  377.     DecryptFile = False
  378.     Me.MousePointer = vbHourglass
  379.     'Create an instance of the Xceed encryption
  380.     Set xEncryptor = New XceedEncryption
  381.     txtMessage = ""
  382.     lErrNumber = 0
  383.     'Create and prepare the encryption method
  384.     If CreateEncryptionMethod(xEncryptor) Then
  385.         ' Decrypt the file using On error... to catch any error thrown by the
  386.         ' encryptor or by COM
  387.         On Error Resume Next
  388.             If Err.Number = 0 Then
  389.                 'Process the file specifying :
  390.                     'The source file name
  391.                     'We want to decrypt the entire file
  392.                     'Decrypt and it's the end of the data
  393.                     'The destination file name and overwrite it
  394.                     'The variable that will contain the number of bytes read
  395.                 lBytesWritten = xEncryptor.ProcessFile(sSourceFileName, _
  396.                                                        0, 0, _
  397.                                                        efpDecrypt, True, _
  398.                                                        sDecryptedFileName, False, _
  399.                                                        lBytesRead)
  400.             End If
  401.             
  402.             'Keep the error informations before exiting the On error... section
  403.             lErrNumber = Err.Number
  404.             sErrDesc = Err.Description
  405.         On Error GoTo 0
  406.     End If
  407.     Set xEncryptor = Nothing
  408.     If lErrNumber <> 0 Then
  409.         'Display the error that occured
  410.         txtMessage.Text = sSourceFileName & " fail to decrypt" & vbCrLf & vbCrLf & _
  411.                           sErrDesc & " (" & Hex(lErrNumber) & ")"
  412.     Else
  413.         'The decryption succeeded. We return True
  414.         DecryptFile = True
  415.         txtMessage.Text = sSourceFileName & " successfully decrypted in " & sDecryptedFileName
  416.     End If
  417.     Me.MousePointer = vbDefault
  418. End Function
  419. '------------------------------------------------------------------------------------
  420. 'Load in the member variables the options saved in the registry the last
  421. 'time this sample file manager was called.
  422. '------------------------------------------------------------------------------------
  423. Private Sub LoadOption()
  424.     m_eEncryptionMethod = Val(GetSetting("XceedEncryptionManager", "Encryption", "EncryptionMethod", Str(eemRijndael)))
  425.     m_eEncryptionMode = Val(GetSetting("XceedEncryptionManager", "Encryption", "EncryptionMode", Str(emoFreeBlocks)))
  426.     m_ePaddingMethod = Val(GetSetting("XceedEncryptionManager", "Encryption", "PaddingMethod", Str(epmFIPS81)))
  427.     m_eHashingMethod = Val(GetSetting("XceedEncryptionManager", "Encryption", "HashingMethod", Str(ehmHaval)))
  428.     m_lKeySize = Val(GetSetting("XceedEncryptionManager", "Encryption", "KeySize", Str(128)))
  429. End Sub
  430. '------------------------------------------------------------------------------------
  431. 'Save the current options from the member variables in the registry
  432. '------------------------------------------------------------------------------------
  433. Private Sub SaveOption()
  434.     Call SaveSetting("XceedEncryptionManager", "Encryption", "EncryptionMethod", Str(m_eEncryptionMethod))
  435.     Call SaveSetting("XceedEncryptionManager", "Encryption", "EncryptionMode", Str(m_eEncryptionMode))
  436.     Call SaveSetting("XceedEncryptionManager", "Encryption", "PaddingMethod", Str(m_ePaddingMethod))
  437.     Call SaveSetting("XceedEncryptionManager", "Encryption", "HashingMethod", Str(m_eHashingMethod))
  438.     Call SaveSetting("XceedEncryptionManager", "Encryption", "KeySize", Str(m_lKeySize))
  439. End Sub
  440. '------------------------------------------------------------------------------------
  441. 'Function that perform the actual drop of a file on the form or the source text box
  442. '------------------------------------------------------------------------------------
  443. Private Sub EncryptDragDrop(ByRef xData As DataObject, _
  444.                             ByRef lEffect As Long)
  445.     Dim sFile As Variant
  446.     If xData.GetFormat(vbCFFiles) Then
  447.         txtSourceFile.Text = xData.Files(1)
  448.         Call SetDestinationFileName
  449.     End If
  450.     lEffect = vbDropEffectNone
  451. End Sub
  452. '------------------------------------------------------------------------------------
  453. 'Function that perform the actual drag of a file on the form or the source text box
  454. 'Only modify the mouse cursor to show if it is permitted to drop.
  455. '------------------------------------------------------------------------------------
  456. Private Sub EncryptDragOver(ByRef xData As DataObject, _
  457.                             ByRef lEffect As Long)
  458.     If xData.GetFormat(vbCFFiles) Then
  459.         lEffect = vbDropEffectCopy
  460.     Else
  461.         lEffect = vbDropEffectNone
  462.     End If
  463. End Sub
  464. '------------------------------------------------------------------------------------
  465. 'Returns the path and file name without its extension
  466. '------------------------------------------------------------------------------------
  467. Private Function RemoveFileExtension(ByVal sFilename As String) As String
  468.     Dim I As Integer
  469.     Dim nFileNameLen As Integer
  470.     Dim nLenToTake As Integer
  471.     nFileNameLen = Len(sFilename)
  472.     I = nFileNameLen
  473.     nLenToTake = -1
  474.     While I > 0 And nLenToTake = -1
  475.         Select Case Mid(sFilename, I, 1)
  476.             Case "."
  477.                 nLenToTake = I - 1
  478.             Case "\"
  479.                 nLenToTake = nFileNameLen
  480.         End Select
  481.         I = I - 1
  482.     Wend
  483.     If nLenToTake = -1 Then
  484.         RemoveFileExtension = ""
  485.     Else
  486.         RemoveFileExtension = Left(sFilename, nLenToTake)
  487.     End If
  488. End Function
  489. '------------------------------------------------------------------------------------
  490. 'Assign a default value to the destination file name if the destination text box
  491. 'is empty.
  492. '------------------------------------------------------------------------------------
  493. Private Sub SetDestinationFileName()
  494.     Dim sEncryptedFileName As String
  495.     sEncryptedFileName = txtDestinationFile.Text
  496.     If Len(sEncryptedFileName) = 0 Then
  497.         sEncryptedFileName = RemoveFileExtension(txtSourceFile.Text)
  498.         If Len(sEncryptedFileName) <> 0 Then
  499.             If m_eEncryptionMethod = eemRijndael Then
  500.                 txtDestinationFile.Text = sEncryptedFileName & ".aes"
  501.             Else
  502.                 txtDestinationFile.Text = sEncryptedFileName & ".2fs"
  503.             End If
  504.         End If
  505.     End If
  506. End Sub
  507. '====================================================================================
  508. 'Functions - others
  509. '====================================================================================
  510. '------------------------------------------------------------------------------------
  511. 'Create a new instance of an encryption method according to the specified
  512. 'encryption method chosen in the option form (saved in the registry).
  513. 'Set some properties to the encryption method object appropriate for the selected
  514. 'encryption method and common the encryption and decryption since this function
  515. 'will be called before doing both.
  516. '------------------------------------------------------------------------------------
  517. Private Function CreateEncryptionMethod(ByRef xEncryptor As XceedEncryption) As Boolean
  518.     Dim bCreateOK As Boolean
  519.     bCreateOK = True
  520.     'We instanciate a new encryption method, assigning it directly to the
  521.     'EncryptionMethod property of the XceedEncryption object.
  522.     'The drawbacks to this programming method are :
  523.     '   - we don't have access to the code completion for the EncryptionMethod
  524.     '   - setting a property of the EncryptionMethod (a VB Object, or COM
  525.     '     IDispatch) will use the QueryInterface COM scheme which is less
  526.     '     efficient than calling a property from a object of type
  527.     '     XceedRijndaelEncryptionMethod for instance.
  528.     'To see an example of how it could be done more efficiently and with the
  529.     'help of code completion, consult the MemoryEncrypt sample application.
  530.     On Error Resume Next
  531.         'Instanciate the right encryption method
  532.         Select Case m_eEncryptionMethod
  533.             Case eemRijndael
  534.                 Set xEncryptor.EncryptionMethod = New XceedRijndaelEncryptionMethod
  535.             
  536.             Case eemTwoFish
  537.                 Set xEncryptor.EncryptionMethod = New XceedTwofishEncryptionMethod
  538.                 
  539.         End Select
  540.         
  541.         If Err.Number = 0 Then
  542.             With xEncryptor.EncryptionMethod
  543.                 'Set the hashing method that will be used to set the key from
  544.                 'the pass phrase.
  545.                 Select Case m_eHashingMethod
  546.                     Case ehmHaval
  547.                         Set .HashingMethod = New XceedHavalHashingMethod
  548.                         If Err.Number = 0 Then
  549.                             'Haval supports hash sizes equivalent to the supported
  550.                             'key size. So, we can assign the latter to the
  551.                             'former without problem.
  552.                             .HashingMethod.HashSize = m_lKeySize
  553.                         End If
  554.                     Case ehmSHA
  555.                         Set .HashingMethod = New XceedSHAHashingMethod
  556.                         If Err.Number = 0 Then
  557.                             'We arbitrarily set the HashSize to the maximum key
  558.                             'size allowed so we don't have to worry that the hash
  559.                             'result of the pass phrase could be shorter than the
  560.                             'expected key (although the Xceed Encryption Library
  561.                             'would have deal with it).
  562.                             .HashingMethod.HashSize = 256
  563.                         End If
  564.                 End Select
  565.                 
  566.                 If Err.Number = 0 Then
  567.                     'Set the secret key of the desired size using the user pass phrase
  568.                     Call .SetSecretKeyFromPassPhrase(txtPassPhrase.Text, m_lKeySize)
  569.                     
  570.                     If Err.Number = 0 Then
  571.                         'Set the encryption mode
  572.                         .EncryptionMode = m_eEncryptionMode
  573.                         
  574.                         If Err.Number = 0 Then
  575.                             'Set the padding method (for the last encrypted or decrypted
  576.                             'block)
  577.                             .PaddingMethod = m_ePaddingMethod
  578.                         End If
  579.                     End If
  580.                 End If
  581.             End With
  582.         End If
  583.         
  584.         If Err.Number <> 0 Then
  585.             'Display the error that occured
  586.             txtMessage = txtMessage & " error initializing the encryption method" & vbCrLf & vbCrLf & _
  587.                          Err.Description & " (" & Hex(Err.Number) & ")" & vbCrLf
  588.             bCreateOK = False
  589.         End If
  590.     On Error GoTo 0
  591.     CreateEncryptionMethod = bCreateOK
  592. End Function
  593.