home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / mirage / mirage.exe / %MAINDIR% / Sample / Form1.frm (.txt) next >
Encoding:
Visual Basic Form  |  1999-02-07  |  6.8 KB  |  214 lines

  1. VERSION 5.00
  2. Object = "{C9E83EE3-7D8C-11D2-9906-444553540000}#1.0#0"; "MIRAGE.OCX"
  3. Begin VB.Form Form1 
  4.    Caption         =   "Mirage Sample Application"
  5.    ClientHeight    =   2040
  6.    ClientLeft      =   60
  7.    ClientTop       =   348
  8.    ClientWidth     =   5640
  9.    LinkTopic       =   "Form1"
  10.    ScaleHeight     =   2040
  11.    ScaleWidth      =   5640
  12.    StartUpPosition =   3  'Windows Default
  13.    Begin MIRAGELib.Mirage Mirage1 
  14.       Left            =   1920
  15.       Top             =   1560
  16.       _Version        =   65536
  17.       _ExtentX        =   423
  18.       _ExtentY        =   423
  19.       _StockProps     =   0
  20.    End
  21.    Begin VB.ComboBox Combo1 
  22.       Height          =   288
  23.       ItemData        =   "Form1.frx":0000
  24.       Left            =   960
  25.       List            =   "Form1.frx":000D
  26.       Sorted          =   -1  'True
  27.       TabIndex        =   7
  28.       Text            =   "CFB"
  29.       Top             =   1560
  30.       Width           =   855
  31.    End
  32.    Begin VB.TextBox Text4 
  33.       Enabled         =   0   'False
  34.       Height          =   285
  35.       Left            =   960
  36.       TabIndex        =   6
  37.       Top             =   1200
  38.       Width           =   4575
  39.    End
  40.    Begin VB.TextBox Text3 
  41.       Enabled         =   0   'False
  42.       Height          =   285
  43.       Left            =   960
  44.       TabIndex        =   5
  45.       Top             =   840
  46.       Width           =   4575
  47.    End
  48.    Begin VB.TextBox Text2 
  49.       Height          =   285
  50.       Left            =   960
  51.       TabIndex        =   4
  52.       Text            =   "1234567890"
  53.       Top             =   480
  54.       Width           =   4575
  55.    End
  56.    Begin VB.CommandButton Decrypt 
  57.       Caption         =   "&Decrypt"
  58.       Height          =   375
  59.       Left            =   3480
  60.       TabIndex        =   3
  61.       Top             =   1560
  62.       Width           =   975
  63.    End
  64.    Begin VB.TextBox Text1 
  65.       Height          =   285
  66.       Left            =   960
  67.       TabIndex        =   2
  68.       Text            =   "This is the data."
  69.       Top             =   120
  70.       Width           =   4575
  71.    End
  72.    Begin VB.CommandButton Encrypt 
  73.       Caption         =   "&Encrypt"
  74.       Height          =   375
  75.       Left            =   2400
  76.       TabIndex        =   1
  77.       Top             =   1560
  78.       Width           =   975
  79.    End
  80.    Begin VB.CommandButton Quit 
  81.       Caption         =   "&Quit"
  82.       Default         =   -1  'True
  83.       Height          =   375
  84.       Left            =   4560
  85.       TabIndex        =   0
  86.       Top             =   1560
  87.       Width           =   975
  88.    End
  89.    Begin VB.Label Label5 
  90.       Alignment       =   1  'Right Justify
  91.       Caption         =   "Method:"
  92.       Height          =   372
  93.       Left            =   120
  94.       TabIndex        =   12
  95.       Top             =   1560
  96.       Width           =   732
  97.    End
  98.    Begin VB.Label Label4 
  99.       Alignment       =   1  'Right Justify
  100.       Caption         =   "Decrypted:"
  101.       Height          =   252
  102.       Left            =   0
  103.       TabIndex        =   11
  104.       Top             =   1200
  105.       Width           =   852
  106.    End
  107.    Begin VB.Label Label3 
  108.       Alignment       =   1  'Right Justify
  109.       Caption         =   "Encrypted:"
  110.       Height          =   252
  111.       Left            =   0
  112.       TabIndex        =   10
  113.       Top             =   840
  114.       Width           =   852
  115.    End
  116.    Begin VB.Label Label2 
  117.       Alignment       =   1  'Right Justify
  118.       Caption         =   "Key:"
  119.       Height          =   252
  120.       Left            =   -120
  121.       TabIndex        =   9
  122.       Top             =   480
  123.       Width           =   972
  124.    End
  125.    Begin VB.Label Label1 
  126.       Alignment       =   1  'Right Justify
  127.       Caption         =   "Data:"
  128.       Height          =   252
  129.       Left            =   120
  130.       TabIndex        =   8
  131.       Top             =   120
  132.       Width           =   732
  133.    End
  134. Attribute VB_Name = "Form1"
  135. Attribute VB_GlobalNameSpace = False
  136. Attribute VB_Creatable = False
  137. Attribute VB_PredeclaredId = True
  138. Attribute VB_Exposed = False
  139. Option Explicit
  140. Private Function StringToMode(ByVal Mode As String)
  141.     Select Case UCase(Mode)
  142.         Case "ECB"
  143.             StringToMode = MIRAGE_MODE_ECB
  144.         Case "CFB"
  145.             StringToMode = MIRAGE_MODE_CFB
  146.         Case "CBC"
  147.             StringToMode = MIRAGE_MODE_CBC
  148.         Case Else
  149.             StringToMode = -1
  150.     End Select
  151. End Function
  152. Private Sub Decrypt_Click()
  153.     Dim Key As String
  154.     Dim ret As String
  155.     Dim Data As String
  156.     Dim Mode As Integer
  157.     Mode = StringToMode(Combo1.Text)
  158.     Key = Mirage1.StrToHex(Text2.Text, Len(Text2.Text))
  159.     Data = Mirage1.HexToStr(Text3.Text, Len(Text3.Text))
  160.     If (DataLengthOK(Mode, Data)) Then
  161.         If (KeyLengthOK(Text2.Text)) Then
  162.             ret = Mirage1.Decrypt(Data, Len(Data), Key, MIRAGE_TWOFISH, Mode)
  163.                    
  164.             If Len(Data) <> Len(ret) Then
  165.                 Debug.Print "Error occurred."
  166.             End If
  167.             
  168.             Text4.Text = ret
  169.             
  170.         End If
  171.     End If
  172. End Sub
  173. Private Sub Encrypt_Click()
  174.     Dim Key As String
  175.     Dim ret As String
  176.     Dim Data As String
  177.     Dim Mode As Integer
  178.     Mode = StringToMode(Combo1.Text)
  179.     Key = Mirage1.StrToHex(Text2.Text, Len(Text2.Text))
  180.     If (DataLengthOK(Mode, Text1.Text)) Then
  181.         If (KeyLengthOK(Text2.Text)) Then
  182.             ret = Mirage1.Encrypt(Text1.Text, Len(Text1.Text), Key, 0, Mode)
  183.             Data = Mirage1.StrToHex(ret, Len(ret))
  184.             Text3.Text = Data
  185.         
  186.         End If
  187.     End If
  188. End Sub
  189. Private Sub Quit_Click()
  190.     Unload Me
  191. End Sub
  192. Private Function DataLengthOK(Mode As Integer, Data As String) As Boolean
  193.     '  This function checks a passed string (Data) for length requirements.
  194.     '  This function could be changed to pad the data to fit the requirements
  195.     '  instead of displaying an error.
  196.     DataLengthOK = 1
  197.     If (Mode <> MIRAGE_MODE_CFB) Then
  198.         If Len(Data) Mod 16 <> 0 Then
  199.             MsgBox "CBC and ECB encryption require that the input block be a multiple of the block size (16 Characters)", vbOKOnly, "Mirage Sample Application"
  200.             DataLengthOK = 0
  201.         End If
  202.     End If
  203. End Function
  204. Private Function KeyLengthOK(Key As String) As Boolean
  205.     '  This function checks a passed string (Key) for length requirements.
  206.     '  This function could be changed to pad or trim the key to fit the requirements
  207.     '  instead of displaying an error.
  208.     KeyLengthOK = 1
  209.     If (Len(Key) < 9) Or (Len(Key) > 32) Then
  210.         MsgBox "Key length must be between 9 and 32 characters.", vbOKOnly, "Mirage Sample Application"
  211.         KeyLengthOK = 0
  212.     End If
  213. End Function
  214.