测试Rockey 4 Smart加密锁的.Net C#语言代码

public enum Ry4Cmd : ushort { RY_FIND = 1, //Find Ry4S RY_FIND_NEXT, //Find next RY_OPEN, //Open Ry4S RY_CLOSE, //Close Ry4S RY_READ, //Read Ry4S RY_WRITE, //Write Ry4S RY_RANDOM, //Generate random RY_SEED, //Generate seed RY_READ_USERID = 10, //Read UID RY_CHECK_MODULE = 12, //Check Module RY_CALCULATE1 = 14, //Calculate1 RY_CALCULATE2, //Calculate1 RY_CALCULATE3, //Calculate1 };
public enum Ry4ErrCode : uint { ERR_SUCCESS = 0, //No error ERR_NO_PARALLEL_PORT = 0x80300001, //(0x80300001)No parallel port ERR_NO_DRIVER, //(0x80300002)No drive ERR_NO_ROCKEY, //(0x80300003)No Ry4S ERR_INVALID_PASSWORD, //(0x80300004)Invalid password ERR_INVALID_PASSWORD_OR_ID, //(0x80300005)Invalid password or ID ERR_SETID, //(0x80300006)Set id error ERR_INVALID_ADDR_OR_SIZE, //(0x80300007)Invalid address or size ERR_UNKNOWN_COMMAND, //(0x80300008)Unkown command ERR_NOTBELEVEL3, //(0x80300009)Inner error ERR_READ, //(0x8030000A)Read error ERR_WRITE, //(0x8030000B)Write error ERR_RANDOM, //(0x8030000C)Generate random error ERR_SEED, //(0x8030000D)Generate seed error ERR_CALCULATE, //(0x8030000E)Calculate error ERR_NO_OPEN, //(0x8030000F)The Ry4S is not opened ERR_OPEN_OVERFLOW, //(0x80300010)Open Ry4S too more(>16) ERR_NOMORE, //(0x80300011)No more Ry4S ERR_NEED_FIND, //(0x80300012)Need Find before FindNext ERR_DECREASE, //(0x80300013)Dcrease error ERR_AR_BADCOMMAND, //(0x80300014)Band command ERR_AR_UNKNOWN_OPCODE, //(0x80300015)Unkown op code ERR_AR_WRONGBEGIN, //(0x80300016)There could not be constant in first instruction in arithmetic ERR_AR_WRONG_END, //(0x80300017)There could not be constant in last instruction in arithmetic ERR_AR_VALUEOVERFLOW, //(0x80300018)The constant in arithmetic overflow ERR_UNKNOWN = 0x8030ffff, //(0x8030FFFF)Unkown error ERR_RECEIVE_NULL = 0x80300100, //(0x80300100)Receive null ERR_PRNPORT_BUSY = 0x80300101 //(0x80300101)Parallel port busy };
public class RockeyAPI { //-------------Ry4S.dll--start-------------------- public const string XDLL = "Ry4S.dll"; //Rockey函数 //EXTERN_C __declspec(dllexport) WORD WINAPI Rockey(WORD function, WORD* handle, DWORD* lp1, DWORD* lp2, WORD* p1, WORD* p2, WORD* p3, WORD* p4, BYTE* buffer); [DllImport(XDLL, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi, EntryPoint = "Rockey")] public static extern ulong _Rockey(ushort function, ref ushort handle, ref uint lp1, ref uint lp2, ref ushort p1, ref ushort p2, ref ushort p3, ref ushort p4, ref object buffer); public static ulong Rockey(Ry4Cmd function, ref ushort handle, ref uint lp1, ref uint lp2, ref ushort p1, ref ushort p2, ref ushort p3, ref ushort p4, ref object buffer) { return _Rockey((ushort)function, ref handle, ref lp1, ref lp2, ref p1, ref p2, ref p3, ref p4, ref buffer); } }
/// <summary> /// 加密锁Rockey4 Smart /// vp:hsg /// create date:2012-04-26 /// </summary> public class RockeyClass { // private uint lp1 = 0; private uint lp2 = 0; // private ushort p1; private ushort p2; private ushort p3; private ushort p4; // private byte[] buffer = new byte[1024]; private object obbuffer = new object(); private ushort handle = 0; // public string HID = ""; // public bool SetDemoPassword() { bool rbc = false; p1 = 0xc44c; p2 = 0xc8f8; p3 = 0x0799; p4 = 0xc43b; rbc = true; return rbc; } public bool SetPassword(ushort m_p1,ushort m_p2) { bool rbc=false; p1 = m_p1; p2 = m_p2; p3 = 0; p4 = 0; rbc=true; return rbc; } public string GetHex8(uint val) { return string.Format("{0:X8}", val); } public string GetHex4(uint val) { return string.Format("{0:X4}", val); } //查找加密锁 Rockey4 Smart public ulong Find() { //Find Ry4S obbuffer=(object)buffer; ulong ret = RockeyAPI.Rockey(Ry4Cmd.RY_FIND,ref handle,ref lp1,ref lp2,ref p1,ref p2,ref p3,ref p4,ref obbuffer); //strRet = string.Format("({0}): {1:X8}", i + 1, uiarrRy4ID[i]); this.HID =GetHex8(lp1); return ret; } //打开当前加密锁 public ulong Open() { ulong ret = RockeyAPI.Rockey(Ry4Cmd.RY_OPEN, ref handle, ref lp1, ref lp2, ref p1, ref p2, ref p3, ref p4, ref obbuffer); return ret; } //关闭当前加密锁 public ulong Close() { ulong ret = RockeyAPI.Rockey(Ry4Cmd.RY_CLOSE, ref handle, ref lp1, ref lp2, ref p1, ref p2, ref p3, ref p4, ref obbuffer); return ret; } //写入用户存储区 public ulong Write(ushort pos, ushort len,byte[] m_buffer1024) { p1 = pos; p2 = len; buffer = m_buffer1024; obbuffer = (object)m_buffer1024; ulong ret = RockeyAPI.Rockey(Ry4Cmd.RY_WRITE, ref handle, ref lp1, ref lp2, ref p1, ref p2, ref p3, ref p4, ref obbuffer); return ret; } //读取用户存储区 public ulong Read(ushort pos, ushort len, ref byte[] m_buffer1024) { p1 = pos; p2 = len; buffer = m_buffer1024; obbuffer = (object)m_buffer1024; ulong ret = RockeyAPI.Rockey(Ry4Cmd.RY_READ, ref handle, ref lp1, ref lp2, ref p1, ref p2, ref p3, ref p4, ref obbuffer); return ret; } //生成随机数 public ulong Random(ref ushort rdval) { ulong ret = RockeyAPI.Rockey(Ry4Cmd.RY_RANDOM, ref handle, ref lp1, ref lp2, ref p1, ref p2, ref p3, ref p4, ref obbuffer); rdval = p1; return ret; } //生成种子码 public ulong Seed(uint m_lp2, ref ushort buf_p1, ref ushort buf_p2, ref ushort buf_p3, ref ushort buf_p4) { lp2 = m_lp2; p1 = buf_p1; p2 = buf_p2; p3 = buf_p3; p4 = buf_p4; ulong ret = RockeyAPI.Rockey(Ry4Cmd.RY_SEED, ref handle, ref lp1, ref lp2, ref p1, ref p2, ref p3, ref p4, ref obbuffer); buf_p1 = p1; buf_p2 = p2; buf_p3 = p3; buf_p4 = p4; return ret; } //读取用户ID public ulong Read_UserID(ref string UID) { ulong ret = RockeyAPI.Rockey(Ry4Cmd.RY_READ_USERID, ref handle, ref lp1, ref lp2, ref p1, ref p2, ref p3, ref p4, ref obbuffer); UID = this.GetHex8(lp1); return ret; } //检查模块状态 public ulong Check_Module(ushort mod_numid_0_64, ref ushort Validate, ref ushort Decreasable)//RY_CHECK_MODULE { p1 = mod_numid_0_64; ulong ret = RockeyAPI.Rockey(Ry4Cmd.RY_CHECK_MODULE, ref handle, ref lp1, ref lp2, ref p1, ref p2, ref p3, ref p4, ref obbuffer); Validate = p2; Decreasable = p3; return ret; } //Calculate 1 public ulong Calculate_1(ref uint m_lp1,ref uint m_lp2, ref ushort m_p1,ref ushort m_p2,ref ushort m_p3,ref ushort m_p4) { //Calculate 1,A=1,B=2,C=3,D=4... //lp1 = 0; lp2 = 8; p1 = 1; p2 = 2; p3 = 3; p4 = 4; lp1 = m_lp1; lp2 = m_lp2; p1 = m_p1; p2 = m_p2; p3 = m_p3; p4 = m_p4; ulong ret = RockeyAPI.Rockey(Ry4Cmd.RY_CALCULATE1, ref handle, ref lp1, ref lp2, ref p1, ref p2, ref p3, ref p4, ref obbuffer); m_p1=p1; m_p2=p2; m_p3=p3; m_p4=p4; return ret; } // //Calculate 2 public ulong Calculate_2(ref uint m_lp1, ref uint m_lp2, ref ushort m_p1, ref ushort m_p2, ref ushort m_p3, ref ushort m_p4) { //Calculate 2,Seed=0x12345678,A=1,B=2,C=3,D=4... //lp1 = 0; lp2 = 0x12345678; p1 = 1; p2 = 2; p3 = 3; p4 = 4; lp1 = m_lp1; lp2 = m_lp2; p1 = m_p1; p2 = m_p2; p3 = m_p3; p4 = m_p4; ulong ret = RockeyAPI.Rockey(Ry4Cmd.RY_CALCULATE2, ref handle, ref lp1, ref lp2, ref p1, ref p2, ref p3, ref p4, ref obbuffer); m_p1 = p1; m_p2 = p2; m_p3 = p3; m_p4 = p4; return ret; } //Calculate 3 public ulong Calculate_3(ref uint m_lp1, ref uint m_lp2, ref ushort m_p1, ref ushort m_p2, ref ushort m_p3, ref ushort m_p4) { //Calculate 3,A=1,B=2,C=3,D=4... //lp1 = 0; lp2 = 8; p1 = 1; p2 = 2; p3 = 3; p4 = 4; lp1 = m_lp1; lp2 = m_lp2; p1 = m_p1; p2 = m_p2; p3 = m_p3; p4 = m_p4; ulong ret = RockeyAPI.Rockey(Ry4Cmd.RY_CALCULATE3, ref handle, ref lp1, ref lp2, ref p1, ref p2, ref p3, ref p4, ref obbuffer); m_p1 = p1; m_p2 = p2; m_p3 = p3; m_p4 = p4; return ret; } //
class Program { static void Main(string[] args) { uint lp1 = 0x00000000; uint lp2 = 0x12345678; ushort p1 = 0x0000; ushort p2 = 0x0000; ushort p3 = 0x0000; ushort p4 = 0x0000; Net.Security.Rockey4Smart.RockeyClass r = new Net.Security.Rockey4Smart.RockeyClass(); // ShowMsg("设置密码"); r.SetDemoPassword(); ulong ret = r.Find(); if (ret>0) { //找到加密锁 ShowMsg("HID=" + r.HID); r.Open(); //获取UserID string UID = ""; r.Read_UserID(ref UID); ShowMsg("UID=" + UID); //获取随机数 ushort rdval=0; r.Random(ref rdval); ShowMsg("Random=" + r.GetHex4(rdval)); //获取种子码 lp2=0x12345678; r.Seed(lp2, ref p1, ref p2, ref p3, ref p4); ShowMsg(string.Format("Seed A,B,C,D={0},{1},{2},{3}", r.GetHex4(p1), r.GetHex4(p2), r.GetHex4(p3), r.GetHex4(p4))); //计算1 lp1 = 0; lp2 = 8; p1 = 1; p2 = 2; p3 = 3; p4 = 4; r.Calculate_1(ref lp1, ref lp2, ref p1, ref p2, ref p3, ref p4); ShowMsg(string.Format("计算1 A,B,C,D={0},{1},{2},{3}", r.GetHex4(p1), r.GetHex4(p2), r.GetHex4(p3), r.GetHex4(p4))); //计算2 lp1 = 0; lp2 = 0x12345678; p1 = 1; p2 = 2; p3 = 3; p4 = 5; r.Calculate_2(ref lp1, ref lp2, ref p1, ref p2, ref p3, ref p4); ShowMsg(string.Format("计算2 A,B,C,D={0},{1},{2},{3}", r.GetHex4(p1), r.GetHex4(p2), r.GetHex4(p3), r.GetHex4(p4))); //计算3 lp1 = 0; lp2 = 8; p1 = 1; p2 = 2; p3 = 3; p4 = 6; r.Calculate_3(ref lp1, ref lp2, ref p1, ref p2, ref p3, ref p4); ShowMsg(string.Format("计算3 A,B,C,D={0},{1},{2},{3}", r.GetHex4(p1), r.GetHex4(p2), r.GetHex4(p3), r.GetHex4(p4))); //关闭加密锁 r.Close(); } } }

转载于:https://www.cnblogs.com/sqlite3/archive/2012/04/26/2566706.html

测试Rockey 4 Smart加密锁的.Net C#语言代码相关推荐

  1. 测试Rockey 4 Smart加密锁的C语言代码

    测试Rockey 4 Smart加密锁的C语言代码 // win32Console_dog_test.cpp : Defines the entry point for the console app ...

  2. [翻译Joel On Software]Joel测试:12步写出更高质量代码/The Joel Test: 12 Steps to Better Code

    Joel on Software The Joel Test: 12 Steps to Better Code Joel测试:12步写出更高质量代码 byJoel Spolsky Wednesday, ...

  3. 案例实战 | Python 玩转 AB 测试中的分层抽样与假设检验!(附代码和数据集)...

    今天由优秀的萝卜同学给大家分享一篇AB测试干货~ 本文会将原理知识穿插于代码段中,相关代码和数据集空降文末可以获取. 前言 在电商网站 AB 测试非常常见,是将统计学与程序代码结合的经典案例之一.尽管 ...

  4. SMART PLC斜坡函数功能块(梯形图代码)

    斜坡函数Ramp的具体应用可以参看下面的文章链接: PID优化系列之给定值斜坡函数(PLC代码+Simulink仿真测试)_RXXW_Dor的博客-CSDN博客很多变频器里的工艺PID,都有" ...

  5. 素性测试的Miller-Rabin算法完全解析 (C语言实现、Python实现)

    因为文中存在公式,只能用图片方式上传了! 以下为C语言源代码: #include <stdio.h> typedef long long unsigned LLU; typedef int ...

  6. Inception网络 运行在Cifar10 测试集87.88% Tensorflow 2.1 小白从代码实践中 理解

    环境 tensorflow 2.1 最好用GPU 模型 Inception 训练数据 Cifar10 或者 Cifar 100 训练集上准确率:93%左右 验证集上准确率:88%左右 测试集上准确率: ...

  7. ResNet 运行在Cifar10 测试集86.38% Tensorflow 2.1 小白从代码实践中 理解

    环境 tensorflow 2.1 最好用GPU 模型 ResNet 训练数据 Cifar10 或者 Cifar 100 训练集上准确率:92%左右 验证集上准确率:87.6%左右 测试集上准确率:8 ...

  8. [深度学习-实践]Tensorflow 2.x应用ResNet SeNet网络训练cifar10数据集的模型在测试集上准确率 86%-87%,含完整代码

    环境 tensorflow 2.1 最好用GPU Cifar10数据集 CIFAR-10 数据集的分类是机器学习中一个公开的基准测试问题.任务的目标对一组32x32 RGB的图像进行分类,这个数据集涵 ...

  9. python测试c语言代码_numpy C语言源代码调试(一)

    调试 首先创建一个用于测试的python文件,例如mytest.py from numpy import linspace #注意这里写错了 x = np.arange(5) np.empty_lik ...

最新文章

  1. 基于灰度的模板匹配算法(一):MAD、SAD、SSD、MSD、NCC、SSDA算法
  2. 《Shell脚本学习指南》第四章 文本处理工具
  3. 全面快速准确地检索医学文献信息的策略
  4. Python使用扩展库progressbar显示进度条
  5. 5.3 tensorflow2实现梯度下降法完成广告投入销售额预测——python实战
  6. win7电脑便签怎么弄
  7. 如何将图片压缩到200K以内,有什么好方法吗?
  8. CNN Explainer
  9. 现代计算机网络的前沿技术,现代计算机网络的前沿技术分析
  10. Java精品项目源码第53期流浪动物管理系统
  11. 教你如何查看SpringCloud Alibaba、Spring Clou 和 SpringBoot对应版本
  12. layui数据表格无数据显示undefined
  13. 《斜杠创业家》读书笔记之思维导图精华版
  14. Solidworks 不能设置或者编辑材料,提示参数错误
  15. Win7便笺、StikyNot.exe、打不开的解决办法、便签已停止启动
  16. asp.net校园车辆管理系统
  17. [转载]茶话之四:政和工夫英伦打李鬼
  18. python爬虫网站接口的使用——将网页上的输入内容的接口转移到对应的爬虫中(通过爬虫查询相关网页的信息)
  19. 为家庭网络布线-第5部分-千兆吞吐量和Vista
  20. sql查询语句DQL笔记

热门文章

  1. 奶制品生产与销售matlab,奶制品的生产与销售模型.doc
  2. Android cec设备,Android HDMI CEC控制服务
  3. 通达信自动交易接口怎么显示大宗流入?
  4. 百度Apollo晒成绩单:伴1500万车主,累计156亿公里,它还要让1亿辆车智能化
  5. JVM 调优实战--jhat命令使用详解
  6. hack、crack站点收集
  7. linux命令查看cpu序列号,Linux下用命令查看CPU ID以及厂家等信息
  8. Android解锁黑屏问题完美解决!
  9. 短视频抖音矩阵玩法详细攻略大全丨国仁网络资讯
  10. 生成网络论文阅读:PGGAN(二):PROGRESSIVE GROWING OF GANS FOR IMPROVED QUALITY, STABILITY, AND VARIATION