private static byte[] DERDecodeVector(byte[] input, int idx, out int consumed)
{
int length;
if (input[idx] < 128) {
length = input[idx];
consumed = 1+length;
idx += 1;
} else if (input[idx] == 0x81) {
length = input[idx+1];
consumed = 2+length;
idx += 2;
} else if (input[idx] == 0x82) {
length = (input[idx+1] << 8) | input[idx+2];
consumed = 3+length;
idx += 3;
} else {
throw new Exception("Unsupported DER vector length");
}
byte[] ret = new byte[length];
Buffer.BlockCopy(input, idx, ret, 0, ret.Length);
return ret;
}