Saturday, June 29, 2019

Spring Boot + Jasypt example to encrypt database password in property file

In this example we will see how to encrypted database password in property file (application.properties or application.yml). We will use Jasypt library for this purpose.

Jasypt (Java Simplified Encryption) is a java library which allows the developer to add basic encryption capabilities to his/her projects with minimum effort, and without the need of having deep knowledge on how cryptography works.

To know more about Jasypt, click here. Go to Jasypt website and download the latest version of jasypt client. I am using jasypt-1.9.2-dist.zip. Once downloaded extract the zip file and go to folder /jasypt-1.9.2/bin and execute the below command. Here input is your password or any other text that you want to encrypt and password is the secret key used by Jasypt to encode and decode the input.

encrypt.bat input="dummy_password" password="SECRET_KEY"


To know about encrypting from the command line using Jasypt CLI Tools. click here.

Add below maven dependency in your pom.xml file

<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
<version>2.1.1</version>
</dependency>

application.yml
Note - the encrypted password in parenthesis with keyword ENC 


There are various options by which you can feed the SECRET_KEY to your application

- From java code you can set system property jasypt.encryptor.password as shown below. You can do this in a separate secure JAR file.

System.setProperty("jasypt.encryptor.password", "SECRET_KEY");


- From command line you can pass system properties

$ Java -Djasypt.encryptor.password=SECRET_KEY Application

My Sql + Spring Boot JPA - One to many, many to one example

This is a simple spring boot JPA (hibernate) example. It will demonstrate how one to many, many to one mapping can be done

Below are the tables created in MySQL

create table department
(
 department_id int not null auto_increment,primary key (department_id),
 department_name  varchar(50) not null
);


create table employee
(
 employee_id int not null auto_increment, primary key (employee_id),
 employee_name varchar(50) not null, 
 department_id int not null, foreign key (department_id) references department(department_id)
);

pom.xml


application.yml


Friday, June 28, 2019

Java - Export database table to CSV file

This is a sample springboot application with bare minimum code to export database tables to CSV file

pom.xml

application.yml

Application.java

Python - Export database table to csv file


Java - Export database tables to an excel file

This is a sample springboot application with bare minimum code to export database tables to an excel file

pom.xml

application.yml

Application.java

Sunday, June 23, 2019

Python - Connect mysql

Python needs a MySQL driver to access the MySQL database. PIP can be used to install "MySQL Connector". PIP is most likely already installed in your Python environment. Go to command prompt and execute below command

C:\> python -m pip install mysql-connector



test-mysql.sql

Sunday, June 16, 2019

Python - Read and write a text file

After coding in Java for nearly 10 years, lately i started learning Python programming and let me tell you it quickly grabbed my interest. So here is the first code for reading and writing a text file using Python. More codes will come along.

read_write_file.py

Saturday, June 1, 2019

Example with React, Redux and Axios API

In previous article we have seen a simple react with redux example. In this article we will add Axios api to it. Axios is used for Promise based HTTP client for the browser and node.js. To know more about axios package, click here.

In this example we will get input name from user and hit a hello world rest endpoint. For running this example you may need to install below packages -
  • redux
  • react-redux
  • axios
  • redux-thunk


App.js