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

📄 mwactivex.ctl

📁 中国石化IC开发程序
💻 CTL
📖 第 1 页 / 共 5 页
字号:
If (piI < 8) Then
    psTemp = psTemp + "80"
    piI = piI + 1
End If
Do While piI < 8                                         '开始补"00"
    psTemp = psTemp + "00"
    piI = piI + 1
Loop
giRet = asc_hex(psTemp, pbTemp(0), 8)

giRet = asc_hex(Mid(psSpin, 1, 16), pbKeyA(0), 8)
giRet = asc_hex(Mid(psSpin, 17, 16), pbKeyB(0), 8)

giRet = ic_encrypt(pbKeyA(0), pbTemp(0), 8, pbExdest(0))
giRet = ic_decrypt(pbKeyB(0), pbExdest(0), 8, pbTemp(0))
giRet = ic_encrypt(pbKeyA(0), pbTemp(0), 8, pbExdest(0))
giRet = Get_Challenge(geU_Random4, pbRandom())
pbRandom(4) = 0
pbRandom(5) = 0
pbRandom(6) = 0
pbRandom(7) = 0
              
pbTemp(0) = &H84
pbTemp(1) = &H24
pbTemp(2) = &H0
pbTemp(3) = &H1
pbTemp(4) = 4 + 8
For i = 0 To 7
    pbTemp(5 + i) = pbExdest(i)
Next i

giRet = asc_hex(psSpin, pbSpin(0), 16)
giRet = Mac_encrypt(pbSpin(), pbRandom(), pbTemp(), 8 + 5, pbMac())

gbInput(0) = &H0        'nad
gbInput(1) = &H40       'pcb
gbInput(2) = &H11       'length
gbInput(3) = &H84       'cla
gbInput(4) = &H24       'ins
gbInput(5) = &H0        'p1
gbInput(6) = &H1        'p2
gbInput(7) = &HC
For i = 0 To 7
    gbInput(8 + i) = pbExdest(i)
Next i
For i = 0 To 3
    gbInput(16 + i) = pbMac(i)
Next i
gbInput(20) = &H0
For i = 0 To 19
    gbInput(20) = gbInput(i) Xor gbInput(20)     'bcc calculation
