VB使用API进行RC4加密解密(MD5密钥)
根据网络资料整改,来源未知,已调试通过.
Option Explicit
Private Declare Function CryptAcquireContext Lib "advapi32.dll" _
Alias "CryptAcquireContextA" ( _
ByRef phProv As Long, _
ByVal pszContainer As String, _
ByVal pszProvider As String, _
ByVal dwProvType As Long, _
ByVal dwFlags As Long) As Long Private Declare Function CryptReleaseContext Lib "advapi32.dll" ( _
ByVal hProv As Long, _
ByVal dwFlags As Long) As Long Private Declare Function CryptCreateHash Lib "advapi32.dll" ( _
ByVal hProv As Long, _
ByVal Algid As Long, _
ByVal hKey As Long, _
ByVal dwFlags As Long, _
ByRef phHash As Long) As Long Private Declare Function CryptDestroyHash Lib "advapi32.dll" ( _
ByVal hHash As Long) As Long Private Declare Function CryptHashData Lib "advapi32.dll" ( _
ByVal hHash As Long, _
pbData As Any, _
ByVal dwDataLen As Long, _
ByVal dwFlags As Long) As Long Private Declare Function CryptDeriveKey Lib "advapi32.dll" ( _
ByVal hProv As Long, _
ByVal Algid As Long, _
ByVal hBaseData As Long, _
ByVal dwFlags As Long, _
ByRef phKey As Long) As Long Private Declare Function CryptDestroyKey Lib "advapi32.dll" ( _
ByVal hKey As Long) As Long Private Declare Function CryptEncrypt Lib "advapi32.dll" ( _
ByVal hKey As Long, _
ByVal hHash As Long, _
ByVal Final As Long, _
ByVal dwFlags As Long, _
pbData As Any, _
ByRef pdwDataLen As Long, _
ByVal dwBufLen As Long) As Long Private Declare Function CryptDecrypt Lib "advapi32.dll" ( _
ByVal hKey As Long, _
ByVal hHash As Long, _
ByVal Final As Long, _
ByVal dwFlags As Long, _
pbData As Any, _
ByRef pdwDataLen As Long) As Long Private Declare Sub MoveMemory Lib "kernel32" Alias "RtlMoveMemory" ( _
Dest As Any, _
Src As Any, _
ByVal Ln As Long) Private Const PROV_RSA_FULL = Private Const CRYPT_NEWKEYSET = &H8 Private Const ALG_CLASS_HASH =
Private Const ALG_CLASS_DATA_ENCRYPT = & Private Const ALG_TYPE_ANY =
Private Const ALG_TYPE_BLOCK = &
Private Const ALG_TYPE_STREAM = & Private Const ALG_SID_MD2 =
Private Const ALG_SID_MD4 =
Private Const ALG_SID_MD5 =
Private Const ALG_SID_SHA1 = Private Const ALG_SID_DES =
Private Const ALG_SID_3DES =
Private Const ALG_SID_RC2 =
Private Const ALG_SID_RC4 =
Enum HASHALGORITHM
MD2 = ALG_CLASS_HASH Or ALG_TYPE_ANY Or ALG_SID_MD2
MD4 = ALG_CLASS_HASH Or ALG_TYPE_ANY Or ALG_SID_MD4
MD5 = ALG_CLASS_HASH Or ALG_TYPE_ANY Or ALG_SID_MD5
SHA1 = ALG_CLASS_HASH Or ALG_TYPE_ANY Or ALG_SID_SHA1
End Enum
Enum ENCALGORITHM
DES = ALG_CLASS_DATA_ENCRYPT Or ALG_TYPE_BLOCK Or ALG_SID_DES
[3DES] = ALG_CLASS_DATA_ENCRYPT Or ALG_TYPE_BLOCK Or ALG_SID_3DES
RC2 = ALG_CLASS_DATA_ENCRYPT Or ALG_TYPE_BLOCK Or ALG_SID_RC2
RC4 = ALG_CLASS_DATA_ENCRYPT Or ALG_TYPE_STREAM Or ALG_SID_RC4
End Enum Dim HexMatrix(, ) As Byte
'================================================
'加密
'================================================
Public Function EncryptString(ByVal str As String, password As String) As String
Dim byt() As Byte
Dim HASHALGORITHM As HASHALGORITHM
Dim ENCALGORITHM As ENCALGORITHM
byt = str
HASHALGORITHM = MD5
ENCALGORITHM = RC4
EncryptString = BytesToHex(Encrypt(byt, password, HASHALGORITHM, ENCALGORITHM))
End Function
Public Function EncryptByte(byt() As Byte, password As String) As Byte()
Dim HASHALGORITHM As HASHALGORITHM
Dim ENCALGORITHM As ENCALGORITHM
HASHALGORITHM = MD5
ENCALGORITHM = RC4
EncryptByte = Encrypt(byt, password, HASHALGORITHM, ENCALGORITHM)
End Function
Private Function Encrypt(data() As Byte, ByVal password As String, Optional ByVal HASHALGORITHM As HASHALGORITHM = MD5, Optional ByVal ENCALGORITHM As ENCALGORITHM = RC4) As Byte()
Dim lRes As Long
Dim hProv As Long
Dim hHash As Long
Dim hKey As Long
Dim lBufLen As Long
Dim lDataLen As Long
Dim abData() As Byte
lRes = CryptAcquireContext(hProv, vbNullString, vbNullString, PROV_RSA_FULL, )
If lRes = And Err.LastDllError = &H80090016 Then lRes = CryptAcquireContext(hProv, vbNullString, vbNullString, PROV_RSA_FULL, CRYPT_NEWKEYSET)
If lRes <> Then
lRes = CryptCreateHash(hProv, HASHALGORITHM, , , hHash)
If lRes <> Then
lRes = CryptHashData(hHash, ByVal password, Len(password), )
If lRes <> Then
lRes = CryptDeriveKey(hProv, ENCALGORITHM, hHash, , hKey)
If lRes <> Then
lBufLen = UBound(data) - LBound(data) +
lDataLen = lBufLen
lRes = CryptEncrypt(hKey, &, , , ByVal &, lBufLen, )
If lRes <> Then
If lBufLen < lDataLen Then lBufLen = lDataLen
ReDim abData( To lBufLen - )
MoveMemory abData(), data(LBound(data)), lDataLen
lRes = CryptEncrypt(hKey, &, , , abData(), lBufLen, lDataLen)
If lRes <> Then
If lDataLen <> lBufLen Then ReDim Preserve abData( To lBufLen - )
Encrypt = abData
End If
End If
End If
CryptDestroyKey hKey
End If
CryptDestroyHash hHash
End If
CryptReleaseContext hProv,
End If
If lRes = Then Err.Raise Err.LastDllError
End Function
'================================================
'解密
'================================================
Public Function DecryptString(ByVal str As String, password As String) As String
Dim byt() As Byte
Dim HASHALGORITHM As HASHALGORITHM
Dim ENCALGORITHM As ENCALGORITHM
byt = HexToBytes(str)
HASHALGORITHM = MD5
ENCALGORITHM = RC4
DecryptString = Decrypt(byt, password, HASHALGORITHM, ENCALGORITHM)
End Function
Public Function DecryptByte(byt() As Byte, password As String) As Byte()
Dim HASHALGORITHM As HASHALGORITHM
Dim ENCALGORITHM As ENCALGORITHM
HASHALGORITHM = MD5
ENCALGORITHM = RC4
DecryptByte = Decrypt(byt, password, HASHALGORITHM, ENCALGORITHM)
End Function
Private Function Decrypt(data() As Byte, ByVal password As String, Optional ByVal HASHALGORITHM As HASHALGORITHM = MD5, Optional ByVal ENCALGORITHM As ENCALGORITHM = RC4) As Byte()
Dim lRes As Long
Dim hProv As Long
Dim hHash As Long
Dim hKey As Long
Dim lBufLen As Long
Dim abData() As Byte
lRes = CryptAcquireContext(hProv, vbNullString, vbNullString, PROV_RSA_FULL, )
If lRes = And Err.LastDllError = &H80090016 Then lRes = CryptAcquireContext(hProv, vbNullString, vbNullString, PROV_RSA_FULL, CRYPT_NEWKEYSET)
If lRes <> Then
lRes = CryptCreateHash(hProv, HASHALGORITHM, , , hHash)
If lRes <> Then
lRes = CryptHashData(hHash, ByVal password, Len(password), )
If lRes <> Then
lRes = CryptDeriveKey(hProv, ENCALGORITHM, hHash, , hKey)
If lRes <> Then
lBufLen = UBound(data) - LBound(data) +
ReDim abData( To lBufLen - )
MoveMemory abData(), data(LBound(data)), lBufLen
lRes = CryptDecrypt(hKey, &, , , abData(), lBufLen)
If lRes <> Then
ReDim Preserve abData( To lBufLen - )
Decrypt = abData
End If
End If
CryptDestroyKey hKey
End If
CryptDestroyHash hHash
End If
CryptReleaseContext hProv,
End If
If lRes = Then Err.Raise Err.LastDllError
End Function '================================================
'字节与十六进制字符串的转换
'================================================
Public Function BytesToHex(bits() As Byte) As String
Dim i As Long
Dim b
Dim s As String
For Each b In bits
If b < Then
s = s & "" & Hex(b)
Else
s = s & Hex(b)
End If
Next
BytesToHex = s
End Function
Public Function HexToBytes(sHex As String) As Byte()
Dim b() As Byte
Dim rst() As Byte
Dim i As Long
Dim n As Long
Dim m1 As Byte
Dim m2 As Byte
If HexMatrix(, ) = Then Call MatrixInitialize
b = StrConv(sHex, vbFromUnicode)
i = (UBound(b) + ) / -
ReDim rst(i)
For i = To UBound(b) Step
If b(i) > Then
m1 = b(i) -
ElseIf b(i) > Then
m1 = b(i) -
ElseIf b(i) > Then
m1 = b(i) -
End If
If b(i + ) > Then
m2 = b(i + ) -
ElseIf b(i + ) > Then
m2 = b(i + ) -
ElseIf b(i + ) > Then
m2 = b(i + ) -
End If
rst(n) = HexMatrix(m1, m2)
n = n +
Next i
HexToBytes = rst
End Function
Private Sub MatrixInitialize()
HexMatrix(, ) = &H0: HexMatrix(, ) = &H1: HexMatrix(, ) = &H2: HexMatrix(, ) = &H3: HexMatrix(, ) = &H4: HexMatrix(, ) = &H5: HexMatrix(, ) = &H6: HexMatrix(, ) = &H7
HexMatrix(, ) = &H8: HexMatrix(, ) = &H9: HexMatrix(, ) = &HA: HexMatrix(, ) = &HB: HexMatrix(, ) = &HC: HexMatrix(, ) = &HD: HexMatrix(, ) = &HE: HexMatrix(, ) = &HF
HexMatrix(, ) = &H10: HexMatrix(, ) = &H11: HexMatrix(, ) = &H12: HexMatrix(, ) = &H13: HexMatrix(, ) = &H14: HexMatrix(, ) = &H15: HexMatrix(, ) = &H16: HexMatrix(, ) = &H17
HexMatrix(, ) = &H18: HexMatrix(, ) = &H19: HexMatrix(, ) = &H1A: HexMatrix(, ) = &H1B: HexMatrix(, ) = &H1C: HexMatrix(, ) = &H1D: HexMatrix(, ) = &H1E: HexMatrix(, ) = &H1F
HexMatrix(, ) = &H20: HexMatrix(, ) = &H21: HexMatrix(, ) = &H22: HexMatrix(, ) = &H23: HexMatrix(, ) = &H24: HexMatrix(, ) = &H25: HexMatrix(, ) = &H26: HexMatrix(, ) = &H27
HexMatrix(, ) = &H28: HexMatrix(, ) = &H29: HexMatrix(, ) = &H2A: HexMatrix(, ) = &H2B: HexMatrix(, ) = &H2C: HexMatrix(, ) = &H2D: HexMatrix(, ) = &H2E: HexMatrix(, ) = &H2F
HexMatrix(, ) = &H30: HexMatrix(, ) = &H31: HexMatrix(, ) = &H32: HexMatrix(, ) = &H33: HexMatrix(, ) = &H34: HexMatrix(, ) = &H35: HexMatrix(, ) = &H36: HexMatrix(, ) = &H37
HexMatrix(, ) = &H38: HexMatrix(, ) = &H39: HexMatrix(, ) = &H3A: HexMatrix(, ) = &H3B: HexMatrix(, ) = &H3C: HexMatrix(, ) = &H3D: HexMatrix(, ) = &H3E: HexMatrix(, ) = &H3F
HexMatrix(, ) = &H40: HexMatrix(, ) = &H41: HexMatrix(, ) = &H42: HexMatrix(, ) = &H43: HexMatrix(, ) = &H44: HexMatrix(, ) = &H45: HexMatrix(, ) = &H46: HexMatrix(, ) = &H47
HexMatrix(, ) = &H48: HexMatrix(, ) = &H49: HexMatrix(, ) = &H4A: HexMatrix(, ) = &H4B: HexMatrix(, ) = &H4C: HexMatrix(, ) = &H4D: HexMatrix(, ) = &H4E: HexMatrix(, ) = &H4F
HexMatrix(, ) = &H50: HexMatrix(, ) = &H51: HexMatrix(, ) = &H52: HexMatrix(, ) = &H53: HexMatrix(, ) = &H54: HexMatrix(, ) = &H55: HexMatrix(, ) = &H56: HexMatrix(, ) = &H57
HexMatrix(, ) = &H58: HexMatrix(, ) = &H59: HexMatrix(, ) = &H5A: HexMatrix(, ) = &H5B: HexMatrix(, ) = &H5C: HexMatrix(, ) = &H5D: HexMatrix(, ) = &H5E: HexMatrix(, ) = &H5F
HexMatrix(, ) = &H60: HexMatrix(, ) = &H61: HexMatrix(, ) = &H62: HexMatrix(, ) = &H63: HexMatrix(, ) = &H64: HexMatrix(, ) = &H65: HexMatrix(, ) = &H66: HexMatrix(, ) = &H67
HexMatrix(, ) = &H68: HexMatrix(, ) = &H69: HexMatrix(, ) = &H6A: HexMatrix(, ) = &H6B: HexMatrix(, ) = &H6C: HexMatrix(, ) = &H6D: HexMatrix(, ) = &H6E: HexMatrix(, ) = &H6F
HexMatrix(, ) = &H70: HexMatrix(, ) = &H71: HexMatrix(, ) = &H72: HexMatrix(, ) = &H73: HexMatrix(, ) = &H74: HexMatrix(, ) = &H75: HexMatrix(, ) = &H76: HexMatrix(, ) = &H77
HexMatrix(, ) = &H78: HexMatrix(, ) = &H79: HexMatrix(, ) = &H7A: HexMatrix(, ) = &H7B: HexMatrix(, ) = &H7C: HexMatrix(, ) = &H7D: HexMatrix(, ) = &H7E: HexMatrix(, ) = &H7F
HexMatrix(, ) = &H80: HexMatrix(, ) = &H81: HexMatrix(, ) = &H82: HexMatrix(, ) = &H83: HexMatrix(, ) = &H84: HexMatrix(, ) = &H85: HexMatrix(, ) = &H86: HexMatrix(, ) = &H87
HexMatrix(, ) = &H88: HexMatrix(, ) = &H89: HexMatrix(, ) = &H8A: HexMatrix(, ) = &H8B: HexMatrix(, ) = &H8C: HexMatrix(, ) = &H8D: HexMatrix(, ) = &H8E: HexMatrix(, ) = &H8F
HexMatrix(, ) = &H90: HexMatrix(, ) = &H91: HexMatrix(, ) = &H92: HexMatrix(, ) = &H93: HexMatrix(, ) = &H94: HexMatrix(, ) = &H95: HexMatrix(, ) = &H96: HexMatrix(, ) = &H97
HexMatrix(, ) = &H98: HexMatrix(, ) = &H99: HexMatrix(, ) = &H9A: HexMatrix(, ) = &H9B: HexMatrix(, ) = &H9C: HexMatrix(, ) = &H9D: HexMatrix(, ) = &H9E: HexMatrix(, ) = &H9F
HexMatrix(, ) = &HA0: HexMatrix(, ) = &HA1: HexMatrix(, ) = &HA2: HexMatrix(, ) = &HA3: HexMatrix(, ) = &HA4: HexMatrix(, ) = &HA5: HexMatrix(, ) = &HA6: HexMatrix(, ) = &HA7
HexMatrix(, ) = &HA8: HexMatrix(, ) = &HA9: HexMatrix(, ) = &HAA: HexMatrix(, ) = &HAB: HexMatrix(, ) = &HAC: HexMatrix(, ) = &HAD: HexMatrix(, ) = &HAE: HexMatrix(, ) = &HAF
HexMatrix(, ) = &HB0: HexMatrix(, ) = &HB1: HexMatrix(, ) = &HB2: HexMatrix(, ) = &HB3: HexMatrix(, ) = &HB4: HexMatrix(, ) = &HB5: HexMatrix(, ) = &HB6: HexMatrix(, ) = &HB7
HexMatrix(, ) = &HB8: HexMatrix(, ) = &HB9: HexMatrix(, ) = &HBA: HexMatrix(, ) = &HBB: HexMatrix(, ) = &HBC: HexMatrix(, ) = &HBD: HexMatrix(, ) = &HBE: HexMatrix(, ) = &HBF
HexMatrix(, ) = &HC0: HexMatrix(, ) = &HC1: HexMatrix(, ) = &HC2: HexMatrix(, ) = &HC3: HexMatrix(, ) = &HC4: HexMatrix(, ) = &HC5: HexMatrix(, ) = &HC6: HexMatrix(, ) = &HC7
HexMatrix(, ) = &HC8: HexMatrix(, ) = &HC9: HexMatrix(, ) = &HCA: HexMatrix(, ) = &HCB: HexMatrix(, ) = &HCC: HexMatrix(, ) = &HCD: HexMatrix(, ) = &HCE: HexMatrix(, ) = &HCF
HexMatrix(, ) = &HD0: HexMatrix(, ) = &HD1: HexMatrix(, ) = &HD2: HexMatrix(, ) = &HD3: HexMatrix(, ) = &HD4: HexMatrix(, ) = &HD5: HexMatrix(, ) = &HD6: HexMatrix(, ) = &HD7
HexMatrix(, ) = &HD8: HexMatrix(, ) = &HD9: HexMatrix(, ) = &HDA: HexMatrix(, ) = &HDB: HexMatrix(, ) = &HDC: HexMatrix(, ) = &HDD: HexMatrix(, ) = &HDE: HexMatrix(, ) = &HDF
HexMatrix(, ) = &HE0: HexMatrix(, ) = &HE1: HexMatrix(, ) = &HE2: HexMatrix(, ) = &HE3: HexMatrix(, ) = &HE4: HexMatrix(, ) = &HE5: HexMatrix(, ) = &HE6: HexMatrix(, ) = &HE7
HexMatrix(, ) = &HE8: HexMatrix(, ) = &HE9: HexMatrix(, ) = &HEA: HexMatrix(, ) = &HEB: HexMatrix(, ) = &HEC: HexMatrix(, ) = &HED: HexMatrix(, ) = &HEE: HexMatrix(, ) = &HEF
HexMatrix(, ) = &HF0: HexMatrix(, ) = &HF1: HexMatrix(, ) = &HF2: HexMatrix(, ) = &HF3: HexMatrix(, ) = &HF4: HexMatrix(, ) = &HF5: HexMatrix(, ) = &HF6: HexMatrix(, ) = &HF7
HexMatrix(, ) = &HF8: HexMatrix(, ) = &HF9: HexMatrix(, ) = &HFA: HexMatrix(, ) = &HFB: HexMatrix(, ) = &HFC: HexMatrix(, ) = &HFD: HexMatrix(, ) = &HFE: HexMatrix(, ) = &HFF
End Sub
测试代码:
Private Sub Command1_Click()
Dim bs() As Byte, be() As Byte, bd() As Byte
bs = StrConv("", vbFromUnicode)
be = EncryptByte(bs, "password")
bd = DecryptByte(be, "password")
Dim s1 As String, s2 As String, s3 As String
s1 = BytesToHex(bs)
s2 = BytesToHex(be)
s3 = BytesToHex(bd)
Print "原始字节:" & s1 & " (len:" & Len(s1) / & ")"
Print "加密字节:" & s2 & " (len:" & Len(s2) & ")"
Print "解密字节:" & s3 & " (len:" & Len(s3) & ")"
Print "--------------------------------"
Dim ss As String, se As String, sd As String
ss = "MD5加/解密"
se = EncryptString(ss, "password")
sd = DecryptString(se, "password")
Print "原文:" & ss & " (len:" & LenB(ss) & ")"
Print "加密:" & se & " (len:" & Len(se) & ")"
Print "解密:" & sd & " (len:" & LenB(sd) & ")"
End Sub

