DEV Community

Cover image for Create digital certificate
bytewhisper
bytewhisper

Posted on • Updated on

Create digital certificate

Digital signatures and certificates play an important role in security and integrity of digital communications, documents, and transactions in today's world.

Digital signatures provide a secure way to verify the identity of the sender and detect any unauthorized modifications to the content. Digital signature should be issued by trusted Certificate Authorities (CAs)

As our world becomes increasingly digital, the importance of digital signatures and certificates continues to grow, underpinning the foundation of trust and security in our digital interactions. Of course for production you need CA`s certificate and what about development? I would like to explain how to create local (Development) certificate for testing puproses.

As our world becomes increasingly digital, the importance of digital signatures and certificates continues to grow, underpinning the foundation of trust and security in our digital interactions. Of course for production you need CA`s certificate and what about development? I would like to explain how to create local (Development) certificate for testing puproses.

Let's start:

When you are working on a development environment, you might not want to use official, paid certificates provided by well-known Certificate Authorities (CAs) like DigiCert or Let's Encrypt. Instead, local development certificates offer a cost-effective solution and save you from the hassle of managing public certificates for temporary and local testing purposes.

You can use local development certificates for:

  • Testing secure connections: If your application or website requires SSL/TLS connections, you can use a local certificate to simulate secure connections without involving a public CA.
  • Code signing: Developers often need to sign code to test its functionality or to avoid security warnings in certain environments.
  • API development: Some APIs might require requests to be signed with a certificate, which can be cumbersome to obtain from a public CA for development purposes.

Creating certificate

Creating a local development certificate involves generating a self-signed certificate. A self-signed certificate is one where the certificate issuer and the certificate subject are the same entity. Keep in mind that these certificates are not suitable for production or public-facing applications due to their lack of trust and vulnerability to man-in-the-middle attacks. But, for local development, they are doing well.

Install OpenSSL (if not already installed)

OpenSSL is a open-source tool for working with SSL/TLS and certificates. Ensure you have OpenSSL installed on your system before proceeding. You can download it from the official OpenSSL website or use your system's package manager to install it.

Generate a Private Key

The first step is to generate a private key. Execute the following command in your terminal or command prompt.

openssl genpkey -algorithm RSA -out private-key.pem

Enter fullscreen mode Exit fullscreen mode

This command will generate a private key and save it in the private-key.pem file.

Create a Certificate Signing Request (CSR)

Next, you need to create a Certificate Signing Request (CSR). The CSR contains the information about the entity (you) who needs the certificate. Use the following command:

openssl req -new -key private-key.pem -out csr.pem

Enter fullscreen mode Exit fullscreen mode

Follow the prompts to provide the necessary information, such as your country, state, organization, and common name (CN).

Generate the Self-Signed Certificate

Now, use the CSR to generate the self-signed certificate:

openssl x509 -req -days 365 -in csr.pem -signkey private-key.pem -out certificate.pem

Enter fullscreen mode Exit fullscreen mode

This command will generate the self-signed certificate and save it in the certificate.pem file.

Create *.pfx file

openssl pkcs12 -export -out certificate.pfx -inkey private-key.pem -in certificate.pem

Enter fullscreen mode Exit fullscreen mode

After running this command, you will be prompted to set a password for the PFX file. This password will be required when importing or using the PFX in other applications or systems. Make sure to keep this password secure, as it protects the private key and the certificate contained within the PFX file.

Start Using the Local Development Certificate

With the private key and the self-signed certificate, you can now use them in your development environment. For furute, I will provide several articles how to use *.pfs file for sign documents with different signing tools.

Conclusion

Creating a local development certificate for digital signing will help for developers who need to test and troubleshoot secure applications and code. While these certificates are not suitable for production use, they are perfect for simulating secure connections and code signing in local and development environments.

Buy Me A Coffee

Top comments (0)