Search code examples
javaresteasybouncycastle

How to generate x.509 certificate by the Java keytool command-line interface


I am using RESTEasy encryption. For that I have to generate x.509 certificate by the Java 'keytool' command-line interface.

Please help me

Thank you


Solution

  • This is the command to generate self signed certificates. All in one line

    keytool -genkey -keyalg RSA -alias selfsigned -keystore keystore.jks 
            -storepass password -validity 360 -keysize 2048
    

    When you run this command, it will ask you for the details of the signatory. These will be the details of your organization. Provide all the details and it will create a new self signed certificate in keystore keystore for you.

    NOTE: When it ask for your first and last name, give the domain name of the server which will be the entry point for your users. i.e. www.myserver.com

    If you already have a keystore then you can use your existing keystore to add new certificate otherwise this command will create the keystore keystore.jks with the password and add the certificate to the new keystore. Note that if you already have a keystore then you need to provide the password of the existing keystore in -storepass parameter of this command.

    For more details, see the keytool man page: http://docs.oracle.com/javase/1.5.0/docs/tooldocs/solaris/keytool.html

    Here you will find details of all the available options you can use with the keytool command.