VB6批量修改IC卡全部扇区密钥源码

本示例使用设备: Android Linux RFID读写器NFC发卡器WEB可编程NDEF文本/智能海报/-淘宝网 (taobao.com)

 函数声明

Private Declare Function piccreadex Lib "OUR_MIFARE.dll" (ByVal ctrlword As Byte, ByVal serial As Long, ByVal area As Byte, ByVal keyA1B0 As Byte, ByVal picckey As Long, ByVal piccdata0_2 As Long) As Byte

'Close the comport
Private Declare Function piccwriteex Lib "OUR_MIFARE.dll" (ByVal ctrlword As Byte, ByVal serial As Long, ByVal area As Byte, ByVal keyA1B0 As Byte, ByVal picckey As Long, ByVal piccdata0_2 As Long) As Byte

'修改单区函数声明
Private Declare Function piccchangesinglekey Lib "OUR_MIFARE.dll" (ByVal ctrlword As Byte, ByVal serial As Long, ByVal area As Byte, ByVal keyA1B0 As Byte, ByVal piccoldkey As Long, ByVal piccnewkey As Long) As Byte

Private Declare Function piccchangesinglekeyex Lib "OUR_MIFARE.dll" (ByVal ctrlword As Byte, ByVal serial As Long, ByVal area As Byte, ByVal keyA1B0 As Byte, ByVal piccoldkey As Long, ByVal piccnewkey As Long) As Byte

'让设备发出声响函数声明
Private Declare Function pcdbeep Lib "OUR_MIFARE.dll" (ByVal xms As Long) As Byte

'读取设备编号函数声明
Private Declare Function pcdgetdevicenumber Lib "OUR_MIFARE.dll" (ByVal devicenumber As Long) As Byte

'寻卡并返回该卡的序列号
Private Declare Function piccrequest Lib "OUR_MIFARE.dll" (ByVal serial As Long) As Byte

'寻卡并选中指定序列号的IC卡,必须指定序列号
Private Declare Function piccrequestex Lib "OUR_MIFARE.dll" (ByVal serial As Long) As Byte

'将密码写入芯片内部保密性极高的只写区域,此函数写入密码仅仅是为了piccauthkey2函数的使用。
Private Declare Function pcdwritekeytoe2 Lib "OUR_MIFARE.dll" (ByVal area As Byte, ByVal keyA1B0 As Byte, ByVal picckey As Long) As Byte

'密码认证方式1,用外部密码认证,必须指定外部密码。本函数必须在piccrequest或piccrequestex函数执行之后运行,并且要紧接着调用,中途不能调用其他函数。
Private Declare Function piccauthkey1 Lib "OUR_MIFARE.dll" (ByVal serial As Long, ByVal area As Byte, ByVal keyA1B0 As Byte, ByVal picckey As Long) As Byte

'读出一块的数据,也就是16个字节。必须在执行piccrequest或 Piccrequestex函数,接着执行piccauthkey1或 piccauthkey2函数,然后执行piccread才能成功读出一块的数据。
Private Declare Function piccread Lib "OUR_MIFARE.dll" (ByVal block As Byte, ByVal piccdata As Long) As Byte

'写一块的数据,也就是16个字节。必须在执行piccrequest或 Piccrequestex函数,接着执行piccauthkey1或 piccauthkey2函数,然后执行piccread才能成功读出一块的数据。
Private Declare Function piccwrite Lib "OUR_MIFARE.dll" (ByVal block As Byte, ByVal piccdata As Long) As Byte

'读设备存储区1
Private Declare Function pcdgetcustomizedata1 Lib "OUR_MIFARE.dll" (ByVal readerdata As Long) As Byte

'写设备存储区1
Private Declare Function pcdsetcustomizedata1 Lib "OUR_MIFARE.dll" (ByVal readerdata As Long) As Byte


'读设备存储区2
Private Declare Function pcdgetcustomizedata2 Lib "OUR_MIFARE.dll" (ByVal readerdata As Long, ByVal devicenumber As Long) As Byte

'写设备存储区2
Private Declare Function pcdsetcustomizedata2 Lib "OUR_MIFARE.dll" (ByVal readerdata As Long) As Byte

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long

Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long


        
'控制字定义,控制字指定,控制字的含义请查看本公司网站提供的动态库说明
Private Const BLOCK0_EN = &H1
Private Const BLOCK1_EN = &H2
Private Const BLOCK2_EN = &H4
Private Const NEEDSERIAL = &H8
Private Const EXTERNKEY = &H10
Private Const NEEDHALT = &H20

Dim counstr As Integer
Dim lastuid As String

 修改全部扇区密码

Private Sub Command2_Click()
Dim divstr, regstr, divreg As String
Dim devno(0 To 3) As Byte '设备编号
status = pcdgetdevicenumber(VarPtr(devno(0)))
If status = 0 Then
    divstr = Format(devno(0), "000") & "-" & Format(devno(1), "000") & "-" & Format(devno(2), "000") & "-" & Format(devno(3), "000")
    divreg = sGetINI(App.Path & "\SysConfig.ini", "DefaultSetup", "RegisterCode", "1234567890abcdef")
    regstr = DecryptStr(divreg)
    If divstr = regstr Then
        lastuid = ""
        If Command2.Caption = "修改选定扇区的卡密码" Then
            Command2.Caption = "停 止"
            For I = 0 To 15
                Text4(I).Text = ""
            Next
            Timer1.Enabled = True
        Else
            Timer1.Enabled = False
            Command2.Caption = "修改选定扇区的卡密码"
        End If
    Else
        Timer1.Enabled = False
        Command2.Caption = "修改选定扇区的卡密码"
        MsgBox ("设备编号:" & divstr & ",非本系统的注册设备,暂不能执行此功能!请将设备编号发给供应商申请注册码开通此功能!"), vbCritical + vbOKOnly, "提示"
    End If
Else
    Timer1.Enabled = False
    Command2.Caption = "修改选定扇区的卡密码"
    MsgBox ("系统未识别到发卡器,暂无法执行此功能!"), vbCritical + vbOKOnly, "提示"
End If
End Sub

Private Sub Timer1_Timer()
Dim I As Integer
Dim status As Byte '存放返回值
Dim myareano As Byte '区号
Dim authmode As Byte '密码类型,用A密码或B密码
Dim mypiccserial(0 To 3) As Byte
Dim mypiccoldkey(0 To 5) As Byte '旧密码
Dim mypiccnewkey(0 To 16) As Byte '新密码
Dim keystr, cardstr As String
    
Timer1.Enabled = False
If piccrequest(VarPtr(mypiccserial(0))) = 0 Then              'M1标签
    For I = 0 To 3
        cardstr = cardstr + Right("0" + Hex(mypiccserial(I)), 2)
    Next I
    
    If cardstr <> lastuid Then
        ListAddItem "寻找到新卡:" & cardstr & ",正在修改扇区密码及控制位,请不要移动卡片..."
        lastuid = cardstr
        
        For I = 0 To 15
            Text4(I).Text = ""
        Next

        For I = 0 To 15
            If Check4(I).Value > 0 Then
                myctrlword = BLOCK0_EN + BLOCK1_EN + BLOCK2_EN + EXTERNKEY
                myareano = I
                authmode = Combo16(I).ListIndex
                
                On Error GoTo err1:
                keystr = Trim(Text17(I).Text)
                mypiccoldkey(0) = "&H" & Mid(keystr, 1, 2)
                mypiccoldkey(1) = "&H" & Mid(keystr, 3, 2)
                mypiccoldkey(2) = "&H" & Mid(keystr, 5, 2)
                mypiccoldkey(3) = "&H" & Mid(keystr, 7, 2)
                mypiccoldkey(4) = "&H" & Mid(keystr, 9, 2)
                mypiccoldkey(5) = "&H" & Mid(keystr, 11, 2)
                
                On Error GoTo err2:
                keystr = Trim(Text1(I).Text)
                mypiccnewkey(0) = "&H" & Mid(keystr, 1, 2)
                mypiccnewkey(1) = "&H" & Mid(keystr, 3, 2)
                mypiccnewkey(2) = "&H" & Mid(keystr, 5, 2)
                mypiccnewkey(3) = "&H" & Mid(keystr, 7, 2)
                mypiccnewkey(4) = "&H" & Mid(keystr, 9, 2)
                mypiccnewkey(5) = "&H" & Mid(keystr, 11, 2)
                
                On Error GoTo err3:
                keystr = Trim(Text2(I).Text)
                mypiccnewkey(6) = "&H" & Mid(keystr, 1, 2)
                mypiccnewkey(7) = "&H" & Mid(keystr, 3, 2)
                mypiccnewkey(8) = "&H" & Mid(keystr, 5, 2)
                mypiccnewkey(9) = "&H" & Mid(keystr, 7, 2)
                
                On Error GoTo err4:
                keystr = Trim(Text3(I).Text)
                mypiccnewkey(10) = "&H" & Mid(keystr, 1, 2)
                mypiccnewkey(11) = "&H" & Mid(keystr, 3, 2)
                mypiccnewkey(12) = "&H" & Mid(keystr, 5, 2)
                mypiccnewkey(13) = "&H" & Mid(keystr, 7, 2)
                mypiccnewkey(14) = "&H" & Mid(keystr, 9, 2)
                mypiccnewkey(15) = "&H" & Mid(keystr, 11, 2)
                
                mypiccnewkey(16) = &H3  '3是表示同时更改A、B、 密码权限访问字,为2表示密码权限访问字不更改,只改A、B密码,为0表示只改A密码
        
                status = piccchangesinglekeyex(myctrlword, VarPtr(mypiccserial(0)), myareano, authmode, VarPtr(mypiccoldkey(0)), VarPtr(mypiccnewkey(0)))
                Select Case status
                    Case 0
                         Text4(I).Text = "扇区密码及控制位修改成功!"
                    Case 12
                         Text4(I).Text = "扇区密码认证失败!"
                    Case Else
                         Text4(I).Text = "操作失败,异常代码:" + Format(status, "0")
                End Select
            End If
        Next
        pcdbeep 50
    Else
        ListAddItem "请在感应区刷新的卡"
    End If
Else
    ListAddItem "请在感应区刷新的卡"
End If

Timer1.Enabled = True
Exit Sub

err1:
    Command2.Caption = "修改选定扇区的卡密码"
    MsgBox (Format(I, "00") & " 区旧认证密码输入错误!"), vbCritical + vbOKOnly, "提示"
    Exit Sub
    
err2:
    Command2.Caption = "修改选定扇区的卡密码"
    MsgBox (Format(I, "00") & " 区新A密码输入错误!"), vbCritical + vbOKOnly, "提示"
    Exit Sub
    
err3:
    Command2.Caption = "修改选定扇区的卡密码"
    MsgBox (Format(I, "00") & " 区新控制位输入错误!"), vbCritical + vbOKOnly, "提示"
    Exit Sub
    
err4:
    Command2.Caption = "修改选定扇区的卡密码"
    MsgBox (Format(I, "00") & " 区新B密码输入错误!"), vbCritical + vbOKOnly, "提示"
    Exit Sub
           
End Sub

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/170856.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

DataFunSummit:2023年数据基础架构峰会-核心PPT资料下载

一、峰会简介 正如From、Join、排序等是SQL的基本算子&#xff0c;存储与计算是也是数据架构中数据生产与消费的基本算子&#xff0c;对于数据架构之下的技术栈层级&#xff0c;我们可将其定义为数据基础架构。 数据存储技术在适应大数据时代的规模需求基础之上&#xff0c;持…

html页面直接使用elementui Plus时间线 + vue3

直接上效果图 案例源码 <!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8"><title>Title</title><script src"../js/vue3.3.8/vue.global.js"></script><link rel"styles…

FTX的前世今生:崛起、辉煌与崩塌

FTX&#xff0c;一度被誉为加密货币领域的明星交易所&#xff0c;其快速的崛起和令人瞩目的崩塌吸引了全球的关注。让我们回顾一下FTX的前世今生&#xff0c;了解其短暂的辉煌和骤然的崩塌。 1. 崛起&#xff1a; FTX的创始人山姆班克曼-弗里德在加密货币领域具有深厚的背景和…

人工智能基础_机器学习044_使用逻辑回归模型计算逻辑回归概率_以及_逻辑回归代码实现与手动计算概率对比---人工智能工作笔记0084

上面我们已经把逻辑回归的公式,以及,公式对应的图形都画画出来了,然后我们再来看看 如何用代码实现 可以看到上面是代码,咱们自己去写一下 import numpy as np from sklearn.linear_model import LogistieRegression from sklearn import datasets # 训练数据和测试数据拆分…

编译器安全

在供应链安全中&#xff0c;大家一直关注采用SCA工具分析开源组件中的安全漏洞以及许可证的合规性。但是对于底层软件开发使用的编译器、链接器等安全却容易被忽视&#xff0c;其中有没有安全漏洞、有没有运行时缺陷、有没有被植入漏洞、木马等&#xff0c;似乎并没有引起多少人…

nodejs+vue线上生活超市购物商城系统w2c42

超市管理系统的开发流程包括对超市管理系统的需求分析&#xff0c;软件的设计建模以及编写程序实现系统所需功能这三个阶段。对超市管理系统的需求分析。在这个阶段&#xff0c;通过查阅书籍&#xff0c;走访商场搜集相关资料&#xff0c;了解经营者对软件功能的具体所需和建议…

【计算机毕业设计】Node.js商城APP-97200,免费送源码,【开题选题+程序定制+论文书写+答辩ppt书写-原创定制程序】

Node.js商城APP的开发 摘 要 在传统的商业模式中&#xff0c;对于日常各类商品&#xff0c;人们习惯于到各种商家店铺购买。然而在快节奏的新时代中&#xff0c;人们不一定能为购买各类商品腾出时间&#xff0c;更不会耐心挑选自己想要的商品。所以设计一个商城APP&#xff0c…

【Java源码】智慧工地云平台:工地管理专家

