home *** CD-ROM | disk | FTP | other *** search
- VERSION 5.00
- Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
- Begin VB.Form frmMemoryEncrypt
- BorderStyle = 3 'Fixed Dialog
- Caption = "Memory Encryption"
- ClientHeight = 6180
- ClientLeft = 45
- ClientTop = 330
- ClientWidth = 10455
- LinkTopic = "Form1"
- MaxButton = 0 'False
- MinButton = 0 'False
- ScaleHeight = 6180
- ScaleWidth = 10455
- StartUpPosition = 2 'CenterScreen
- Begin VB.Frame Frame2
- Caption = "Frame2"
- Height = 1515
- Left = 150
- TabIndex = 3
- Top = 1275
- Width = 8340
- Begin VB.OptionButton optAsymmetricEncryption
- Caption = "Asymmetric encryption"
- Height = 240
- Left = 75
- TabIndex = 4
- Top = 0
- Width = 1890
- End
- Begin VB.CommandButton cmdSelectPrivateKeyFile
- Caption = "..."
- Height = 285
- Left = 7950
- TabIndex = 6
- Top = 375
- Width = 285
- End
- Begin VB.TextBox txtPrivateKeyFile
- Height = 285
- Left = 1500
- OLEDropMode = 1 'Manual
- TabIndex = 5
- Top = 375
- Width = 6390
- End
- Begin VB.TextBox txtPublicKeyFile
- Height = 285
- Left = 1500
- OLEDropMode = 2 'Automatic
- TabIndex = 7
- Top = 750
- Width = 6390
- End
- Begin VB.CommandButton cmdSelectPublicKeyFile
- Caption = "..."
- Height = 285
- Left = 7950
- TabIndex = 8
- Top = 750
- Width = 285
- End
- Begin VB.CommandButton cmdRandomKeyPair
- Caption = "Set random key pair"
- Height = 315
- Left = 6450
- TabIndex = 9
- Top = 1125
- Width = 1815
- End
- Begin VB.Label lbl
- Caption = "Private key file"
- Height = 240
- Index = 2
- Left = 150
- TabIndex = 20
- Top = 375
- Width = 1290
- End
- Begin VB.Label lbl
- Caption = "Public key file"
- Height = 240
- Index = 3
- Left = 150
- TabIndex = 19
- Top = 750
- Width = 1215
- End
- End
- Begin VB.Frame fraSymmetricEncryption
- Height = 1065
- Left = 150
- TabIndex = 0
- Top = 75
- Width = 8340
- Begin VB.OptionButton optSymmetricEncryption
- Caption = "Symmetric encryption"
- Height = 240
- Left = 75
- TabIndex = 15
- Top = 0
- Width = 1815
- End
- Begin VB.CommandButton cmdOption
- Caption = "Option"
- Height = 315
- Left = 7125
- TabIndex = 2
- Top = 675
- Width = 1140
- End
- Begin VB.TextBox txtPassPhrase
- Height = 285
- IMEMode = 3 'DISABLE
- Left = 1500
- OLEDropMode = 1 'Manual
- TabIndex = 1
- Top = 300
- Width = 6765
- End
- Begin VB.Label lbl
- Caption = "Pass phrase"
- Height = 240
- Index = 0
- Left = 150
- TabIndex = 18
- Top = 300
- Width = 915
- End
- End
- Begin VB.Frame fraEncrypted
- Caption = "Encrypted text"
- Height = 2640
- Left = 5850
- TabIndex = 17
- Top = 2925
- Width = 4515
- Begin VB.TextBox txtEncryptedText
- BeginProperty Font
- Name = "Courier New"
- Size = 8.25
- Charset = 0
- Weight = 400
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 2265
- Left = 75
- MultiLine = -1 'True
- ScrollBars = 2 'Vertical
- TabIndex = 13
- Top = 300
- Width = 4365
- End
- End
- Begin VB.Frame fraDecrypted
- Caption = "Decrypted text"
- Height = 2640
- Left = 150
- TabIndex = 16
- Top = 2925
- Width = 4440
- Begin VB.TextBox txtDecryptedText
- Height = 2265
- Left = 75
- MultiLine = -1 'True
- ScrollBars = 2 'Vertical
- TabIndex = 10
- Top = 300
- Width = 4290
- End
- End
- Begin VB.CommandButton cmdQuit
- Cancel = -1 'True
- Caption = "Quit"
- Height = 390
- Left = 9225
- TabIndex = 14
- Top = 5700
- Width = 1140
- End
- Begin VB.CommandButton cmdDecrypt
- Caption = "<< Decrypt"
- Height = 540
- Left = 4725
- TabIndex = 12
- Top = 4575
- Width = 990
- End
- Begin VB.CommandButton cmdEncrypt
- Caption = "Encrypt >>"
- Height = 540
- Left = 4725
- TabIndex = 11
- Top = 3600
- Width = 990
- End
- Begin MSComDlg.CommonDialog dlgCommon
- Left = 1725
- Top = 5625
- _ExtentX = 847
- _ExtentY = 847
- _Version = 393216
- End
- Attribute VB_Name = "frmMemoryEncrypt"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = True
- Attribute VB_Exposed = False
- ' Xceed Encryption Library - Memory Encrypt sample
- ' Copyright (c) 2001 Xceed Software Inc.
- ' [MemoryEncrypt.frm]
- ' This form module contains the main form's code. It demonstrates how to
- ' Encrypt a chunk of memory data using different kinds of Encryption methods,
- ' and Decrypt an Encrypted memory data. It specifically uses:
- ' - The Encrypt, Decrypt, SetSecretKeyFromPassPhrase,
- ' SetRandomInitVector and SetRandomKeyPair methods.
- ' - The HashingMethod, HashSize, EncryptionMode, PaddingMethod, EncryptionMethod,
- ' PrivateKey and PublicKey properties.
- ' This file is part of the Xceed Encryption Library sample applications.
- ' The source code in this file is only intended as a supplement to Xceed
- ' Encryption Library's documentation, and is provided "as is", without
- ' warranty of any kind, either expressed or implied.
- Option Explicit
- 'The different encryption methods
- Public Enum enuEncryptionMethod
- eemRijndael = 0
- eemTwoFish = 1
- End Enum
- 'The different hashing methods
- Public Enum enuHashingMethod
- ehmSHA = 0
- ehmHaval = 1
- End Enum
- 'The values chosen by the user in the Option form
- Private m_eEncryptionMethod As enuEncryptionMethod
- Private m_eEncryptionMode As EXEEncryptionMode
- Private m_ePaddingMethod As EXEPaddingMethod
- Private m_eHashingMethod As enuHashingMethod
- Private m_lSecretKeySize As Integer
- '====================================================================================
- ' EVENTS - triggered by the form and its controls
- '====================================================================================
- '------------------------------------------------------------------------------------
- 'Do the Encryption of the original text
- '------------------------------------------------------------------------------------
- Private Sub cmdEncrypt_Click()
- Dim xEncryptor As XceedEncryption
- Dim vaDecryptedText As Variant
- Dim lErrorNumber As Long
- Dim sEncrypted As String
- 'Create an instance of the Xceed Encryption
- Set xEncryptor = New XceedEncryption
- With xEncryptor
- 'Create and prepare the Encryption Method
- If PrepareEncryptionMethod(xEncryptor) Then
- 'Convert unicode text to an ascii string
- 'Useful to reduce the output Encrypted string, but it could
- 'be skipped
- vaDecryptedText = StrConv(txtDecryptedText.Text, vbFromUnicode)
-
- On Error Resume Next
- 'Encrypt the ascii string, specifying that (True parameter)
- 'this is the end of data (there will be no more calls to Encrypt).
- 'Then convert the encrypted text to Hexadecimal representation so
- 'it can be readable in a text box
- sEncrypted = BinaryToHex(.Encrypt(vaDecryptedText, True))
-
- lErrorNumber = Err.Number
- If lErrorNumber <> 0 Then
- Call MsgBox("Error during Encrypt." & vbCrLf & Err.Description & " (" & Hex(Err.Number) & ")")
- End If
- On Error GoTo 0
- Else
- 'An error occured, we don't know which one, we don't care because it was
- 'already shown to the user. We set the error code to an arbitrary
- 'value of 1.
- lErrorNumber = 1
- End If
-
- If lErrorNumber = 0 Then
- If Len(sEncrypted) = 0 Then
- 'No output was produced
- txtEncryptedText.Text = ""
- Else
- 'Display the Encrypted result in the text box
- 'The BinaryToHex method returning a BSTR (Unicode), we
- 'don't have to convert the encrypted string. We can affect
- 'it directly to the textbox
- txtEncryptedText.Text = sEncrypted
- End If
- End If
- End With
- 'Deallocate the Encryption object. The Encryption object will free
- 'the EncryptionMethod object.
- Set xEncryptor = Nothing
- End Sub
- '------------------------------------------------------------------------------------
- 'Do the Decryption of the Encrypted text
- '------------------------------------------------------------------------------------
- Private Sub cmdDecrypt_Click()
- Dim xEncryptor As XceedEncryption
- Dim lErrorNumber As Long
- Dim vaDecrypted As Variant
- 'Create an instance of the Xceed Encryption
- Set xEncryptor = New XceedEncryption
- With xEncryptor
- 'Create and prepare the Encryption Method
- If PrepareEncryptionMethod(xEncryptor) Then
- On Error Resume Next
- 'Convert the encrypted text from Hexadecimal representation to
- 'binary representation so it can be successfully decrypted.
- 'Decrypt the ascii Encrypted string, specifying that (True parameter)
- 'this is the end of data (there will be no more calls to Decrypt).
- vaDecrypted = .Decrypt(HexToBinary(txtEncryptedText.Text), True)
-
- lErrorNumber = Err.Number
- If lErrorNumber <> 0 Then
- Call MsgBox("Error during Decrypt." & vbCrLf & Err.Description & " (" & Hex(Err.Number) & ")")
- End If
- On Error GoTo 0
- Else
- 'An error occured, we don't know which one and we don't care because it was
- 'already shown to the user. We set the error code to an arbitrary
- 'value of 1.
- lErrorNumber = 1
- End If
-
- If lErrorNumber = 0 Then
- If IsEmpty(vaDecrypted) Then
- 'No output was produced
- txtDecryptedText.Text = ""
- Else
- 'Display the Decrypted result in the text box.
- 'We convert the ascii string
- 'returned by the Decrypt method to Unicode so that the
- 'Decrypted text box will contained something readable.
- 'If we had not convert the Decrypted string in the Encrypt
- 'process (to reduce the output Encrypted string), we
- 'would simply assign the vaDecrypted to the txtDecryptedText.
- txtDecryptedText.Text = StrConv(vaDecrypted, vbUnicode)
- End If
- End If
- End With
- 'Deallocate the Encryption object. The Encryption object will free
- 'the EncryptionMethod object.
- Set xEncryptor = Nothing
- End Sub
- '------------------------------------------------------------------------------------
- 'Display the options form, saving them if the user click OK
- '------------------------------------------------------------------------------------
- Private Sub cmdOption_Click()
- Dim xFrmOption As frmOption
- Set xFrmOption = New frmOption
- If xFrmOption.ShowForm(m_eEncryptionMethod, m_eEncryptionMode, m_ePaddingMethod, m_eHashingMethod, m_lSecretKeySize) Then
- Call SaveOption
- End If
- Set xFrmOption = Nothing
- End Sub
- '------------------------------------------------------------------------------------
- 'Quit the sample application
- '------------------------------------------------------------------------------------
- Private Sub cmdQuit_Click()
- End
- End Sub
- '------------------------------------------------------------------------------------
- 'Generate new private and public keys stored in the file specified in the
- 'respective text boxes.
- '------------------------------------------------------------------------------------
- Private Sub cmdRandomKeyPair_Click()
- Dim fxKeyPair As frmKeyPair
- If Len(Trim$(txtPrivateKeyFile.Text)) = 0 Or Len(Trim$(txtPublicKeyFile.Text)) = 0 Then
- 'The file names are mandatory
- Call MsgBox("You must specify the key file names where will be stored the private and public keys", vbExclamation, "Error")
- Else
- 'Show the dialog box used to generate a new key pair, passing it the two file names
- Set fxKeyPair = New frmKeyPair
- Call fxKeyPair.ShowForm(txtPrivateKeyFile.Text, txtPublicKeyFile.Text)
- Set fxKeyPair = Nothing
- End If
- End Sub
- '------------------------------------------------------------------------------------
- 'Select the file name that contain (or will contain) the private key.
- '------------------------------------------------------------------------------------
- Private Sub cmdSelectPrivateKeyFile_Click()
- With dlgCommon
- .FileName = ""
- .DialogTitle = "Source file"
- .Filter = "Key file (*.key)|*.key|All type (*.*)|*.*"
- .FilterIndex = 0
- .Flags = cdlOFNExplorer
- On Error Resume Next
- Call .ShowOpen
- If Len(.FileName) > 0 Then
- txtPrivateKeyFile.Text = .FileName
- Call SavePrivateKeyFileSetting
- End If
- On Error GoTo 0
- End With
- End Sub
- '------------------------------------------------------------------------------------
- 'Select the file name that contain (or will contain) the public key.
- '------------------------------------------------------------------------------------
- Private Sub cmdSelectPublicKeyFile_Click()
- With dlgCommon
- .FileName = ""
- .DialogTitle = "Source file"
- .Filter = "Key file (*.key)|*.key|All type (*.*)|*.*"
- .FilterIndex = 0
- .Flags = cdlOFNExplorer
- On Error Resume Next
- Call .ShowOpen
- If Len(.FileName) > 0 Then
- txtPublicKeyFile.Text = .FileName
- Call SavePublicKeyFileSetting
- End If
- On Error GoTo 0
- End With
- End Sub
- '------------------------------------------------------------------------------------
- 'Initialize the default and last saved options
- '------------------------------------------------------------------------------------
- Private Sub Form_Load()
- Call LoadOption
- txtDecryptedText.Text = "This is a little test to show you how the memory encryption works." & vbCrLf & _
- "And it is very easy to use."
- Call EnableControls
- End Sub
- '------------------------------------------------------------------------------------
- 'The user selected asymmetric mode, disable controls associated with symmetric
- 'encryption
- '------------------------------------------------------------------------------------
- Private Sub optAsymmetricEncryption_Click()
- If Me.Visible Then
- optSymmetricEncryption.Value = False
- Call EnableControls
- Call SaveEncryptionType
- End If
- End Sub
- '------------------------------------------------------------------------------------
- 'The user selected symmetric mode, disable controls associated with asymmetric
- 'encryption
- '------------------------------------------------------------------------------------
- Private Sub optSymmetricEncryption_Click()
- If Me.Visible Then
- optAsymmetricEncryption.Value = False
- Call EnableControls
- Call SaveEncryptionType
- End If
- End Sub
- Private Sub txtPrivateKeyFile_LostFocus()
- Call SavePrivateKeyFileSetting
- End Sub
- Private Sub txtPublicKeyFile_LostFocus()
- Call SavePublicKeyFileSetting
- End Sub
- '====================================================================================
- ' FUNCTIONS
- '====================================================================================
- '------------------------------------------------------------------------------------
- 'Enable the control associated with the selected encryption type (symmetric or
- 'asymmetric). Disable the other controls.
- '------------------------------------------------------------------------------------
- Private Sub EnableControls()
- Dim bSecretKeyEncryption As Boolean
- bSecretKeyEncryption = optSymmetricEncryption.Value
- txtPassPhrase.Enabled = bSecretKeyEncryption
- cmdOption.Enabled = bSecretKeyEncryption
- txtPrivateKeyFile.Enabled = Not bSecretKeyEncryption
- cmdSelectPrivateKeyFile.Enabled = Not bSecretKeyEncryption
- txtPublicKeyFile.Enabled = Not bSecretKeyEncryption
- cmdSelectPublicKeyFile.Enabled = Not bSecretKeyEncryption
- cmdRandomKeyPair.Enabled = Not bSecretKeyEncryption
- End Sub
- '------------------------------------------------------------------------------------
- 'Prepare the Encryption Method according to the user selection
- 'Return True if all succeeded
- '------------------------------------------------------------------------------------
- Private Function PrepareEncryptionMethod(ByRef xEncryptor As XceedEncryption) As Boolean
- 'We use one variable for each Encryption Method to simplify the programming
- '(code completion). Only one of these will be used at a time (according to
- 'the chosen Encryption method in the combo box).
- 'To see an example of how it could be done without all these declarations,
- 'consult the Manager sample application.
- Dim xRijndael As XceedRijndaelEncryptionMethod
- Dim xTwofish As XceedTwofishEncryptionMethod
- Dim xRSA As XceedRSAEncryptionMethod
- Dim vaPrivateKey As Variant
- Dim vaPublicKey As Variant
- Dim bPrepareOK As Boolean
- bPrepareOK = True
- On Error Resume Next
- If optSymmetricEncryption.Value Then
- 'The user chose to perform symmetric encryption/decryption
-
- Select Case m_eEncryptionMethod
- Case eemRijndael
- 'Instanciate the Rijndael encryption method
- Set xRijndael = New XceedRijndaelEncryptionMethod
-
- If Err.Number = 0 Then
- 'Set the hashing method that will be used to set the key from
- 'the pass phrase.
- Select Case m_eHashingMethod
- Case ehmHaval
- Set xRijndael.HashingMethod = New XceedHavalHashingMethod
- If Err.Number = 0 Then
- 'Haval supports hash sizes equivalent to the supported
- 'key size. So, we can assign the latter to the
- 'former without problem.
- xRijndael.HashingMethod.HashSize = m_lSecretKeySize
- End If
- Case ehmSHA
- Set xRijndael.HashingMethod = New XceedSHAHashingMethod
- If Err.Number = 0 Then
- 'We arbitrarily set the HashSize to the maximum key
- 'size allowed so we don't have to worry that the hash
- 'result of the pass phrase could be shorter than the
- 'expected key (although the Xceed Encryption Library
- 'would have deal with it).
- xRijndael.HashingMethod.HashSize = 256
- End If
- End Select
- End If
-
- If Err.Number = 0 Then
- 'Set the encryption mode
- xRijndael.EncryptionMode = m_eEncryptionMode
- If Err.Number = 0 Then
- 'Set the padding method (for the last encrypted or decrypted
- 'block)
- xRijndael.PaddingMethod = m_ePaddingMethod
- If Err.Number = 0 Then
- 'Set the secret key of the desired size using the user pass phrase
- Call xRijndael.SetSecretKeyFromPassPhrase(txtPassPhrase.Text, m_lSecretKeySize)
- If Err.Number = 0 Then
- If m_eEncryptionMode = emoChainedBlocks Then
- 'Will be useful only when encrypting since, in decryption,
- 'the InitVector is read at the beginning of the encrypted text.
- Call xRijndael.SetRandomInitVector
- End If
- End If
- End If
- End If
- End If
-
- If Err.Number = 0 Then
- 'Set the previously initialized Encryption Method of the Encryptor object
- 'received as a parameter of this function.
- Set xEncryptor.EncryptionMethod = xRijndael
- 'Free the temporary Encryption Method. The previous assignation adding
- 'a reference to the Encryption Method object, this object will effectively
- 'be freed by the xEncryptor object when the latter will be freed.
- End If
- Set xRijndael = Nothing
-
- Case eemTwoFish
- 'Instanciate the Twofish encryption method
- Set xTwofish = New XceedTwofishEncryptionMethod
-
- If Err.Number = 0 Then
- Select Case m_eHashingMethod
- Case ehmHaval
- Set xTwofish.HashingMethod = New XceedHavalHashingMethod
- If Err.Number = 0 Then
- xTwofish.HashingMethod.HashSize = m_lSecretKeySize
- End If
- Case ehmSHA
- Set xTwofish.HashingMethod = New XceedSHAHashingMethod
- If Err.Number = 0 Then
- xTwofish.HashingMethod.HashSize = 256
- End If
- End Select
- End If
-
- If Err.Number = 0 Then
- xTwofish.EncryptionMode = m_eEncryptionMode
- If Err.Number = 0 Then
- xTwofish.PaddingMethod = m_ePaddingMethod
- If Err.Number = 0 Then
- Call xTwofish.SetSecretKeyFromPassPhrase(txtPassPhrase.Text, m_lSecretKeySize)
- If Err.Number = 0 Then
- If m_eEncryptionMode = emoChainedBlocks Then
- Call xTwofish.SetRandomInitVector
- End If
- End If
- End If
- End If
- End If
-
- If Err.Number = 0 Then
- Set xEncryptor.EncryptionMethod = xTwofish
- End If
- Set xTwofish = Nothing
-
- End Select
- Else
- 'The user chose to perform asymmetric encryption/decryption
-
- If optAsymmetricEncryption.Value Then
- 'Instanciate the RSA encryption method
- Set xRSA = New XceedRSAEncryptionMethod
- If Err.Number = 0 Then
- 'Initialize the private key (used when decrypting)
- Call ReadKeyFile(txtPrivateKeyFile.Text, vaPrivateKey)
- xRSA.PrivateKey = vaPrivateKey
- If Err.Number = 0 Then
- 'Initialize the public key (used when encrypting)
- Call ReadKeyFile(txtPublicKeyFile.Text, vaPublicKey)
- xRSA.PublicKey = vaPublicKey
- If Err.Number = 0 Then
- Set xEncryptor.EncryptionMethod = xRSA
- End If
- End If
- End If
- Set xRSA = Nothing
- End If
- End If
-
- If Err.Number <> 0 Then
- bPrepareOK = False
- Call MsgBox("Error during Encryption method initialization." & vbCrLf & Err.Description & " (" & Hex(Err.Number) & ")")
- End If
- On Error GoTo 0
- PrepareEncryptionMethod = bPrepareOK
- End Function
- '------------------------------------------------------------------------------------
- 'Load in the member variables the options saved in the registry the last
- 'time this sample file manager was called.
- '------------------------------------------------------------------------------------
- Private Sub LoadOption()
- m_eEncryptionMethod = Val(GetSetting("XceedMemoryEncrypt", "Encryption", "EncryptionMethod", Str(eemRijndael)))
- m_eEncryptionMode = Val(GetSetting("XceedMemoryEncrypt", "Encryption", "EncryptionMode", Str(emoFreeBlocks)))
- m_ePaddingMethod = Val(GetSetting("XceedMemoryEncrypt", "Encryption", "PaddingMethod", Str(epmFIPS81)))
- m_eHashingMethod = Val(GetSetting("XceedMemoryEncrypt", "Encryption", "HashingMethod", Str(ehmHaval)))
- m_lSecretKeySize = Val(GetSetting("XceedMemoryEncrypt", "Encryption", "SecretKeySize", Str(128)))
- txtPrivateKeyFile.Text = GetSetting("XceedMemoryEncrypt", "Encryption", "PrivateKeyFile", "")
- txtPublicKeyFile.Text = GetSetting("XceedMemoryEncrypt", "Encryption", "PublicKeyFile", "")
- optAsymmetricEncryption.Value = Val(GetSetting("XceedMemoryEncrypt", "Encryption", "Asymmetric", "0"))
- optSymmetricEncryption.Value = Val(GetSetting("XceedMemoryEncrypt", "Encryption", "Symmetric", Str(Val(True))))
- End Sub
- '------------------------------------------------------------------------------------
- 'Save the current options from the member variables in the registry
- '------------------------------------------------------------------------------------
- Private Sub SaveOption()
- Call SaveSetting("XceedMemoryEncrypt", "Encryption", "EncryptionMethod", Str(m_eEncryptionMethod))
- Call SaveSetting("XceedMemoryEncrypt", "Encryption", "EncryptionMode", Str(m_eEncryptionMode))
- Call SaveSetting("XceedMemoryEncrypt", "Encryption", "PaddingMethod", Str(m_ePaddingMethod))
- Call SaveSetting("XceedMemoryEncrypt", "Encryption", "HashingMethod", Str(m_eHashingMethod))
- Call SaveSetting("XceedMemoryEncrypt", "Encryption", "SecretKeySize", Str(m_lSecretKeySize))
- End Sub
- '------------------------------------------------------------------------------------
- 'Read the content of the specified file, allegedly containing a private or public
- 'key in hexadecimal representation.
- 'Return the key in the vaKey parameter. This function can return Empty.
- '------------------------------------------------------------------------------------
- Private Sub ReadKeyFile(ByVal sKeyFile As String, _
- ByRef vaKey As Variant)
- Dim nNoFic As Integer
- Dim sBuffer As String
- Dim sKey As String
- vaKey = Empty
- If Len(sKeyFile) > 0 Then
- On Error Resume Next
- nNoFic = FreeFile
- Open sKeyFile For Input As #nNoFic
- If Err.Number = 0 Then
- sKey = ""
- While Not EOF(nNoFic) And Err.Number = 0
- Line Input #nNoFic, sBuffer
- sKey = sKey & sBuffer
- Wend
- Close #nNoFic
- End If
-
- If Err.Number = 0 Then
- 'The file has been read successfully. Decode the hexadecimal key to binary form.
- vaKey = HexToBinary(sKey)
- Else
- vaKey = Empty
- Call MsgBox("Error reading key file " & sKeyFile & vbCrLf & Err.Description & " (" & Hex(Err.Number) & ")")
- End If
- On Error GoTo 0
- End If
- End Sub
- '------------------------------------------------------------------------------------
- 'Save the current selected (and deselected) encryption type (symmetric or asymmetric)
- '------------------------------------------------------------------------------------
- Private Sub SaveEncryptionType()
- Call SaveSetting("XceedMemoryEncrypt", "Encryption", "Asymmetric", Str$(Int(optAsymmetricEncryption.Value)))
- Call SaveSetting("XceedMemoryEncrypt", "Encryption", "Symmetric", Str$(Int(optSymmetricEncryption.Value)))
- End Sub
- '------------------------------------------------------------------------------------
- 'Save the current private key file name
- '------------------------------------------------------------------------------------
- Private Sub SavePrivateKeyFileSetting()
- Call SaveSetting("XceedMemoryEncrypt", "Encryption", "PrivateKeyFile", txtPrivateKeyFile.Text)
- End Sub
- '------------------------------------------------------------------------------------
- 'Save the current public key file name
- '------------------------------------------------------------------------------------
- Private Sub SavePublicKeyFileSetting()
- Call SaveSetting("XceedMemoryEncrypt", "Encryption", "PublicKeyFile", txtPublicKeyFile.Text)
- End Sub
-