example to use keytool to set up public/private keys

  1. Run the following two commands to generate keystore
    keytool –genkeypair –alias dlkey -keypass password -storetype jks –keystore dlkeystore.jks -storepass password -validity 365 -keyalg RSA
  2. Export certificate of private key dlkey
    keytool –exportcert –alias dlkey -file dlkey.cert -keystore dlkeystore.jks -storepass password
  3. Send the dlkey.cert (public key) to target server.
  4. Run the following command to import the server certificate (fnet.net.cer) to keystore

keytool –importcert –file fnet.net.cer -alias dlcert -keypass password -keystore dlkeystore.jks –storepass password

Oracle String Column Reformat Using RegExp Replacement

This post discusses how to quickly reformat a string column in oracle table.

Sample table definition goes as follows:

CREATE TABLE test (event_id VARCHAR2(20));
INTO test VALUES (‘2015-06-25-000122’)
INTO test VALUES (‘2015-06-25-000130’)

Now I want to reformat the string format from yyyy-mm-dd-xxxxxx to yyyymmdd-xxxxxx, I can use regular expression as follows:

UPDATE test SET event_id=REGEXP_REPLACE(event_id, ‘([[:digit:]]{4})-([[:digit:]]{2})-([[:digit:]]{2})-([[:digit:]]{6})’, ‘\1\2\3-\4’);

A brief explanation is as follows:

event_id: source chars

‘([[:digit:]]{4})-([[:digit:]]{2})-([[:digit:]]{2})-([[:digit:]]{6})’: pattern

‘\1\2\3-\4’: replace string

[[:digit]] stands for any digit combinations

{num} specify how many digits are there

() in the pattern string is used to specify a trunk of string in the pattern so that we can use number in the replace string to refer to the trunk. For example, ‘\1’ in the replace string ‘\1\2\3-\4’ refers to the ([[:digit:]{4}) in the pattern string.