📄 mwactivex.ctl
字号:
VERSION 5.00
Begin VB.UserControl MWactiveX
ClientHeight = 900
ClientLeft = 0
ClientTop = 0
ClientWidth = 1710
ClipBehavior = 0 '无
ControlContainer= -1 'True
InvisibleAtRuntime= -1 'True
Picture = "MWactiveX.ctx":0000
ScaleHeight = 900
ScaleWidth = 1710
ToolboxBitmap = "MWactiveX.ctx":1A4C
End
Attribute VB_Name = "MWactiveX"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
'***********************************************************
'* *
'* MWActiveX.ocx集成明华SmartCOS3.2版本 *
'* 开发人:周建平 *
'* 开发时间:2000年9月10日起 *
'* *
'***********************************************************
Public Enum geUser_CreateFileType
geU_CreateMF
geU_CreateDF
geU_CreateEF
geU_CreateEndMF
geU_CreateEndDF
End Enum
Public Enum geUser_ComType
geU_Com1 = 0
geU_com2
End Enum
Public Enum geUser_baudType
geU_Baud9600 = 9600
geU_Baud1440 = 14400
geU_Baud19200 = 19200
geU_Baud28800 = 28800
End Enum
'此枚举类型定义随机数的类型(4字节和8字节)
Public Enum geUser_RandomType
geU_Random4
geU_Random8
End Enum
Public Enum geUser_SelectType
geU_SelectMF
geU_SelectMFName
geU_SelectDF
geU_SelectDFName
geU_SelectEF
End Enum
Public Enum geUser_UpdateType
geU_Data
geU_DataMac
End Enum
Public Enum geUser_ApplicationType
geU_TempKey8
geU_ForeverKey8
geU_TempKey16
geU_ForeverKey16
End Enum
Public Enum geUser_WriteKeyType
geU_WordInstall
geu_WordEdit
geU_EncryptInstall
geU_EncryptEdit
geU_OUTKEY_EncryptInstall
End Enum
Public Enum geUser_BusinessType '交易类型
geU_Bankbook
geU_Purse
End Enum
Public Enum geUser_RSAKeyType
geU_64BitKey = &H8
geU_128BitKey = &H10
geU_256BitKey = &H20
geU_512BitKey = &H40
geU_1024BitKey = &H80
End Enum
Public Enum geUser_ProofType
geU_Read = &H0
geU_Clean = &H1
End Enum
Public Function Asc_To_Hex(psInputString As String, pbOutputByte As Byte, piByteLength As Integer) As Boolean
gsErrHint = ""
giRet = asc_hex(psInputString, pbOutputByte, piByteLength)
If giRet <> 0 Then
gsErrHint = "转换错误."
Exit Function
End If
Asc_To_Hex = True
End Function
Public Function Hex_To_Asc(pbInputByte As Byte, pbOutString As String, piByteLength As Integer) As Boolean
gsErrHint = ""
Dim psTemp As String * 200
giRet = hex_asc(pbInputByte, psTemp, piByteLength)
If giRet <> 0 Then
gsErrHint = "转换错误."
Exit Function
End If
pbOutString = Left(psTemp, piByteLength * 2)
Hex_To_Asc = True
End Function
Public Function ChineseString_DoubleByte(psInputString As String, pbWrite() As Byte) As Boolean
'此函数完成字符串到字节变量的赋值,其中把每个字符串用2个字节来存储,做到字母与汉字存储的统一.
'如串"中国123",占10个字节;串"12345",占10个字节.
For i = 1 To Len(psInputString)
pbWrite((i - 1) * 2) = Val("&H" + Mid(Format(hex(asc(Mid(psInputString, i, 1))), "0000"), 1, 2))
pbWrite((i - 1) * 2 + 1) = Val("&H" + Mid(Format(hex(asc(Mid(psInputString, i, 1))), "0000"), 3, 2))
Next i
ChineseString_DoubleByte = True
End Function
Public Function DoubleByte_ChineseString(psOutputString As String, pbRead() As Byte, piLength As Integer) As Boolean
'此函数完成字节变量到字符串的转换,其中每2个字节为一个字符串.
'piLength为字节总长度,是psOutputString长度的2倍.
psOutputString = ""
For i = 1 To piLength / 2
psOutputString = psOutputString + Chr(Val("&H" + (hex(pbRead((i - 1) * 2)) + hex(pbRead((i - 1) * 2 + 1)))))
Next i
DoubleByte_ChineseString = True
End Function
Private Sub UserControl_Terminate()
giRet = ic_exit(glIcdev)
End Sub
Public Property Get Errshow() As String
Errshow = gsErrHint
End Property
Public Property Get handle() As Long
handle = glIcdev
End Property
Public Function Com_Open(piCom As geUser_ComType, plBaud As geUser_baudType) As Boolean
gsErrHint = ""
glIcdev = auto_init(piCom, plBaud)
If glIcdev <= 0 Then
gsErrHint = "连接端口错误."
Exit Function
End If
Com_Open = True
End Function
Public Function Com_Close() As Boolean
gsErrHint = ""
giRet = ic_exit(glIcdev)
If giRet <> 0 Then
gsErrHint = "关闭端口错误."
Exit Function
End If
Com_Close = True
End Function
Public Function Reset(psReturn As String) As Boolean
'当没有建ATR文件时,缺省返回16个字节.
'如果建ATR文件,则长度不能超过OBH个字节.
gsErrHint = ""
giRet = CpuA_Reset(glIcdev, gbOutput(0))
If giRet <> 0 Then
gsErrHint = "CPU卡复位错误."
Exit Function
End If
giRet = hex_asc(gbOutput(0), gsHex, 16)
psReturn = Mid(gsHex, 1, 32)
Reset = True
End Function
Public Function Sam_Reset(psReturn As String) As Boolean
'当没有建ATR文件时,缺省返回16个字节.
'如果建ATR文件,则长度不能超过OBH个字节.
gsErrHint = ""
giRet = SamA_Reset(glIcdev, giLength, gbOutput(0))
If giRet <> 0 Then
gsErrHint = "SAM卡复位错误."
Exit Function
End If
giRet = hex_asc(gbOutput(0), gsHex, 16)
psReturn = Mid(gsHex, 1, 32)
Sam_Reset = True
End Function
Public Function Delete(psTransferCode As String) As Boolean
'psTransferCode 16个字符的传输代码.
gsErrHint = ""
gbInput(0) = &H0 'nad
gbInput(1) = &H40 'pcb
gbInput(2) = &HD 'length
gbInput(3) = &H80 'cla
gbInput(4) = &HE 'ins
gbInput(5) = &H0 'p1
gbInput(6) = &H0 'p2
gbInput(7) = &H8 'le
giRet = asc_hex(psTransferCode, gbInput(8), 8)
'For i = 8 To 15
' gbInput(i) = &HFF
'Next i
gbInput(16) = &H0
For i = 0 To 15
gbInput(16) = gbInput(i) Xor gbInput(16) 'bcc calculation
Next i
giRet = cpu_protocol(glIcdev, 17, gbInput(0), gbOutput(0))
If giRet <> 0 Then
gsErrHint = "上卡座卡删除错误."
Exit Function
End If
giLength = gbOutput(2)
giRet = hex_asc(gbOutput(0), gsHex, giLength + 3)
If Not Get_Result(gsHex, giLength) Then
gsErrHint = "上卡座卡删除错误,ERROR NO:" + gsErrorNO
Exit Function
End If
Delete = True
End Function
Public Function Sam_Delete(psTransferCode As String) As Boolean
'psTransferCode 16个字符的传输代码.
gsErrHint = ""
gbInput(0) = &H0 'nad
gbInput(1) = &H40 'pcb
gbInput(2) = &HD 'length
gbInput(3) = &H80 'cla
gbInput(4) = &HE 'ins
gbInput(5) = &H0 'p1
gbInput(6) = &H0 'p2
gbInput(7) = &H8 'le
giRet = asc_hex(psTransferCode, gbInput(8), 8)
'For i = 8 To 15
' gbInput(i) = &HFF
'Next i
gbInput(16) = &H0
For i = 0 To 15
gbInput(16) = gbInput(i) Xor gbInput(16) 'bcc calculation
Next i
giRet = sam_protocol(glIcdev, 17, gbInput(0), gbOutput(0))
If giRet <> 0 Then
gsErrHint = "下卡座卡删除错误."
Exit Function
End If
giLength = gbOutput(2)
giRet = hex_asc(gbOutput(0), gsHex, giLength + 3)
If Not Get_Result(gsHex, giLength) Then
gsErrHint = "下卡座卡删除错误,ERROR NO:" + gsErrorNO
Exit Function
End If
Sam_Delete = True
End Function
Public Function Get_Challenge(peLength As geUser_RandomType, pbRandom() As Byte) As Boolean
gsErrHint = ""
If peLength = geU_Random4 Then
gbInput(0) = &H0 'nad
gbInput(1) = &H40 'pcb
gbInput(2) = &H5 'length
gbInput(3) = &H0 'cla
gbInput(4) = &H84 'ins
gbInput(5) = &H0 'p1
gbInput(6) = &H0 'p2
gbInput(7) = &H4 'le
gbInput(8) = &H0
For i = 0 To 7
gbInput(8) = gbInput(i) Xor gbInput(8) 'bcc calculation
Next i
giRet = cpu_protocol(glIcdev, 9, gbInput(0), gbOutput(0))
If giRet <> 0 Then
gsErrHint = "产生随机数错误."
Exit Function
End If
giLength = gbOutput(2)
giRet = hex_asc(gbOutput(0), gsHex, giLength + 3)
If Not Get_Result(gsHex, giLength) Then
gsErrHint = "产生随机数错误,ERROR NO:" + gsErrorNO
Exit Function
End If
pbRandom(0) = gbOutput(3)
pbRandom(1) = gbOutput(4)
pbRandom(2) = gbOutput(5)
pbRandom(3) = gbOutput(6)
End If
If peLength = geU_Random8 Then
gbInput(0) = &H0 'nad
gbInput(1) = &H40 'pcb
gbInput(2) = &H5 'length
gbInput(3) = &H0 'cla
gbInput(4) = &H84 'ins
gbInput(5) = &H0 'p1
gbInput(6) = &H0 'p2
gbInput(7) = &H8 'le
gbInput(8) = &H0
For i = 0 To 7
gbInput(8) = gbInput(i) Xor gbInput(8) 'bcc calculation
Next i
giRet = cpu_protocol(glIcdev, 9, gbInput(0), gbOutput(0))
If giRet <> 0 Then
gsErrHint = "产生随机数错误."
Exit Function
End If
giLength = gbOutput(2)
giRet = hex_asc(gbOutput(0), gsHex, giLength + 3)
If Not Get_Result(gsHex, giLength) Then
gsErrHint = "产生随机数错误,ERROR NO:" + gsErrorNO
Exit Function
End If
pbRandom(0) = gbOutput(3)
pbRandom(1) = gbOutput(4)
pbRandom(2) = gbOutput(5)
pbRandom(3) = gbOutput(6)
pbRandom(4) = gbOutput(7)
pbRandom(5) = gbOutput(8)
pbRandom(6) = gbOutput(9)
pbRandom(7) = gbOutput(10)
End If
Get_Challenge = True
End Function
Public Function Sam_Get_Challenge(peLength As geUser_RandomType, pbRandom() As Byte) As Boolean
gsErrHint = ""
If peLength = geU_Random4 Then
gbInput(0) = &H0 'nad
gbInput(1) = &H40 'pcb
gbInput(2) = &H5 'length
gbInput(3) = &H0 'cla
gbInput(4) = &H84 'ins
gbInput(5) = &H0 'p1
gbInput(6) = &H0 'p2
gbInput(7) = &H4 'le
gbInput(8) = &H0
For i = 0 To 7
gbInput(8) = gbInput(i) Xor gbInput(8) 'bcc calculation
Next i
giRet = sam_protocol(glIcdev, 9, gbInput(0), gbOutput(0))
If giRet <> 0 Then
gsErrHint = "产生随机数错误."
Exit Function
End If
giLength = gbOutput(2)
giRet = hex_asc(gbOutput(0), gsHex, giLength + 3)
If Not Get_Result(gsHex, giLength) Then
gsErrHint = "产生随机数错误,ERROR NO:" + gsErrorNO
Exit Function
End If
pbRandom(0) = gbOutput(3)
pbRandom(1) = gbOutput(4)
pbRandom(2) = gbOutput(5)
pbRandom(3) = gbOutput(6)
End If
If peLength = geU_Random8 Then
gbInput(0) = &H0 'nad
gbInput(1) = &H40 'pcb
gbInput(2) = &H5 'length
gbInput(3) = &H0 'cla
gbInput(4) = &H84 'ins
gbInput(5) = &H0 'p1
gbInput(6) = &H0 'p2
gbInput(7) = &H8 'le
gbInput(8) = &H0
For i = 0 To 7
gbInput(8) = gbInput(i) Xor gbInput(8) 'bcc calculation
Next i
giRet = sam_protocol(glIcdev, 9, gbInput(0), gbOutput(0))
If giRet <> 0 Then
gsErrHint = "产生随机数错误."
Exit Function
End If
giLength = gbOutput(2)
giRet = hex_asc(gbOutput(0), gsHex, giLength + 3)
If Not Get_Result(gsHex, giLength) Then
gsErrHint = "产生随机数错误,ERROR NO:" + gsErrorNO
Exit Function
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -