The DER encoder in OpenSSL is correct, but the above examples apparently weren't using it. The result of "I made my own DER encoder" is usually wrong... it's not hard to encode DER correctly but it takes a little effort that people don't bother to put in.