VB使用API进行RC4加密解密(MD5密钥)的更多相关文章
- RC4加密解密算法
RC4相对是速度快.安全性高的加密算法.在实际应用中,我们可以对安全系数要求高的文本进行多重加密,这样破解就有一定困难了.如下测试给出了先用RC4加密,然后再次用BASE64编码,这样双重锁定,保证数 ...
- DES加密解密 MD5加密解密
#region MD5 加密 /// <summary> /// MD5加密静态方法 /// </summary> /// <param name="Encry ...
- [C#]加密解密 MD5、AES
/// <summary> /// MD5函数 /// </summary> /// <param name="str">原始字符串</p ...
- java RC4加密解密
package com.dgut.app.utils; import java.lang.Byte; import java.util.UUID; public class RC4 { public ...
- RC4加密解密
package util; public class RC4Util { public static String decry_RC4(byte[] data, String key) { if (d ...
- C#加密解密(DES,AES,Base64,md5,SHA256,RSA,RC4)
一:异或^简单加解密(数字类型) 1:原理: 异或用于比较两个二进制数的相应位,在执行按位"异或"运算时,如果两个二进制数的相应位都为1或者都为0,则返回0;如果两个二进制数的相应 ...
- .net Xml加密解密操作
生成密钥的方法: /// <summary>生成RSA加密 解密的 密钥 /// 生成的key就是 方法EncryptByRSA与DecryptByRSA用的key了 /// </s ...
- 用C#实现DES加密解密解决URL参数明文的问题
啥也不说,直接上代码. 加密解码,封装到一个类,key可以自己修改. using System; using System.Security.Cryptography; using System.Te ...
- C# 对密码等数据进行对称性加密解密
类: /// <summary> /// DESEncrypt加密解密算法. /// </summary> public class DESEncrypt { private ...
随机推荐
- chrome浏览器开发常用快捷键之基础篇-遁地龙卷风
1.标签页和窗口快捷键 打开新的标签页,并跳转到该标签页 Ctrl + t 重新打开最后关闭的标签页,并跳转到该标签页 Ctrl + Shift + t 跳转到下一个打开的标签页 Ctrl + PgD ...
- HTML required
required required属性表明该控件为必填项.required特性可用于任何类型的输入元素.required属性是布尔类型属性,无需专门把它设置为true,只需将它添加到标签中即可.一个表 ...
- 423 重温Java Script and jQuery 葵花宝典 Bootstrap
Bootstrap需要引的三个文件 <link rel="stylesheet" href="css/bootstrap.css"> 表格元素 ...
- RandomAccessFile出现中文乱码问题
之前程序里调用了RandomAccessFile的writeByte(String str)方法,报文里存在中文的时候出现了乱码 后面换成了 write(byte b[])或writeBytes(by ...
- pythonのdjango select_related 和 prefetch_related()
在数据库有外键的时候,使用select_related() 和 prefetch_related() 可以很好的减少数据库请求次数,从而提高性能. (1)select_related()当执行它的查询 ...
- [Kubernetes]基于角色的权限控制之RBAC
Kubernetes中有很多种内置的编排对象,此外还可以自定义API资源类型和控制器的编写方式.那么,我能不能自己写一个编排对象呢?答案是肯定的.而这,也正是Kubernetes项目最具吸引力的地方. ...
- 机器学习基石11-Linear Models for Classification
注: 文章中所有的图片均来自台湾大学林轩田<机器学习基石>课程. 笔记原作者:红色石头 微信公众号:AI有道 上一节课,我们介绍了Logistic Regression问题,建立cross ...
- MinGW GCC 8.3.1 2019年2月23日 出炉啦
GNU 2019-02-22 发布了 GCC 8.3 https://gcc.gnu.org/onlinedocs/8.3.0/ 有详细的说明 MinGW 上可用的 GCC 8.3.1 版本下载地址 ...
- 【easy】572. Subtree of Another Tree
判断一棵树中是否包含另一棵子树(包含是,两棵树重合处的根节点之下的子节点都相等) 有两种方法: 方法二:递归写法 //方法一:可以借鉴之前序列化的题目,如果序列化得到的序列一样就是相同的树 //方法二 ...
- c++入门篇七
拷贝构造函数的调用时机: class Person { public: //构造函数 Person() { //无参构造函数 } Person(int a) { //有参构造函数 cout <& ...