Reading BER-encoded data
So, based on your update it looks like you've switched to reading from Stream - good decision.

A bit simplified/cleaner approach for reading int is:

public static class ASN1Int
{
    public static int Read(Stream inputStream)
    {
        const int sizeMarker = 0x80; //TODO: name appropriately

        int size = inputStream.ReadByte();

        if (size &lt; sizeMarker)
            return inputStream.ReadByte();

        size -= sizeMarker;
        //TODO: add assertion to make sure size&lt;=4 if needed

        var result = inputStream.ReadByte();

        while (--size &gt; 0)
            result = (result &lt;&lt; 8) + inputStream.ReadByte();

        return result;
    }
}