home *** CD-ROM | disk | FTP | other *** search
- VERSION 5.00
- Object = "{C9E83EE3-7D8C-11D2-9906-444553540000}#1.0#0"; "MIRAGE.OCX"
- Begin VB.Form Form1
- Caption = "Mirage Sample Application"
- ClientHeight = 2040
- ClientLeft = 60
- ClientTop = 348
- ClientWidth = 5640
- LinkTopic = "Form1"
- ScaleHeight = 2040
- ScaleWidth = 5640
- StartUpPosition = 3 'Windows Default
- Begin MIRAGELib.Mirage Mirage1
- Left = 1920
- Top = 1560
- _Version = 65536
- _ExtentX = 423
- _ExtentY = 423
- _StockProps = 0
- End
- Begin VB.ComboBox Combo1
- Height = 288
- ItemData = "Form1.frx":0000
- Left = 960
- List = "Form1.frx":000D
- Sorted = -1 'True
- TabIndex = 7
- Text = "CFB"
- Top = 1560
- Width = 855
- End
- Begin VB.TextBox Text4
- Enabled = 0 'False
- Height = 285
- Left = 960
- TabIndex = 6
- Top = 1200
- Width = 4575
- End
- Begin VB.TextBox Text3
- Enabled = 0 'False
- Height = 285
- Left = 960
- TabIndex = 5
- Top = 840
- Width = 4575
- End
- Begin VB.TextBox Text2
- Height = 285
- Left = 960
- TabIndex = 4
- Text = "1234567890"
- Top = 480
- Width = 4575
- End
- Begin VB.CommandButton Decrypt
- Caption = "&Decrypt"
- Height = 375
- Left = 3480
- TabIndex = 3
- Top = 1560
- Width = 975
- End
- Begin VB.TextBox Text1
- Height = 285
- Left = 960
- TabIndex = 2
- Text = "This is the data."
- Top = 120
- Width = 4575
- End
- Begin VB.CommandButton Encrypt
- Caption = "&Encrypt"
- Height = 375
- Left = 2400
- TabIndex = 1
- Top = 1560
- Width = 975
- End
- Begin VB.CommandButton Quit
- Caption = "&Quit"
- Default = -1 'True
- Height = 375
- Left = 4560
- TabIndex = 0
- Top = 1560
- Width = 975
- End
- Begin VB.Label Label5
- Alignment = 1 'Right Justify
- Caption = "Method:"
- Height = 372
- Left = 120
- TabIndex = 12
- Top = 1560
- Width = 732
- End
- Begin VB.Label Label4
- Alignment = 1 'Right Justify
- Caption = "Decrypted:"
- Height = 252
- Left = 0
- TabIndex = 11
- Top = 1200
- Width = 852
- End
- Begin VB.Label Label3
- Alignment = 1 'Right Justify
- Caption = "Encrypted:"
- Height = 252
- Left = 0
- TabIndex = 10
- Top = 840
- Width = 852
- End
- Begin VB.Label Label2
- Alignment = 1 'Right Justify
- Caption = "Key:"
- Height = 252
- Left = -120
- TabIndex = 9
- Top = 480
- Width = 972
- End
- Begin VB.Label Label1
- Alignment = 1 'Right Justify
- Caption = "Data:"
- Height = 252
- Left = 120
- TabIndex = 8
- Top = 120
- Width = 732
- End
- Attribute VB_Name = "Form1"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = True
- Attribute VB_Exposed = False
- Option Explicit
- Private Function StringToMode(ByVal Mode As String)
- Select Case UCase(Mode)
- Case "ECB"
- StringToMode = MIRAGE_MODE_ECB
- Case "CFB"
- StringToMode = MIRAGE_MODE_CFB
- Case "CBC"
- StringToMode = MIRAGE_MODE_CBC
- Case Else
- StringToMode = -1
- End Select
- End Function
- Private Sub Decrypt_Click()
- Dim Key As String
- Dim ret As String
- Dim Data As String
- Dim Mode As Integer
- Mode = StringToMode(Combo1.Text)
- Key = Mirage1.StrToHex(Text2.Text, Len(Text2.Text))
- Data = Mirage1.HexToStr(Text3.Text, Len(Text3.Text))
- If (DataLengthOK(Mode, Data)) Then
- If (KeyLengthOK(Text2.Text)) Then
- ret = Mirage1.Decrypt(Data, Len(Data), Key, MIRAGE_TWOFISH, Mode)
-
- If Len(Data) <> Len(ret) Then
- Debug.Print "Error occurred."
- End If
-
- Text4.Text = ret
-
- End If
- End If
- End Sub
- Private Sub Encrypt_Click()
- Dim Key As String
- Dim ret As String
- Dim Data As String
- Dim Mode As Integer
- Mode = StringToMode(Combo1.Text)
- Key = Mirage1.StrToHex(Text2.Text, Len(Text2.Text))
- If (DataLengthOK(Mode, Text1.Text)) Then
- If (KeyLengthOK(Text2.Text)) Then
- ret = Mirage1.Encrypt(Text1.Text, Len(Text1.Text), Key, 0, Mode)
- Data = Mirage1.StrToHex(ret, Len(ret))
- Text3.Text = Data
-
- End If
- End If
- End Sub
- Private Sub Quit_Click()
- Unload Me
- End Sub
- Private Function DataLengthOK(Mode As Integer, Data As String) As Boolean
- ' This function checks a passed string (Data) for length requirements.
- ' This function could be changed to pad the data to fit the requirements
- ' instead of displaying an error.
- DataLengthOK = 1
- If (Mode <> MIRAGE_MODE_CFB) Then
- If Len(Data) Mod 16 <> 0 Then
- MsgBox "CBC and ECB encryption require that the input block be a multiple of the block size (16 Characters)", vbOKOnly, "Mirage Sample Application"
- DataLengthOK = 0
- End If
- End If
- End Function
- Private Function KeyLengthOK(Key As String) As Boolean
- ' This function checks a passed string (Key) for length requirements.
- ' This function could be changed to pad or trim the key to fit the requirements
- ' instead of displaying an error.
- KeyLengthOK = 1
- If (Len(Key) < 9) Or (Len(Key) > 32) Then
- MsgBox "Key length must be between 9 and 32 characters.", vbOKOnly, "Mirage Sample Application"
- KeyLengthOK = 0
- End If
- End Function
-