ModifyPredefinedFileKey.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. namespace ShengJu_CUT100_DES.MessageEntity.Outgoing
  6. {
  7. /// <summary>
  8. /// 对进行高级格式化后自动创建的默认应用目录下的4个文件,按指定编号的密钥验证旧密钥后将旧密钥的更改为新密钥
  9. /// </summary>
  10. public class ModifyPredefinedFileKey : MessageBase
  11. {
  12. public enum PredefinedFileKeyTypeEnum
  13. {
  14. 根密钥 = 0x00,
  15. 文件1读密钥 = 0x01,
  16. 文件1读写密钥 = 0x02,
  17. 文件2读密钥 = 0x03,
  18. 文件2读写密钥 = 0x04,
  19. 文件3读密钥 = 0x05,
  20. 文件3读写密钥 = 0x06,
  21. 文件4读密钥 = 0x07,
  22. 文件4读写密钥 = 0x08
  23. }
  24. /// <summary>
  25. ///
  26. /// </summary>
  27. /// <param name="fileId">1-4</param>
  28. /// <param name="blockAddress">0-3</param>
  29. /// <param name="readKey">16 bytes key,密钥值需要与制定文件的读写密钥相对应</param>
  30. public ModifyPredefinedFileKey(PredefinedFileKeyTypeEnum keyType, byte[] oldKey, byte[] newKey)
  31. {
  32. if (oldKey == null || newKey == null)
  33. throw new ArgumentNullException("must provide oldKey and newKey");
  34. if (oldKey.Length != 16 || newKey.Length != 16)
  35. throw new ArgumentException("oldKey and newKey must has its length to 16");
  36. base.命令代码 = CommandType.DesFireEV1操作命令_更改密钥;
  37. base.RawDataAndCheck = new byte[] { (byte)keyType }.Concat(oldKey).Concat(newKey).ToList();
  38. }
  39. }
  40. }