• Home
  • About
    • lahuman photo

      lahuman

      열심히 사는 아저씨

    • Learn More
    • Facebook
    • LinkedIn
    • Github
  • Posts
    • All Posts
    • All Tags
  • Projects

crt, key 인증서 파일 pem으로 변환

27 Feb 2019

Reading time ~1 minute

cert, key 파일을 pem 파일로 변환 하기

nginx에서 사용하던 인증서를 nodejs에서 바로 사용을 하기 위해 pem 파일 형식으로 변경 해야하는 일이 생겨서 검색을 해보았다. 파일 형석의 변환은 다음과 같이 쉽게 할 수 있다.

# key 변경
openssl rsa -in server.key -text > private.pem
# crt 변경
openssl x509 -inform PEM -in server.crt > public.pem

추가 팁] nodejs 에서 https 설정

nodejs에서 https 사용을 위해서는 https 모듈을 추가로 설치 해야 한다.

이후 소스내에 다음과 같이 인증서를 options을 추가 하면 된다.

const https = require('https');
const fs = require('fs');
const options = {
  ca: fs.readFileSync('인증서경로/ca-bundle.pem')
  key: fs.readFileSync('인증서경로/domain_xxxxx.key.pem')
  cert: fs.readFileSync('인증서경로/domain_xxxxx.crt.pem')
};
https.createServer(options, (req, res) => {
  res.writeHead(200);
  res.end('hello world\n');
}).listen(443);

참 쉽죠?

참고 주소

  • How to get .pem file from .key and .crt files?
  • Node.js SSL 인증서 설치/적용 가이드


pemcert Share Tweet +1