I am trying to retrieve a Date value from the registry. The value is encrypted with CryptProtectData.
The Bytes of interest are (little-endian):
[-16] and [-15] is a the year. [-14] and [-13] is a month and [-12] and [-11] is a day.
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);
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.
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.
var yearBytes = new byte[] {unprotectedRegistryValue[-16], unprotectedRegistryValue[-15]};
I receive an IndexOutOfRangeException because the indexes of the unprotectedRegistryValue are all positive.
I miss some understanding between the part of encrypt the data and pass the bytes of interest to further processing the values.
How could I manage to get the bytes of interest and pass them further?