Self-signed certificate with CA


Jawad-Dev:

I am working on a solution for file encryption via a combination of RSA and AES. RSA is basically used here for a handshake to encrypt a symmetric key and decrypt with the key pair at the receiver side.

I have used Java keystore for private key and self signed certificate for public key. Both are created as follows:

key store

keytool -genkey -keyalg RSA -alias BANK -keystore receiverKeystore.jks -validity 360 -keysize 2048

Certificate export

keytool -export -alias BANK -keystore receiverKeystore.jks -rfc -file bankCert.cer

Again, both are used in Java as follows:

private key

private void setKeys() {

        KeyStore senderKeyStore = null;
        String keyStorePassword = "fms123";

        try {

            senderKeyStore = KeyStore.getInstance( "JKS" );  
            FileInputStream is = new FileInputStream( keystorePath );
            senderKeyStore.load( is, keyStorePassword.toCharArray() );  

            senderPrivateKey = ( PrivateKey ) senderKeyStore.getKey( KEYSTORE_ALIAS, keyStorePassword.toCharArray() );

            receiverPublicKey = loadReceiverPublicKeyFromCertificate();
        }
        catch ( Exception e ) {
            System.out.println( " Exception in setting keys from key store = " + e );
        }

    } 

public key

private PublicKey loadReceiverPublicKeyFromCertificate () {

        PublicKey publicKey = null; 

        try {

            FileInputStream fin = new FileInputStream( certificateFilePath );
            CertificateFactory factory = CertificateFactory.getInstance( "X.509" );
            X509Certificate certificate = ( X509Certificate ) factory.generateCertificate( fin );
            publicKey = certificate.getPublicKey();
        }
        catch ( Exception e ) {
            System.out.println( " Exception in loading receiver certificate = " + e );
        }

        return publicKey;
    }

I now have the following questions:

  1. Is it the right way?
  2. If I use a trusted certificate here, how will I get the public key from it? Will it be fetched the same way? and private key? Will I use the same method or something from the certificate?

  3. How to distribute certificates to recipients? For this, what is the use of secure communication?

I'm new to cryptography and would love to get some advice.

Maarten Bodewes:

Your handshake is called key establishment . Handshake is used in (online) transport mode, but I don't think you developed that. I would use PKCS#12 keystore instead, JKS is a bit outdated. The whole idea of ​​using a char[]as a password is that its contents can be deleted directly after using a, so using Stringas as an input is not a good idea. Strings are usually detained and immutable in Java, so you can't destroy them without ugly hacks involving native code.

A trusted certificate is no different from an untrusted certificate. Yes, you can retrieve the public key from it. The private key is usually stored with the certificate chain leading to the leaf user certificate to which the private key belongs. However, the private key is not part of the certificate , so you cannot retrieve the private key from the certificate. It doesn't matter, the private key should be established where the private key is required. There is no need to transfer them except for backup purposes.

How you send the certificate to the recipient is up to you. The tricky part is getting the recipient to trust the certificate. Using pre-established keys (such as trusted PGP keys) works. If you don't have such a key, you're in trouble. What you can do is build trust using other methods. It's probably one of the easiest ways to have the other party call you and then verify that the certificate thumbprint (basically just the hash on the certificate) is correct. If your users aren't too far from us, you can of course bring them in person as well.

However, you cannot create secure channels out of thin air. If you don't trust the other person, it's obviously impossible to establish complete trust.

Related


Self-signed certificate with CA

Jawad-Dev: I am working on a solution for file encryption via a combination of RSA and AES. RSA is basically used here for a handshake to encrypt a symmetric key and decrypt with the key pair at the receiver side. I have used Java keystore for private key and

Self-signed certificate with CA

Jawad-Dev: I am working on a solution for file encryption via a combination of RSA and AES. RSA is basically used here for a handshake to encrypt a symmetric key and decrypt with the key pair at the receiver side. I have used Java keystore for private key and

Self-signed certificate with CA

Jawad-Dev: I am working on a solution for file encryption via a combination of RSA and AES. RSA is basically used here for a handshake to encrypt a symmetric key and decrypt with the key pair at the receiver side. I have used Java keystore for private key and

Trusted CA on self-signed certificate

horny I have an old Linux based embedded device from a project about ten years ago. The device has no built-in UI, keyboard or anything like that, just a small web server to control it. I have since forgotten the passcode on the device and the company that ori

Trusted CA on self-signed certificate

horny I have an old Linux based embedded device from a project about ten years ago. The device has no built-in UI, keyboard or anything like that, just a small web server to control it. I have since forgotten the passcode on the device and the company that ori

Find out if a certificate is self-signed or CA-signed

Nishan: I have a web application that allows users to upload pkcs12. I store pkcs12 as binary in database. Is there any way for me to know if the certificate in pkcs12 is self signed or CA signed? I am running a java web application on tomcat and can use opens

Find out if a certificate is self-signed or CA-signed

Nishan: I have a web application that allows users to upload pkcs12. I store pkcs12 as binary in database. Is there any way for me to know if the certificate in pkcs12 is self signed or CA signed? I am running a java web application on tomcat and can use opens

Find out if a certificate is self-signed or CA-signed

Nishan: I have a web application that allows users to upload pkcs12. I store pkcs12 as binary in database. Is there any way for me to know if the certificate in pkcs12 is self signed or CA signed? I am running a java web application on tomcat and can use opens

Invalid CA certificate with self-signed certificate chain

