⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mwactivex.ctl

📁 中国石化IC开发程序
💻 CTL
📖 第 1 页 / 共 5 页
字号:
    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
Sam_Get_Challenge = True
End Function

Public Function Select_File(piSelectFile As geUser_SelectType, psFileID As String) As Boolean
'当按文件标识选择DF,EF时,psFileID为两个字节的文件标识符,用字符串来传递,psFileID如"0015".
'当按文件名称选择MF或DF时,psFileID为MF名称或DF名称.
gsErrHint = ""
If piSelectFile = geU_SelectDF Then
    gbInput(0) = &H0        'nad
    gbInput(1) = &H40       'pcb
    gbInput(2) = &H7        'length
    gbInput(3) = &H0        'cla
    gbInput(4) = &HA4       'ins
    gbInput(5) = &H0        'p1
    gbInput(6) = &H0        'p2
    gbInput(7) = &H2        'le
    gbInput(8) = Val("&H" + Mid(psFileID, 1, 2))
    gbInput(9) = Val("&H" + Mid(psFileID, 3, 2))
    gbInput(10) = 0
    For i = 0 To 9
        gbInput(10) = gbInput(i) Xor gbInput(10)     'bcc calculation
    Next i
    giRet = cpu_protocol(glIcdev, 11, gbInput(0), gbOutput(0))
    If giRet <> 0 Then
         gsErrHint = "选择DF文件错误."
         Exit Function
    End If
    giLength = gbOutput(2)
    giRet = hex_asc(gbOutput(0), gsHex, giLength + 3)
    If Not Get_Result(gsHex, giLength) Then
        gsErrHint = "选择DF文件错误,ERROR NO:" + gsErrorNO
        Exit Function
    End If
End If
If piSelectFile = geU_SelectEF Then
    gbInput(0) = &H0        'nad
    gbInput(1) = &H40       'pcb
    gbInput(2) = &H7        'length
    gbInput(3) = &H0        'cla
    gbInput(4) = &HA4       'ins
    gbInput(5) = &H2         'p1
    gbInput(6) = &H0        'p2
    gbInput(7) = &H2        'le
    gbInput(8) = Val("&H" + Mid(psFileID, 1, 2))
    gbInput(9) = Val("&H" + Mid(psFileID, 3, 2))
    gbInput(10) = 0
    For i = 0 To 9
        gbInput(10) = gbInput(i) Xor gbInput(10)     'bcc calculation
    Next i
    giRet = cpu_protocol(glIcdev, 11, gbInput(0), gbOutput(0))
    If giRet <> 0 Then
         gsErrHint = "选择EF文件错误."
         Exit Function
    End If
    giLength = gbOutput(2)
    giRet = hex_asc(gbOutput(0), gsHex, giLength + 3)
    If Not Get_Result(gsHex, giLength) Then
        gsErrHint = "选择EF文件错误,ERROR NO:" + gsErrorNO
        Exit Function
    End If
End If
If piSelectFile = geU_SelectMF Then
    gbInput(0) = &H0        'nad
    gbInput(1) = &H40       'pcb
    gbInput(2) = &H7        'length
    gbInput(3) = &H0        'cla
    gbInput(4) = &HA4       'ins
    gbInput(5) = &H0         'p1
    gbInput(6) = &H0         'p2
    gbInput(7) = &H2        'le
    gbInput(8) = &H3F
    gbInput(9) = &H0
    gbInput(10) = 0
    For i = 0 To 9
        gbInput(10) = gbInput(i) Xor gbInput(10)     'bcc calculation
    Next i
    giRet = cpu_protocol(glIcdev, 11, gbInput(0), gbOutput(0))
    If giRet <> 0 Then
         gsErrHint = "选择MF文件错误."
         Exit Function
    End If
    giLength = gbOutput(2)
    giRet = hex_asc(gbOutput(0), gsHex, giLength + 3)
    If Not Get_Result(gsHex, giLength) Then
        gsErrHint = "选择MF文件错误,ERROR NO:" + gsErrorNO
        Exit Function
    End If
