当前位置:编程学习 > C#/ASP.NET >>

C# 读取明华RF读卡器,验证密码不对,请帮忙,谢谢

 //初始化读卡器
            Int16 icdev = IC.rf_init(1, 9600);
            textBox1.Text = icdev.ToString();
            if (icdev < 0)
            {
                MessageBox.Show("端口初始化失败,请检查接口线是否连接正确。", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                IC.rf_exit(icdev);
            }

            //寻卡
            ulong snr;        
            Int16  st = IC.rf_card(icdev, 0, out snr);
            if (st != 0)
            { 
                MessageBox.Show("MCM寻卡失败", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                IC.rf_exit(icdev);
            }
            textBox2.Text = st.ToString();
            textBox3.Text = "卡号:"+snr.ToString();

            //装载密码
            byte[] pwd = new byte[3] { 255, 255, 255 };
            //Int16 lk = IC.rf_load_key(icdev, 0, 8, pwd);
            Int16 lk = IC.rf_load_key(icdev, 0, 8, pwd);
            if (lk != 0)
            {
                MessageBox.Show("装密码失败", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                IC.rf_exit(icdev);
            }

            //密码验证--前面都对,到这一步出问题了,请大侠们帮忙啊,一下两个,用哪个也不对。
            //Int16 at = IC.rf_authentication(icdev, 0, 8);//0为验证模式,表示密码A;8表示8号扇区
            Int16 at = IC.rf_authentication_2(icdev, 0, 8, 0);//验证8号扇区0号块
            if (at != 0)
            {
                MessageBox.Show("验证密码失败", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                IC.rf_exit(icdev);
            }

————————————————————————————————————
库函数如下:

     //验证密码
    [DllImport("mwrf32.dll", EntryPoint = "rf_authentication", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
   public static extern Int16 rf_authentication(Int16 icdev, byte mode, byte SecNr);
 //验证密码2
  [DllImport("mwrf32.dll", EntryPoint = "rf_authentication_2", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)]
  public static extern Int16 rf_authentication_2(int icdev, byte mode, byte SecNr, Int16 blocknr); C# 明华 rf_authentication 读卡器 密码验证 --------------------编程问答-------------------- 读IC卡吗? --------------------编程问答-------------------- 我也遇到密码验证失败,请问楼主解决了吗? --------------------编程问答-------------------- 以前我做的

byte[] _Key = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; //12位密码,初始默认为FFFFFFFFFFFF

                                        string[] strArrayInfo = new string[3];
                                        bool bolIsReadSuccess = true;


                                        if (rf_load_key(icDev, byteCardFindMode, 1, _Key) != 0)
                                        {
                                            bolIsReadSuccess = false;
                                        }
                                        else
                                        {
                                            if (rf_authentication(icDev, byteCardPwdMode, 1) == 0)//进行验证
                                            {
                                                for (int i = 0; i < 3; i++)
                                                {
                                                    if (rf_read(icDev, (byte)(i + 4), _Data) == 0)//从第一扇区的1,2,3块(绝对地址4-6块)取数据
                                                    {
                                                        rf_decrypt(byteKey, _Data, 16, byteDecryptValue); //使用密钥将密文转换为明文,格式为byte数组
                                                        strArrayInfo[i] = Encoding.Default.GetString(byteDecryptValue); //将byte数组明文转换为字符串明文
                                                        strArrayInfo[i] = strArrayInfo[i].Trim();
                                                    }
                                                    else
                                                    {
                                                        bolIsReadSuccess = false;
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                bolIsReadSuccess = false;
                                            }
                                        }

--------------------编程问答-------------------- 我的程序也差不多,rf_authentication就是验证失败了! --------------------编程问答-------------------- 除 --------------------编程问答-------------------- 我也遇到了这个问题,怎么解决呀 --------------------编程问答-------------------- 写IC卡的孩子们伤不起呀。
曾经做过多家的读卡、写卡程序,有的厂家卡片不太稳定,伤不起。
问厂家也不了了之,没找出问题。
你自己找更费劲了。 --------------------编程问答-------------------- 我现在遇到的问题更去了,用Web形式使用IC读写器,在客户机找不到,只能插到服务器上使用?这个问题怎么解决。。。总不能再从服务器拉根线,哈哈。。。
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,