Tejas I have a self signed certificate chain with these commands and configured it on the Apache server but when i tryopenssl s_client -showcerts -servername server -connect my-host.local:443 -CAfile all.crt I am getting error from opensslVerify return code: 2

Invalid CA certificate with self-signed certificate chain

Tejas I have a self signed certificate chain with these commands and configured it on the Apache server but when i tryopenssl s_client -showcerts -servername server -connect my-host.local:443 -CAfile all.crt I am getting error from opensslVerify return code: 2

OpenSSL Self-Signed Root CA Certificate: Set Start Date

Kampar I'm using the following setup (using OpenSSL 1.0.1 14 Mar 2012) to create a small test CA with my own self signed certificate. The problem I'm having is that if I look at the start date of the CA's own certificate, it will create it for tomorrow (and I

Using self signed CA certificate for WebSocket (ws) in Node JS

Thomas Shankartis I need to connect to a separate WebSocket server using a ws client in Node JS . Since I have a "Self-Signed Root CA" installed in my computer's "Trusted Root Certification Authorities" store, I can connect using the sample program in Chrome.

C# Generate intermediate certificate from self signed root CA

username I am using Visual Studio 2019 with c# and Bouncy Castlein version 1.8.5. I have been able to generate Certificate Authority(CA) successfully and now want to generate one Intermediate Certificate. In the current workflow, the CA certificate is returned

C# Generate intermediate certificate from self signed root CA

username I am using Visual Studio 2019 with c# and Bouncy Castlein version 1.8.5. I have been able to generate Certificate Authority(CA) successfully and now want to generate one Intermediate Certificate. In the current workflow, the CA certificate is returned

OpenSSL Self-Signed Root CA Certificate: Set Start Date

Kampar I'm using the following setup (using OpenSSL 1.0.1 14 Mar 2012) to create a small test CA with my own self signed certificate. The problem I'm having is that if I look at the start date of the CA's own certificate, it will create it for tomorrow (and I

Generate self-signed certificate with root CA signer

Ninja Ninja Scenario: I'm using PowerShell on Windows Server 2012r2 to generate a root certificate and want to use it to sign newly created intermediate and web certificates in a dynamically generated (and destroyed) dev/test environment. The scripts are deplo

Generate self-signed certificate with root CA signer

Ninja Ninja Scenario: I'm using PowerShell on Windows Server 2012r2 to generate a root certificate and want to use it to sign newly created intermediate and web certificates in a dynamically generated (and destroyed) dev/test environment. The scripts are deplo

Self-signed certificate doesn't work - invalid CA

it Using openssl I am trying to install a ssl certificate on my server using Apache. Follow some links like this youtube tutorial . I was able to download/install openSSL running the following commands openssl genrsa -aes256 -out private.key 2048 openssl rsa -

Using self signed CA certificate for WebSocket (ws) in Node JS

Thomas Shankartis I need to connect to a separate WebSocket server using a ws client in Node JS . Since I have a "Self-Signed Root CA" installed in my computer's "Trusted Root Certification Authorities" store, I can connect using the sample program in Chrome.

Using self signed CA certificate for WebSocket (ws) in Node JS

Thomas Shankartis I need to connect to a separate WebSocket server using a ws client in Node JS . Since I have a "Self-Signed Root CA" installed in my computer's "Trusted Root Certification Authorities" store, I can connect using the sample program in Chrome.

How to trust a self-signed certificate without trusting a CA?

SeMeKh So, I've generated the rootCA, and signed the certificate for *.a.com, how can I trust the generated certificate in Firefox/Chrome without directly trusting the CA? Note that adding an exception (once) is not enough in this case because there are multip

C# Generate intermediate certificate from self signed root CA

username I am using Visual Studio 2019 with c# and Bouncy Castlein version 1.8.5. I have been able to generate Certificate Authority(CA) successfully and now want to generate one Intermediate Certificate. In the current workflow, the CA certificate is returned

OpenSSL Self-Signed Root CA Certificate: Set Start Date

Kampar I'm using the following setup (using OpenSSL 1.0.1 14 Mar 2012) to create a small test CA with my own self signed certificate. My problem is that if I look at the start date of the CA's own certificate, it will create that certificate for tomorrow (and

Windows Tomcat7 SSL CA certificate says self signed

crush Hi, I'm trying to configure tomcat7 (7.0.50) in Windows 7 with a certificate from a CA (trust, if that matters). I downloaded the CA root, chain root and chain certificate files and the new certificate. According to the tomcat guide , I used the keystore

Using self signed CA certificate for WebSocket (ws) in Node JS

Thomas Shankartis I need to connect to a separate WebSocket server using a ws client in Node JS . Since I have a "Self-Signed Root CA" installed in my computer's "Trusted Root Certification Authorities" store, I can connect using the sample program in Chrome.

C# Generate intermediate certificate from self signed root CA

username I am using Visual Studio 2019 with c# and Bouncy Castlein version 1.8.5. I have been able to generate Certificate Authority(CA) successfully and now want to generate one Intermediate Certificate. In the current workflow, the CA certificate is returned

C# Generate intermediate certificate from self signed root CA

username I am using Visual Studio 2019 with c# and Bouncy Castlein version 1.8.5. I have been able to generate Certificate Authority(CA) successfully and now want to generate one Intermediate Certificate. In the current workflow, the CA certificate is returned

OpenSSL Self-Signed Root CA Certificate: Set Start Date

Kampar I'm using the following setup (using OpenSSL 1.0.1 14 Mar 2012) to create a small test CA with my own self signed certificate. The problem I'm having is that if I look at the start date of the CA's own certificate, it will create it for tomorrow (and I