title: How to access specific byte from registry value encrypted with CryptProtectData
body: <p>I am trying to retrieve a Date value from the registry. The value is encrypted with CryptProtectData.</p>
  
  <p>The Bytes of interest are (little-endian):</p>
  
  <p>[-16] and [-15] is a the year. [-14] and [-13] is a month and [-12] and [-11] is a day.</p>
  
  <pre><code>RegistryKey HKCR;
  RegistryKey dateKey;
  HKCR = RegistryKey.OpenBaseKey(RegistryHive.ClassesRoot, RegistryView.Default);
  dateKey = HKCR.OpenSubKey(subKeyPath);
  byte[] registryValue = (byte[])dateKey.GetValue(null);
  byte[] unprotectedRegistryValue = ProtectedData.Unprotect(registryValue, null, DataProtectionScope.LocalMachine);
  </code></pre>
  
  <p>The unprotectedRegistryValue is an byte Array: {byte[224]}.
  I have to further process the range [-16..-11] and pass the apropried values to BitConverter.ToInt16([-16..-15]) and then to Date functions to receive the information about the year for example.</p>
  
  <p>Unfortunatelly I am stuck with the value from unprotectedRegistryValue, because there is no negative index. When I try to access the values for the year information.</p>
  
  <pre><code>var yearBytes = new byte[] {unprotectedRegistryValue[-16], unprotectedRegistryValue[-15]};
  </code></pre>
  
  <p>I receive an IndexOutOfRangeException because the indexes of the unprotectedRegistryValue are all positive.</p>
  
  <p>I miss some understanding between the part of encrypt the data and pass the bytes of interest to further processing the values.</p>
  
  <p>How could I manage to get the bytes of interest and pass them further?</p>