📄 form1.frm
字号:
VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.1#0"; "COMDLG32.OCX"
Begin VB.Form Form1
Caption = "AES字符加密例程"
ClientHeight = 7755
ClientLeft = 7080
ClientTop = 2010
ClientWidth = 8640
LinkTopic = "Form1"
ScaleHeight = 7755
ScaleWidth = 8640
Begin MSComDlg.CommonDialog CommonDialog1
Left = 7440
Top = 4680
_ExtentX = 847
_ExtentY = 847
_Version = 327681
End
Begin VB.CommandButton Command4
Caption = "选择要解密的文件进行解密"
Height = 495
Left = 4680
TabIndex = 18
Top = 5400
Width = 2535
End
Begin VB.CommandButton Command3
Caption = "选择文件进行加密"
Height = 495
Left = 4680
TabIndex = 17
Top = 4680
Width = 2535
End
Begin VB.OptionButton Option4
Caption = "128位"
Enabled = 0 'False
Height = 375
Left = 5160
TabIndex = 16
Top = 360
Value = -1 'True
Width = 855
End
Begin VB.TextBox Text2
Height = 1695
Left = 120
Locked = -1 'True
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 12
Top = 4560
Width = 4095
End
Begin VB.Frame Frame1
Caption = "密钥设置"
Height = 1215
Left = 240
TabIndex = 6
Top = 240
Width = 8295
Begin VB.TextBox Text1
Height = 375
Left = 1320
TabIndex = 10
Text = "password"
Top = 600
Width = 1935
End
Begin VB.OptionButton Option3
Caption = "256位"
Height = 375
Left = 2640
TabIndex = 9
Top = 120
Width = 855
End
Begin VB.OptionButton Option2
Caption = "192位"
Height = 375
Left = 1800
TabIndex = 8
Top = 120
Width = 975
End
Begin VB.OptionButton Option1
Caption = "128位"
Height = 375
Left = 960
TabIndex = 7
Top = 120
Value = -1 'True
Width = 855
End
Begin VB.Label Label6
Caption = "分组长度"
Height = 255
Left = 4080
TabIndex = 15
Top = 240
Width = 975
End
Begin VB.Label Label5
Caption = "密钥长度"
Height = 255
Left = 120
TabIndex = 14
Top = 240
Width = 855
End
Begin VB.Label Label3
Caption = "输入密钥"
Height = 255
Left = 240
TabIndex = 11
Top = 720
Width = 1215
End
End
Begin VB.CommandButton Command2
Caption = "字符串解密"
Height = 375
Left = 120
TabIndex = 3
Top = 6360
Width = 1215
End
Begin VB.TextBox txtShow
Height = 1695
Left = 120
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 2
Top = 1920
Width = 3975
End
Begin VB.CommandButton Command1
Caption = "字符加密"
Height = 375
Left = 120
TabIndex = 1
Top = 3720
Width = 1215
End
Begin VB.TextBox txtDisp
Height = 1695
Left = 4320
Locked = -1 'True
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 0
Top = 1920
Width = 4095
End
Begin MSComDlg.CommonDialog CommonDialog2
Left = 7440
Top = 5400
_ExtentX = 847
_ExtentY = 847
_Version = 327681
End
Begin VB.Label Label4
Caption = "解密后的字符串"
Height = 255
Left = 240
TabIndex = 13
Top = 4200
Width = 1695
End
Begin VB.Label Label2
Caption = "加密后字符串显示区"
Height = 255
Left = 4680
TabIndex = 5
Top = 1560
Width = 1935
End
Begin VB.Label Label1
Caption = "源字符串"
Height = 255
Left = 240
TabIndex = 4
Top = 1560
Width = 735
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click()
Dim Temp() As Byte
Dim strInfo As String
Dim i As Integer, J As Integer, intK As Integer
Dim key_len As BlockLength, block_len As BlockLength
strInfo = ""
If Option1.Value = True Then
block_len = BlockLength.Bits128
ElseIf Option2.Value = True Then
block_len = BlockLength.Bits192
ElseIf Option3.Value = True Then
block_len = BlockLength.Bits256
End If
If Option4.Value = True Then
key_len = BlockLength.Bits128
End If
strInfo = AES_Str_Encyrpt(txtShow.Text, Text1.Text, block_len, block_len) '加密字符串
'strInfo = AES_Str_Encyrpt(txtShow.Text, Text1.Text, BlockLength.Bits256, BlockLength.Bits128) '加密字符串
'For i = 0 To UBound(Temp)
' strInfo = strInfo + Hex(Temp(i)) + " "
' If i Mod 15 = 0 And i <> 0 Then strInfo = strInfo + Chr(13) + Chr(10)
'Next i
txtDisp.Text = strInfo
End Sub
Private Sub Command2_Click()
Dim Str1 As String, Str2 As String
Dim key_len As BlockLength, block_len As BlockLength
Str1 = ""
If Option1.Value = True Then
key_len = BlockLength.Bits128
ElseIf Option2.Value = True Then
key_len = BlockLength.Bits192
ElseIf Option3.Value = True Then
key_len = BlockLength.Bits256
End If
If Option4.Value = True Then
block_len = BlockLength.Bits128
End If
Str1 = AES_Str_Decyrpt(txtDisp.Text, Text1.Text, key_len, key_len)
'Str1 = EncodeBase64String(Str1)
If Str1 <> "" Then
Text2.Text = Str1
Else: Text2.Text = txtShow.Text
End If
End Sub
Private Sub Command3_Click() '加密文件
CommonDialog1.InitDir = "f:\" '设置初始化目录
CommonDialog1.FileName = "*.txt"
CommonDialog1.Filter = "要加密的文本文件(*.txt)|*.txt"
CommonDialog1.FilterIndex = 1
CommonDialog1.DialogTitle = "加密文件"
CommonDialog1.Action = 1
Dim file_str As String, jiami_str As String, file_name As String
jiami_str = ""
file_str = ""
file_name = CommonDialog1.FileName
If file_name <> "*.txt" Then
Open file_name For Input As #1
Do While Not EOF(1)
Input #1, file_str
jiami_str = jiami_str & file_str
Loop
Close #1
'---------------------加密选择的文件中的内容------------------------
Dim key_len As BlockLength, block_len As BlockLength
If Option1.Value = True Then
key_len = BlockLength.Bits128
ElseIf Option2.Value = True Then
key_len = BlockLength.Bits192
ElseIf Option3.Value = True Then
key_len = BlockLength.Bits256
End If
If Option4.Value = True Then
block_len = BlockLength.Bits128
End If
Dim strInfo As String
strInfo = ""
strInfo = AES_Str_Encyrpt(jiami_str, Text1.Text, key_len, block_len) '加密文件中的字符串
file_name = file_name & "_aes"
Open file_name For Output As #1
Print #1, strInfo
Close
MsgBox "文件" & file_name & "已经加密成功"
End If
End Sub
Private Sub Command4_Click() '解密文件
CommonDialog2.InitDir = "f:\" '设置初始化目录
CommonDialog2.FileName = "*.txt_aes"
CommonDialog2.Filter = "AES加密文件(*.txt_aes)|*.txt_aes"
CommonDialog2.FilterIndex = 1
CommonDialog2.DialogTitle = "解密文件"
Dim file_str As String, jiemi_str As String, file_name As String
jiemi_str = ""
file_str = ""
CommonDialog2.Action = 1
file_name = CommonDialog2.FileName
If file_name <> "*.txt_aes" Then
Open file_name For Input As #1
Do While Not EOF(1)
Input #1, file_str
jiemi_str = jiemi_str & file_str
Loop
Close #1
'---------------------解密选择的文件中的内容------------------------
Dim key_len As BlockLength, block_len As BlockLength
If Option1.Value = True Then
key_len = BlockLength.Bits128
ElseIf Option2.Value = True Then
key_len = BlockLength.Bits192
ElseIf Option3.Value = True Then
key_len = BlockLength.Bits256
End If
If Option4.Value = True Then
block_len = BlockLength.Bits128
End If
'------------------------------------------------------------------
Dim strInfo As String
strInfo = ""
strInfo = AES_Str_Decyrpt(jiemi_str, Text1.Text, key_len, block_len) '加密文件中的字符串
file_name = file_name & "AES解密文件"
Open file_name For Output As #1
Print #1, strInfo
Close
MsgBox "文件" & file_name & "已经解密成功"
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -