How to Pick Best Stocks in Share Market

When thinking about investments, 3 things come to my mind, in Sri Lankan context. Buy real state in a suburb or a town that is fast growingPut in a Fixed Deposit in a bankInvest in the stock market As the current FD rates are in declining phase, it did not really come as a good option to me at the moment of writing this. Hence I thought to investigate a bit on investing in the share market as it doesn't really need a larger amount of money as to by a property as in option 1.
Below is an insightful speech by the richest person in Sri Lanka, who is known as a business magnate, 'Mr. Dhammika Perera', explaining how he started with share market (while the overall speech highlights many important facts, he specifically talks about share market from 6minutes and 26 seconds. Speech is in Sinhalese).

One thing he said, captured me that do not enter a business if you do not know about it. He also emphasized that it's the knowledge we should seek, not money, which surprised me t…

Generating Key Pairs and Importing Public Key Certificates to a Trusted Keystore

Through this I am sharing the most simple scenario to follow in using Java keytool for the requirements of Apache Wookie projects digital signature implementation. Anyway if you are looking to know how to generate a key pair or import a certificate to a Keystore using keytool, still this may be helpful. Refer this segment of Java SE documentation to know in-depth details.

You needs a configuration of Java in your computer to use keytool and that is enough :).

Generating Key Pairs

Use following command in command prompt to generate a keypair with a self-signed certificate
keytool -genkey -alias wookie -keyalg RSA -keystore wookieKeystore.jks -keysize 4096
After  -alias give the alias to be used for keys
          -keylag give the algorithm to be used in key generation
         -keystore give the name of the keystore with type .jks (You can give a path here to store the keystore in a desired place)
          -keysize give the length for the generating key in bits
This will look something as follows,

That's all and you are having a key pair now. :) 
In Aspects of Wookie, now you can sign Widgets using this keystore. But in order to get your widgets verified and deployed in Wookie server you needs to get your public key trusted by server directly or via a third party.

Generating .cer File

To insert a public key certificate into a trusted keystore it needs to be exported as a .cer file. (There are several other options to use too.)
keytool -v -export -file keystore1.cer -keystore wookieKeystore.jks -alias wookie

Importing Public Key Certificates to a Trusted Keystore

To import a trusted certificate to a trusted keystore following command can be used.
keytool -import -alias keystore1 -file keystore1.cer -keystore wookieKeystore.jks
This command simply says to import the public key certificate of key having alias 'keystore1' which is in the file keystore1.cer to the keystore 'wookieKeystore.jks'.

Now any signature generated using the private key of keystore1 aliased key pair, can be properly validated using wookieKeystore.jks.


  1. This comment has been removed by a blog administrator.

  2. are you sure the generated key pair is self-signed?

    1. Yes, it is.. You can confirm on Oracle site,

  3. keytool uses the -selfcert command to generate a self signed certificate. I am also not sure if keytool can export the public key. openssl can.

    1. Yes keytool can export the public cert as of above. Only confusion was regarding exporting the private key as a .p12 file. This is also possible with Java 7 onwards..

  4. Hi Pusphalanka,

    Can u please share the downlinked/full sample code for the Signing SOAP Messages - Generation of Enveloped XML Signatures? When I clicked to the download link its no more there in the


  5. Hello Pushpalanka,

    Do you have also verification part of "Signing SOAP Messages" available? Verification always fails :(

  6. Hi Pushpalanka .. Thanks for wonderful post... need one help .... i created jks file using the same method u suggested. Can you help me what would be the value of keystorepass, privateKeyAlias, privateKeyPass and certificateAlias required in one of the program in which you suggested how to make signed enveloped xml from xml.

    I can understand pass keystorepass and privatekeypass will be my password. But i am unable to know what are the values for privateKeyalias and certificateAlias.


Post a Comment

Popular posts from this blog

Signing SOAP Messages - Generation of Enveloped XML Signatures

How to send an HTML email in Java (Using Google SMTP Server)

Adding Custom Claims to the SAML Response - (How to Write a Custom Claim Handler for WSO2 Identity Server)