Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

413
Vistas
How to convert .cer file to .pem in the browser

The cer file I'm reading in from a file input, I can then use the fileReader to get the contents. I was expecting the file to have start and end comments but it doesn't.

How can I convert the cer to pem in the browser, without uploading the file to a server?

What I really want is something like

openssl x509 -in cert.cer -out cert.pem

but in the browser

I've also tried a few x509 packages from npm, like...

import * as x509 from '@peculiar/x509';
...
  const uploadCsr = async (fileArr: File[]): Promise<void> => {
    const file = fileArr[0];
    const reader = new FileReader();
    reader.onload = (e: any): void => {
      const cert = new x509.X509Certificate(e.target.result);
      console.log('cert', cert); 
    };
    reader.readAsBinaryString(file);
  };

but the error I get is

TypeError: Unsupported format of 'raw' argument. Must be one of DER, PEM, HEX, Base64, or Base4Url
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I had to use the readAsArrayBuffer with @peculiar/x509 and .toString('pem');

import * as x509 from '@peculiar/x509';
...

  const checkCsr = async (fileArr: File[]): Promise<void> => {
    setServerError('');
    const file = fileArr[0];
    const reader = new FileReader();
    reader.onload = async (e: any): Promise<void> => {
      const cert = new x509.X509Certificate(e.target.result);
      const expires = Date.parse(`${cert.notAfter}`) / 1000;
      const now = Math.floor(Date.now() / 1000);
      if (now > expires) setServerError('Certificate has expired');
      const issuerArr = cert.issuer.split('=');
      if (!issuerArr[3].includes('Apple Inc'))
        setServerError('Certificate not issued by Apple Inc');
      const pem = cert.toString('pem');
      if (!serverError) setCertificatePem(pem);
    };
    reader.readAsArrayBuffer(file);
  };
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda