Hello,
I just noticed, that the DerData.GetLength method is buggy. For example. A length of 128 in DER-Format would be
0xF1 0xF0 (0xF1 indicating a total of 1 octet, and 0xF0 the single octet representing 128)
But the source code would only return an byte[] Array of size 1.
Like
```
private byte[] GetLength(int length)
{
if (length > 127)
{
int size = 1;
int val = length;
while ((val >>= 8) != 0)
size++;
// here it must be new byte[size + 1] to have place for the octects AND the octect count byte
var data = new byte[size + 1];
data[0] = (byte)(size | 0x80);
for (int i = (size - 1) * 8, j = 1; i >= 0; i -= 8, j++)
{
data[j] = (byte)(length >> i);
}
return data;
}
else
{
return new byte[] { (byte)length };
}
}
```
Greetz
Christian
I just noticed, that the DerData.GetLength method is buggy. For example. A length of 128 in DER-Format would be
0xF1 0xF0 (0xF1 indicating a total of 1 octet, and 0xF0 the single octet representing 128)
But the source code would only return an byte[] Array of size 1.
Like
```
private byte[] GetLength(int length)
{
if (length > 127)
{
int size = 1;
int val = length;
while ((val >>= 8) != 0)
size++;
// here it must be new byte[size + 1] to have place for the octects AND the octect count byte
var data = new byte[size + 1];
data[0] = (byte)(size | 0x80);
for (int i = (size - 1) * 8, j = 1; i >= 0; i -= 8, j++)
{
data[j] = (byte)(length >> i);
}
return data;
}
else
{
return new byte[] { (byte)length };
}
}
```
Greetz
Christian