{"action":"opened","issue":{"url":"https://api.github.com/repos/digitalbazaar/forge/issues/336","labels_url":"https://api.github.com/repos/digitalbazaar/forge/issues/336/labels{/name}","comments_url":"https://api.github.com/repos/digitalbazaar/forge/issues/336/comments","events_url":"https://api.github.com/repos/digitalbazaar/forge/issues/336/events","html_url":"https://github.com/digitalbazaar/forge/issues/336","id":121887045,"number":336,"title":"Difference between PEM and DER when file is passed in as a buffer","user":{"login":"AlaRuba","id":1168883,"avatar_url":"https://avatars.githubusercontent.com/u/1168883?v=3","gravatar_id":"","url":"https://api.github.com/users/AlaRuba","html_url":"https://github.com/AlaRuba","followers_url":"https://api.github.com/users/AlaRuba/followers","following_url":"https://api.github.com/users/AlaRuba/following{/other_user}","gists_url":"https://api.github.com/users/AlaRuba/gists{/gist_id}","starred_url":"https://api.github.com/users/AlaRuba/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AlaRuba/subscriptions","organizations_url":"https://api.github.com/users/AlaRuba/orgs","repos_url":"https://api.github.com/users/AlaRuba/repos","events_url":"https://api.github.com/users/AlaRuba/events{/privacy}","received_events_url":"https://api.github.com/users/AlaRuba/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-12-12T23:24:02Z","updated_at":"2015-12-12T23:24:02Z","closed_at":null,"body":"Hi,\r\n\r\nI opened a previous issue, but I think this issue better encapsulates the problem.\r\n\r\nSo, I'm uploading my certificates to be parsed. I'm trying to handle both PEM and DER files, but they both get uploaded in a multi-part form that stores the contents in a buffer.\r\n\r\nNow, I have the PEM working. If I pass in the buffer containing the buffer that has PEM format,\r\n\r\nI can get the certificate this way\r\n\r\n    var certString = certBuffer.toString();\r\n    var cert = pki.certificateFromPem(certString);\r\n\r\nNow I have the DER version of the same certificate that just worked. Now, I uploaded the DER file the same way, and I thought I would be able to extract the certificate the same way\r\n\r\n    var certString = certBuffer.toString();\r\n    var obj = forge.asn1.fromDer(certString);\r\n    var cert = forge.pki.certificateFromAsn1(obj);\r\n\r\nHowever, I get the following error  Cannot read X.509 certificate. ASN.1 object is not an X509v3 Certificate\r\n\r\nI was wondering if DER should be handled differently. I notice when I print the string, the content is some haphazard malformed data with some correct data. Whereas when I open the DER in Sublime, it's just bytes.\r\n\r\nI was wondering how to handle this.\r\n\r\nSorry to bug and great work."}}