Beispiel #1
0
        /*Load Key
         * Send
         * FF 82 00 00 06 FF FF FF FF FF FF
         * or
         * FF 82 [KeyStructure:00(all others are reserved for fu)] [KeyNumber:00-01] 06 [KeyChunk0:**] [KeyChunk0:**] [KeyChunk0:**] [KeyChunk0:**] [KeyChunk0:**] [KeyChunk0:**]
         * Returns
         * 90 00
         */
        /// <summary>
        /// Loads Athentication Keys into the system
        /// </summary>
        /// <param name="Key">A enumeration as 1 or 2 for posible memory locations</param>
        /// <param name="KeyValue">The Key Value to use. Length must be six</param>
        /// <returns></returns>
        public ACR122U_ResposeErrorCodes LoadAthenticationKeys(ACR122U_KeyMemories Key, byte[] KeyValue)//only for mifare 1k cards
        {
            byte[] Return;
            if (!Enum.IsDefined(typeof(ACR122U_KeyMemories), Key))
            {
                throw new Exception("Your Key Load location is not a valid one.");
            }
            if (KeyValue.Length != 6)
            {
                throw new Exception("Your Key has too many or too few bites.\nKeys must have 6 bytes.");
            }

            byte[] CommandAsBytes = new byte[11] {
                0xFF, 0x82, 0x00, (byte)Key, 0x06, KeyValue[0], KeyValue[1], KeyValue[2], KeyValue[3], KeyValue[4], KeyValue[5]
            };

            TransmitData(CommandAsBytes, out Return);

            LastACRResultCode = RetrieveDataCodes(ref Return);
            return(LastACRResultCode);
        }
Beispiel #2
0
        /*Load Key
         * Send
         * FF 86 00 00 05 01 00 00 60 01
         * or
         * FF 86 00 00 05 01 00 [Block:00-FF] 6{000<KeyType:0=A,1=B>} [KeyNumber:00-01]
         * Returns
         * 90 00
         * Note in a 4 block sector the last block is the key block
         */
        /// <summary>
        /// Uses prev loaded Athentication Keys to Athenticate
        /// </summary>
        /// <param name="Key">A enumeration as A or B</param>
        /// <param name="KeyToUse">A enumeration as 1 or 2 for posible memory locations</param>
        /// <returns></returns>
        public ACR122U_ResposeErrorCodes Athentication(byte BlockToAthenticate, ACR122U_Keys Key, ACR122U_KeyMemories KeyToUse)
        {
            if (!Enum.IsDefined(typeof(ACR122U_KeyMemories), KeyToUse))
            {
                throw new Exception("Your Key Load location is not a valid one.");
            }
            if (!Enum.IsDefined(typeof(ACR122U_Keys), Key))
            {
                throw new Exception("Your Key Selection is not a valid one.");
            }

            byte[] Return;
            byte[] CommandAsBytes = new byte[10] {
                0xFF, 0x86, 0x00, 0x00, 0x05, 0x01, 0x00, BlockToAthenticate, (byte)(0x60 | (byte)Key), (byte)KeyToUse
            };

            TransmitData(CommandAsBytes, out Return);
            LastACRResultCode = RetrieveDataCodes(ref Return);
            return(LastACRResultCode);
        }