How do I use the Key Values feature for challenge-response authentication between my program and the Key?

  1. You create the Key Value Table in an encrypted format:
  2. public const ushort KEY1 = 20948;
    public const ushort VALUE1 = 54905;
    public const ushort KEY2 = 53897;
    public const ushort VALUE2 = 53228;
    public const ushort KEY3 = 3419;
    public const ushort VALUE3 = 60377;
    public const ushort KEY4 = 1239;
    public const ushort VALUE4 = 60886;
    public const ushort KEY5 = 59746;
    public const ushort VALUE5 = 58848;
    public const ushort KEY6 = 17220;
    public const ushort VALUE6 = 1087;
    public const ushort KEY7 = 6067;
    public const ushort VALUE7 = 64059;
    public const ushort KEY8 = 39284;
    public const ushort VALUE8 = 26330;
    public const ushort KEY9 = 63006;
    public const ushort VALUE9 = 19074;
    public const ushort KEY10 = 42225;
    public const ushort VALUE10 = 58807;
    public const ushort KEY_XOR = 21930;
    public const ushort VALUE_XOR = 43605;
    ushort[] KeyTable = new ushort[10]
                        {KEY1 ^ KEY_XOR,
                         KEY2 ^ KEY_XOR,
                         KEY3 ^ KEY_XOR,
                         KEY4 ^ KEY_XOR,
                         KEY5 ^ KEY_XOR,
                         KEY6 ^ KEY_XOR,
                         KEY7 ^ KEY_XOR,
                         KEY8 ^ KEY_XOR,
                         KEY9 ^ KEY_XOR,
                         KEY10 ^ KEY_XOR};
    ushort[] ValueTable = new ushort[10]
                         {VALUE1 ^ VALUE_XOR,
                          VALUE2 ^ VALUE_XOR,
                          VALUE3 ^ VALUE_XOR,
                          VALUE4 ^ VALUE_XOR,
                          VALUE5 ^ VALUE_XOR,
                          VALUE6 ^ VALUE_XOR,
                          VALUE7 ^ VALUE_XOR,
                          VALUE8 ^ VALUE_XOR,
                          VALUE9 ^ VALUE_XOR,
                          VALUE10 ^ VALUE_XOR};
  3. You generate an index (m_nKeyValueIdx) of 10 random digits for the 10 Key-Value pairs. The sample code gets the current hark disk space modulo by 10.
  4. // Example of calculating a random index for Key Value
    DriveInfo d = new DriveInfo("c");
    long AmtFree = d.TotalFreeSpace;
    long Total = d.TotalSize;
    m_nKeyValueIdx = (AmtFree * 100 / Total) % 10;
  5. You put the Key Value Code to the property Kc.KeyValueCode. Then, call the method Kc.SetKeyValue(). The system will decode the KeyValueCode for the Key-Value pair, and save in the Key in an encrypted format.
  6. You can get the Key Value Code by using ElecKey Integrator. In the Key Options dialog box, you will be able to assign the Key Values as same as the values KEY1, VALUE1 ... KEY10, VALUE10 in the code.
  7. You get a Key from the static encrypted KeyTable by the index (m_nKeyValueIdx). Then call the method Kc.GetKeyValue() using that Key. You will get the Value (m_wValue) of such Key.
  8. // Getting KeyValue
    ushort Key = KeyTable[m_nKeyValueIdx];
    Key ^= KEY_XOR;
    m_wValue = Kc.GetKeyValue(Key);
    m_wValue ^= VALUE_XOR;
  9. Put the Key Value checking (between m_wValue and ValueTable[m_nKeyValueIdx]) in functions in your code as you needed. If they match, let the function continues. Otherwise, you would exit the function.
  10. private void feature4ToolStripMenuItem_Click(object sender, EventArgs e)
    {
       if (m_wValue == ValueTable[m_nKeyValueIdx]) // example of checking Key Value in an important function
       {
          MessageBox.Show("This is Feature-4.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
       }
    }