智慧工地是目前建筑行业的热门话题之一&#xff0c;它代表了未来建筑施工的发展趋势。那么&#xff0c;智慧工地的未来&#xff0c;你看好吗&#xff1f; 从技术角度来看&#xff0c;智慧工地无疑是未来发展的趋势。随着人工智能、大数据、云计算等技术的飞速发展&#xff0c;智…

RESTful API 设计指南——开篇词

引言 十年后的今天&#xff0c;我终于学会了RESTful API。 以上&#xff0c;就是我最近一个月的心路历程。入职新公司不到2周&#xff0c;自己都还没完全理解RESTful API就要求给校招应届生培训&#xff0c;着实压力山大。培训结束后也感觉收获颇丰&#xff0c;遂总结分享出来&…

cpupower命令

Linux 内部共有五种对频率的管理策略 userspace &#xff0c; conservative &#xff0c; ondemand &#xff0c; powersave&#xff08;省电模式&#xff09; 和 performance&#xff08;性能模式&#xff09;。 performance: 顾名思义只注重效率&#xff0c;将CPU频率固定…

【AI实用技巧】GPT写sql统计语句

编写sql的统计语句是一项复杂的任务&#xff0c;特别是涉及多表的情况下。但有了GPT的帮助&#xff0c;一切变得轻松愉快。 AI7号 - 最强人工智能&#xff08;GPT&#xff09;中文版https://ai7.pro/s/9v2um 举例说明 有表结构如下&#xff1a; users(user_id, name) bills(…

CRM系统的客户细分有什么作用?

我们常常说&#xff0c;企业想要开展有针对性的营销活动&#xff0c;就需要进行客户细分。通过特定条件&#xff0c;将客户分为几类&#xff0c;从而对不同类型的客户提供不同的产品和服务。下面我们就针对这里来详细说说&#xff0c;CRM中客户细分是什么&#xff1f;如何细分客…

ADB安装及使用介绍

一、ADB简介 1、什么是adb ADB 全称为 Android Debug Bridge&#xff0c;起到调试桥的作用&#xff0c;是一个客户端-服务器端程序。其中客户端是用来操作的电脑&#xff0c;服务端是 Android 设备。 ADB 也是 Android SDK 中的一个工具&#xff0c;可以直接操作管理 Android …

Linux安全之AIDE系统入侵检测工具安装和使用

一、AIDE 系统入侵检测工具简介 AIDE&#xff0c;全称为Advanced Intrusion Detection Environment&#xff0c;是一个主要用于检测文件完整性的入侵检测工具。它能够构建一个指定文件的数据库&#xff0c;并使用aide.conf作为其配置文件。AIDE数据库能够保存文件的各种属性&am…

出版级柱状图绘制,轻松拿捏(初学者友好的R包ggpubr在线版)

工具地址 Galaxy中国&#xff08;UseGalaxy.cn&#xff09; > Graph/Display Data > 柱状图 功能描述 这个工具可以绘制出版级柱状图&#xff0c;是 ggpubr 包的 barplot 工具的在线版。 条形图通过垂直或水平的条形展示分类变量的分布&#xff08;频数&#xff09;。横坐…

九宫格 图片 自定义 路径

<image :src" ../../static/img/ item.urlname .png " class"u-w-82 u-h-82 u-p-t-36"></image>使用场景&#xff1a;九宫格里含有多张图片 html <view class"u-p-b-46 u-p-x-35"><u-grid :border"false" c…

element表格分页+数据过滤筛选

目录 前言效果展示分页效果展示搜索效果展示 代码分析分页功能过滤数据功能 全部代码 前言 在el-element的标签里的tableData数据过多时&#xff0c;会导致表格页面操作卡顿。为解决这一问题&#xff0c;有以下解决方法&#xff1a; 分页加载&#xff1a; 将大量数据进行分页&…

Django 入门学习总结8-管理页面的生成

修改polls/admin.py文件为&#xff1a; from django.contrib import admin from .models import Choice, Question class ChoiceInline(admin.StackedInline): model Choice extra 3 class QuestionAdmin(admin.ModelAdmin): fieldsets [ (None, {&q…

系列十四、异步回调

一、概述 二、案例代码 /*** Author : 一叶浮萍归大海* Date: 2023/11/21 10:45* Description: 异步任务案例代码*/ public class CompletableFutureMainApp {public static void main(String[] args) throws ExecutionException, InterruptedException {CompletableFuture<…

WMS仓库管理系统的应用场景有哪些?

“WMS仓库管理系统的应用场景有哪些&#xff1f;” WMS&#xff08;仓库管理系统&#xff09;作为一种强大的工具&#xff0c;它在提升仓库操作效率、优化库存管理以及改善供应链可视性方面发挥着关键作用。那么&#xff0c;WMS究竟在哪些场景下展现出强大的应用价值呢&#x…