End If
If piSelectFile = geU_SelectMFName Then
    gbInput(0) = &H0        'nad
    gbInput(1) = &H40       'pcb
    gbInput(2) = Len(psFileID) \ 2 + 5       'length
    gbInput(3) = &H0        'cla
    gbInput(4) = &HA4       'ins
    gbInput(5) = &H4          'p1
    gbInput(6) = &H0         'p2
    gbInput(7) = Len(psFileID) \ 2       'le
    giRet = asc_hex(psFileID, gbInput(8), Len(psFileID) \ 2)
    gbInput(8 + Len(psFileID) \ 2) = 0
    For i = 0 To 8 + Len(psFileID) \ 2 - 1
        gbInput(8 + Len(psFileID) \ 2) = gbInput(i) Xor gbInput(8 + Len(psFileID) \ 2)     'bcc calculation
    Next i
    giRet = cpu_protocol(glIcdev, 8 + Len(psFileID) \ 2 + 1, gbInput(0), gbOutput(0))
    If giRet <> 0 Then
         gsErrHint = "选择MF文件错误."
         Exit Function
    End If
    giLength = gbOutput(2)
    giRet = hex_asc(gbOutput(0), gsHex, giLength + 3)
    If Not Get_Result(gsHex, giLength) Then
        gsErrHint = "选择MF文件错误,ERROR NO:" + gsErrorNO
        Exit Function
    End If
End If
If piSelectFile = geU_SelectDFName Then
    gbInput(0) = &H0        'nad
    gbInput(1) = &H40       'pcb
    gbInput(2) = Len(psFileID) \ 2 + 5       'length
    gbInput(3) = &H0        'cla
    gbInput(4) = &HA4       'ins
    gbInput(5) = &H4          'p1
    gbInput(6) = &H0         'p2
    gbInput(7) = Len(psFileID) \ 2       'le
    giRet = asc_hex(psFileID, gbInput(8), Len(psFileID) \ 2)
    gbInput(8 + Len(psFileID) \ 2) = 0
    For i = 0 To 8 + Len(psFileID) \ 2 - 1
        gbInput(8 + Len(psFileID) \ 2) = gbInput(i) Xor gbInput(8 + Len(psFileID) \ 2)     'bcc calculation
    Next i
    giRet = cpu_protocol(glIcdev, 8 + Len(psFileID) \ 2 + 1, gbInput(0), gbOutput(0))
    If giRet <> 0 Then
         gsErrHint = "选择DF文件错误."
         Exit Function
    End If
    giLength = gbOutput(2)
    giRet = hex_asc(gbOutput(0), gsHex, giLength + 3)
    If Not Get_Result(gsHex, giLength) Then
        gsErrHint = "选择DF文件错误,ERROR NO:" + gsErrorNO
        Exit Function
    End If
End If
Select_File = True
End Function

Public Function Sam_Select_File(piSelectFile As geUser_SelectType, psFileID As String) As Boolean
'当选择DF,EF时,psFileID为两个字节的文件标识符,用字符串来传递,psFileID如"0015".
gsErrHint = ""
If piSelectFile = geU_SelectDF Then
    gbInput(0) = &H0        'nad
    gbInput(1) = &H40       'pcb
    gbInput(2) = &H7        'length
    gbInput(3) = &H0        'cla
    gbInput(4) = &HA4       'ins
    gbInput(5) = &H0        'p1
    gbInput(6) = &H0        'p2
    gbInput(7) = &H2        'le
    gbInput(8) = Val("&H" + Mid(psFileID, 1, 2))
    gbInput(9) = Val("&H" + Mid(psFileID, 3, 2))
    gbInput(10) = 0
    For i = 0 To 9
        gbInput(10) = gbInput(i) Xor gbInput(10)     'bcc calculation
    Next i
    giRet = sam_protocol(glIcdev, 11, gbInput(0), gbOutput(0))
    If giRet <> 0 Then
         gsErrHint = "选择DF文件错误."
         Exit Function
    End If
    giLength = gbOutput(2)
    giRet = hex_asc(gbOutput(0), gsHex, giLength + 3)
    If Not Get_Result(gsHex, giLength) Then
        gsErrHint = "选择DF文件错误,ERROR NO:" + gsErrorNO
        Exit Function
    End If
End If
If piSelectFile = geU_SelectEF Then
    gbInput(0) = &H0        'nad
    gbInput(1) = &H40       'pcb
    gbInput(2) = &H7        'length
    gbInput(3) = &H0        'cla
    gbInput(4) = &HA4       'ins
    gbInput(5) = &H2         'p1
    gbInput(6) = &H0        'p2
    gbInput(7) = &H2        'le
    gbInput(8) = Val("&H" + Mid(psFileID, 1, 2))
    gbInput(9) = Val("&H" + Mid(psFileID, 3, 2))
    gbInput(10) = 0
    For i = 0 To 9
        gbInput(10) = gbInput(i) Xor gbInput(10)     'bcc calculation
    Next i
    giRet = sam_protocol(glIcdev, 11, gbInput(0), gbOutput(0))
    If giRet <> 0 Then
         gsErrHint = "选择EF文件错误."
         Exit Function
    End If
    giLength = gbOutput(2)
    giRet = hex_asc(gbOutput(0), gsHex, giLength + 3)
    If Not Get_Result(gsHex, giLength) Then
        gsErrHint = "选择EF文件错误,ERROR NO:" + gsErrorNO
        Exit Function
    End If
End If
If piSelectFile = geU_SelectMF Then
    gbInput(0) = &H0        'nad
    gbInput(1) = &H40       'pcb
    gbInput(2) = &H7        'length
    gbInput(3) = &H0        'cla
    gbInput(4) = &HA4       'ins
    gbInput(5) = &H0         'p1
    gbInput(6) = &H0         'p2
    gbInput(7) = &H2        'le
    gbInput(8) = &H3F
    gbInput(9) = &H0
    gbInput(10) = 0
    For i = 0 To 9
        gbInput(10) = gbInput(i) Xor gbInput(10)     'bcc calculation
    Next i
    giRet = sam_protocol(glIcdev, 11, gbInput(0), gbOutput(0))
    If giRet <> 0 Then
         gsErrHint = "选择MF文件错误."
         Exit Function
    End If
    giLength = gbOutput(2)
    giRet = hex_asc(gbOutput(0), gsHex, giLength + 3)
    If Not Get_Result(gsHex, giLength) Then
        gsErrHint = "选择MF文件错误,ERROR NO:" + gsErrorNO
        Exit Function
    End If
End If
If piSelectFile = geU_SelectMFName Then
    gbInput(0) = &H0        'nad
    gbInput(1) = &H40       'pcb
    gbInput(2) = Len(psFileID) \ 2 + 5       'length
    gbInput(3) = &H0        'cla
    gbInput(4) = &HA4       'ins
    gbInput(5) = &H4          'p1
    gbInput(6) = &H0         'p2
    gbInput(7) = Len(psFileID) \ 2       'le
    giRet = asc_hex(psFileID, gbInput(8), Len(psFileID) \ 2)
    gbInput(8 + Len(psFileID) \ 2) = 0
    For i = 0 To 8 + Len(psFileID) \ 2 - 1
        gbInput(8 + Len(psFileID) \ 2) = gbInput(i) Xor gbInput(8 + Len(psFileID) \ 2)     'bcc calculation
    Next i
    giRet = sam_protocol(glIcdev, 8 + Len(psFileID) \ 2 + 1, gbInput(0), gbOutput(0))
    If giRet <> 0 Then
         gsErrHint = "选择MF文件错误."
         Exit Function
    End If
    giLength = gbOutput(2)
    giRet = hex_asc(gbOutput(0), gsHex, giLength + 3)
    If Not Get_Result(gsHex, giLength) Then
        gsErrHint = "选择MF文件错误,ERROR NO:" + gsErrorNO
        Exit Function
    End If
