1

I'm trying to convert a .crt string into a .der certificate and save it into Redis. I'm try to replicate the following steps with Nodejs

openssl x509 -outform der -in certificate.pem -out certificate.der
openssl rsa -outform DER -in key.pem -out key.der
redis-cli -x HMSET domain:testsite1.com cert < testsite1.com.der
redis-cli -x HMSET domain:testsite1.com key < testsite1.com.key.der

The .crt string looks like this

-----BEGIN CERTIFICATE-----
XXXXXXXXXXX
-----END CERTIFICATE-----
-----BEGIN CERTIFICATE-----
XXXXXXXXXX
-----END CERTIFICATE-----
-----BEGIN CERTIFICATE-----
XXXXXXXXX
-----END CERTIFICATE-----

This is my failed attempt using node-forge npm and redis.

var certDER = forge.asn1.toDer(forge.pki.certificateToAsn1('/opt/resty/ssl/*.ngdeploy.com.chained.crt',{encoding: 'utf8'}));
REDIS.hmset('test','cert',certDER);

I tried Googling for solutions but I didn't find any for converting .crt string to .der binary. I'm looking for a Node.js solution and not an OpenSSL solution. Please advise.

Itamar Haber
  • 47,336
  • 7
  • 91
  • 117
mbejda
  • 1,471
  • 16
  • 25
  • Split these 3 certificates (one cert will be `-----BEGIN CERTIFICATE----- XXXXXXXXXXX -----END CERTIFICATE-----. Keep the formating - 64 characters per line) and call `openssl x509 -inform PEM -outform DER -in certificate.pem -out certificate.der` on each of them. It should work. – pepo Apr 11 '16 at 18:31
  • @pepo I'm looking for a node.js solution not using openssl cli. – mbejda Apr 11 '16 at 18:56

1 Answers1

2

The extension of a file is often meaningless. What you seam to look for is a way to convert from text or PEM format (Base64) to binary or DER.

The simplest way is to use Openssl but if you must use JS this thread might help just make sure you reverse the conversion (PEM to DER , instead of DER to PEM)

Community
  • 1
  • 1
Jofre
  • 215
  • 1
  • 16