Next i
giRet = cpu_protocol(glIcdev, 21, 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
PIN_Unblock = True
End Function

Public Function Sam_PIN_Unblock(psPin As String, psSpin As String) As Boolean
'psPin 此处解锁密码为16个字节.为8个字节时的程序没做.
Dim pbMac(4) As Byte
Dim pbSpin(16) As Byte
Dim psTemp As String
Dim pbTemp(100) As Byte
Dim pbExdest(100) As Byte
Dim piI As Integer
Dim pbKeyA(8) As Byte
Dim pbKeyB(8) As Byte
Dim pbRandom(8) As Byte
gsErrHint = ""
psTemp = "0" + CStr(Len(psPin) / 2) + psPin
piI = Len(psPin) / 2 + 1                                 '如果不到8个字节,开始补"80"
If (piI < 8) Then
    psTemp = psTemp + "80"
    piI = piI + 1
End If
Do While piI < 8                                         '开始补"00"
    psTemp = psTemp + "00"
    piI = piI + 1
Loop
giRet = asc_hex(psTemp, pbTemp(0), 8)

giRet = asc_hex(Mid(psSpin, 1, 16), pbKeyA(0), 8)
giRet = asc_hex(Mid(psSpin, 17, 16), pbKeyB(0), 8)

giRet = ic_encrypt(pbKeyA(0), pbTemp(0), 8, pbExdest(0))
giRet = ic_decrypt(pbKeyB(0), pbExdest(0), 8, pbTemp(0))
giRet = ic_encrypt(pbKeyA(0), pbTemp(0), 8, pbExdest(0))
giRet = Sam_Get_Challenge(geU_Random4, pbRandom())
pbRandom(4) = 0
pbRandom(5) = 0
pbRandom(6) = 0
pbRandom(7) = 0
              
pbTemp(0) = &H84
pbTemp(1) = &H24
pbTemp(2) = &H0
pbTemp(3) = &H1
pbTemp(4) = 4 + 8
For i = 0 To 7
    pbTemp(5 + i) = pbExdest(i)
Next i

giRet = asc_hex(psSpin, pbSpin(0), 16)
giRet = Mac_encrypt(pbSpin(), pbRandom(), pbTemp(), 8 + 5, pbMac())

gbInput(0) = &H0        'nad
gbInput(1) = &H40       'pcb
gbInput(2) = &H11       'length
gbInput(3) = &H84       'cla
gbInput(4) = &H24       'ins
gbInput(5) = &H0        'p1
gbInput(6) = &H1        'p2
gbInput(7) = &HC
For i = 0 To 7
    gbInput(8 + i) = pbExdest(i)
Next i
For i = 0 To 3
    gbInput(16 + i) = pbMac(i)
Next i
gbInput(20) = &H0
For i = 0 To 19
    gbInput(20) = gbInput(i) Xor gbInput(20)     'bcc calculation
Next i
giRet = sam_protocol(glIcdev, 21, 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_PIN_Unblock = True
End Function

Public Function Reload_PIN(psPin As String, psRpin As String) As Boolean
'psPin 要修改的密码,为2-6个字节的字符串,一定为偶数个字符串.
'psRpin PIN重装子密码,为16个字节的字符串,32个字符串.
Dim psTemp As String
Dim psMac As String
gsErrHint = ""
psTemp = psPin
giRet = asc_hex(psRpin, gbInput(0), 16)
For i = 0 To 7
    gbInput(i) = gbInput(i) Xor gbInput(i + 8)
Next i
giRet = hex_asc(gbInput(0), gsHex, 8)
psMac = MAC(1, gsHex, 16, psTemp, Len(psTemp))

gbInput(0) = &H0        'nad
gbInput(1) = &H40       'pcb
gbInput(2) = CByte(Len(psPin) / 2 + 9)   'length
gbInput(3) = &H80       'cla
gbInput(4) = &H5E       'ins
gbInput(5) = &H0        'p1
gbInput(6) = &H0        'p2
gbInput(7) = CByte(Len(psPin) / 2 + 4)
giRet = asc_hex(psPin, gbInput(8), Len(psPin) / 2)
giRet = asc_hex(psMac, gbInput(8 + Len(psPin) / 2), 4)
gbInput(12 + Len(psPin) / 2) = &H0
For i = 0 To 11 + Len(psPin) / 2
    gbInput(12 + Len(psPin) / 2) = gbInput(i) Xor gbInput(12 + Len(psPin) / 2)     'bcc calculation
Next i
giRet = cpu_protocol(glIcdev, 13 + Len(psPin) / 2, 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
Reload_PIN = True
End Function

Public Function Sam_Reload_PIN(psPin As String, psRpin As String) As Boolean
'psPin 要修改的密码,为2-6个字节的字符串,一定为偶数个字符串.
'psRpin PIN重装子密码,为16个字节的字符串,32个字符串.
Dim psTemp As String
Dim psMac As String
gsErrHint = ""
psTemp = psPin
giRet = asc_hex(psRpin, gbInput(0), 16)
For i = 0 To 7
    gbInput(i) = gbInput(i) Xor gbInput(i + 8)
Next i
giRet = hex_asc(gbInput(0), gsHex, 8)
psMac = Sam_MAC(1, gsHex, 16, psTemp, Len(psTemp))

gbInput(0) = &H0        'nad
gbInput(1) = &H40       'pcb
gbInput(2) = CByte(Len(psPin) / 2 + 9)   'length
gbInput(3) = &H80       'cla
gbInput(4) = &H5E       'ins
gbInput(5) = &H0        'p1
gbInput(6) = &H0        'p2
gbInput(7) = CByte(Len(psPin) / 2 + 4)
giRet = asc_hex(psPin, gbInput(8), Len(psPin) / 2)
giRet = asc_hex(psMac, gbInput(8 + Len(psPin) / 2), 4)
gbInput(12 + Len(psPin) / 2) = &H0
For i = 0 To 11 + Len(psPin) / 2
    gbInput(12 + Len(psPin) / 2) = gbInput(i) Xor gbInput(12 + Len(psPin) / 2)     'bcc calculation
Next i
giRet = sam_protocol(glIcdev, 13 + Len(psPin) / 2, 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_Reload_PIN = True
End Function

Public Function Create_File(peType As geUser_CreateFileType, psFileInfo As String) As Boolean
'psFileInfo '在建立文件时为文件信息字符串;
'            在结束MF文件建立时为空;
'            在结束DF文件建立时为FID.
gsErrHint = ""
Select Case peType
    Case geU_CreateMF
        gbInput(0) = &H0        'nad
        gbInput(1) = &H40       'pcb
        gbInput(2) = Len(psFileInfo) / 2 + 5      'length
        gbInput(3) = &H80       'cla
        gbInput(4) = &HE0       'ins
        gbInput(5) = &H0        'p1
        gbInput(6) = &H0        'p2
        gbInput(7) = Len(psFileInfo) / 2     'lc
        giRet = asc_hex(psFileInfo, gbInput(8), Len(psFileInfo) / 2)
        gbInput(8 + Len(psFileInfo) / 2) = &H0
        For i = 0 To 7 + Len(psFileInfo) / 2
            gbInput(8 + Len(psFileInfo) / 2) = gbInput(i) Xor gbInput(8 + Len(psFileInfo) / 2)     'bcc calculation
        Next i
        giRet = cpu_protocol(glIcdev, 9 + Len(psFileInfo) / 2, 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
    Case geU_CreateDF
        gbInput(0) = &H0        'nad
        gbInput(1) = &H40       'pcb
        gbInput(2) = Len(psFileInfo) / 2 + 5      'length
        gbInput(3) = &H80       'cla
        gbInput(4) = &HE0       'ins
        gbInput(5) = &H1         'p1
        gbInput(6) = &H0        'p2
        gbInput(7) = Len(psFileInfo) / 2     'lc
        giRet = asc_hex(psFileInfo, gbInput(8), Len(psFileInfo) / 2)
        gbInput(8 + Len(psFileInfo) / 2) = &H0
        For i = 0 To 7 + Len(psFileInfo) / 2
            gbInput(8 + Len(psFileInfo) / 2) = gbInput(i) Xor gbInput(8 + Len(psFileInfo) / 2)     'bcc calculation
        Next i
        giRet = cpu_protocol(glIcdev, 9 + Len(psFileInfo) / 2, 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
    Case geU_CreateEF
        gbInput(0) = &H0        'nad
        gbInput(1) = &H40       'pcb
        gbInput(2) = 7 + 5      'length
        gbInput(3) = &H80       'cla
        gbInput(4) = &HE0       'ins
        gbInput(5) = &H2         'p1
        gbInput(6) = &H0        'p2
        gbInput(7) = 7    'lc
        giRet = asc_hex(psFileInfo, gbInput(8), Len(psFileInfo) / 2)
        gbInput(8 + Len(psFileInfo) / 2) = &H0
        For i = 0 To 7 + Len(psFileInfo) / 2
            gbInput(8 + Len(psFileInfo) / 2) = gbInput(i) Xor gbInput(8 + Len(psFileInfo) / 2)     'bcc calculation
        Next i
        giRet = cpu_protocol(glIcdev, 9 + Len(psFileInfo) / 2, 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
    Case geU_CreateEndMF
        gbInput(0) = &H0        'nad
        gbInput(1) = &H40       'pcb
        gbInput(2) = &H7          'length
        gbInput(3) = &H80       'cla
        gbInput(4) = &HE0       'ins
        gbInput(5) = &H0         'p1
        gbInput(6) = &H1         'p2
        gbInput(7) = &H2         'lc
        gbInput(8) = &H3F
        gbInput(9) = &H0
        gbInput(10) = &H0
        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
    Case geU_CreateEndDF
        gbInput(0) = &H0        'nad
        gbInput(1) = &H40       'pcb
        gbInput(2) = &H7          'length
        gbInput(3) = &H80       'cla
        gbInput(4) = &HE0       'ins
        gbInput(5) = &H1          'p1
        gbInput(6) = &H1         'p2
        gbInput(7) = &H2         'lc
        gbInput(8) = Val("&H" + Mid(psFileInfo, 1, 2))
        gbInput(9) = Val("&H" + Mid(psFileInfo, 3, 2))
        gbInput(10) = &H0
        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 Select
Create_File = True
End Function

Public Function Sam_Create_File(peType As geUser_CreateFileType, psFileInfo As String) As Boolean
'psFileInfo '在建立文件时为文件信息字符串;
'            在结束MF文件建立时为空;
'            在结束DF文件建立时为FID.
gsErrHint = ""
Select Case peType
    Case geU_CreateMF
        gbInput(0) = &H0        'nad
        gbInput(1) = &H40       'pcb
        gbInput(2) = Len(psFileInfo) / 2 + 5      'length
        gbInput(3) = &H80       'cla
        gbInput(4) = &HE0       'ins
        gbInput(5) = &H0        'p1
        gbInput(6) = &H0        'p2
        gbInput(7) = Len(psFileInfo) / 2     'lc
        giRet = asc_hex(psFileInfo, gbInput(8), Len(psFileInfo) / 2)
        gbInput(8 + Len(psFileInfo) / 2) = &H0
        For i = 0 To 7 + Len(psFileInfo) / 2
            gb

⌨️ 快捷键说明

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