End If
If piSelectFile = geU_SelectDFName Then
    gbInput(0) = &H0        'nad
    gbInput(1) = &H40       'pcb
    gbInput(2) = Len(psFileID) \ 2 + 5       'length
    gbInput(3) = &H0        'cla
    gbInput(4) = &HA4       'ins
    gbInput(5) = &H4          'p1
    gbInput(6) = &H0         'p2
    gbInput(7) = Len(psFileID) \ 2       'le
    giRet = asc_hex(psFileID, gbInput(8), Len(psFileID) \ 2)
    gbInput(8 + Len(psFileID) \ 2) = 0
    For i = 0 To 8 + Len(psFileID) \ 2 - 1
        gbInput(8 + Len(psFileID) \ 2) = gbInput(i) Xor gbInput(8 + Len(psFileID) \ 2)     'bcc calculation
    Next i
    giRet = sam_protocol(glIcdev, 8 + Len(psFileID) \ 2 + 1, gbInput(0), gbOutput(0))
    If giRet <> 0 Then
         gsErrHint = "选择DF文件错误."
         Exit Function
    End If
    giLength = gbOutput(2)
    giRet = hex_asc(gbOutput(0), gsHex, giLength + 3)
    If Not Get_Result(gsHex, giLength) Then
        gsErrHint = "选择DF文件错误,ERROR NO:" + gsErrorNO
        Exit Function
    End If
End If
Sam_Select_File = True
End Function

Public Function External_Authentication(psKeyID As String, pbInEncrypt() As Byte) As Boolean
'psKeyID 为外部认证密钥的标识符,1个字节的字符串数据,如:"01".
'pbInEncrype 为加密后的随机数,取前8字节.
gsErrHint = ""
gbInput(0) = &H0        'nad
gbInput(1) = &H40       'pcb
gbInput(2) = &HD        'length
gbInput(3) = &H0        'cla
gbInput(4) = &H82       'ins
gbInput(5) = &H0        'p1
gbInput(6) = Val("&H" + psKeyID)     'p2
gbInput(7) = &H8        'le
gbInput(8) = pbInEncrypt(0)
gbInput(9) = pbInEncrypt(1)
gbInput(10) = pbInEncrypt(2)
gbInput(11) = pbInEncrypt(3)
gbInput(12) = pbInEncrypt(4)
gbInput(13) = pbInEncrypt(5)
gbInput(14) = pbInEncrypt(6)
gbInput(15) = pbInEncrypt(7)
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
External_Authentication = True
End Function

Public Function Sam_External_Authentication(psKeyID As String, pbInEncrypt() As Byte) As Boolean
'psKeyID 为外部认证密钥的标识符,1个字节的字符串数据,如:"01".
'pbInEncrype 为加密后的随机数,取前8字节.
gsErrHint = ""
gbInput(0) = &H0        'nad
gbInput(1) = &H40       'pcb
gbInput(2) = &HD        'length
gbInput(3) = &H0        'cla
gbInput(4) = &H82       'ins
gbInput(5) = &H0        'p1
gbInput(6) = Val("&H" + psKeyID)     'p2
gbInput(7) = &H8        'le
gbInput(8) = pbInEncrypt(0)
gbInput(9) = pbInEncrypt(1)
gbInput(10) = pbInEncrypt(2)
gbInput(11) = pbInEncrypt(3)
gbInput(12) = pbInEncrypt(4)
gbInput(13) = pbInEncrypt(5)
gbInput(14) = pbInEncrypt(6)
gbInput(15) = pbInEncrypt(7)
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_External_Authentication = True
End Function

Public Function Internal_Authentication(psKeyID As String, pbInRandom() As Byte, pbOutEncrypt() As Byte) As Boolean
'psKeyID 为内部认证密钥的标识符,1个字节的字符串数据,如:"01".
'pbInRandom 从接口设备发来的8字节的随机数,取前8字节.
'pbOutEncrypt 返回的加密数据,取前8字节.
gsErrHint = ""
gbInput(0) = &H0        'nad
gbInput(1) = &H40       'pcb
gbInput(2) = &HD        'length
gbInput(3) = &H0        'cla
gbInput(4) = &H88       'ins
gbInput(5) = &H0        'p1
gbInput(6) = Val("&H" + psKeyID)     'p2
gbInput(7) = &H8        'le
gbInput(8) = pbInRandom(0)
gbInput(9) = pbInRandom(1)
gbInput(10) = pbInRandom(2)
gbInput(11) = pbInRandom(3)
gbInput(12) = pbInRandom(4)
gbInput(13) = pbInRandom(5)
gbInput(14) = pbInRandom(6)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -