Replace DER re-encoding code with a version based more closely on OpenSSL functions.