Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

423
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda