Example of RSA using JAVA


I have two web services and I want to send encrypted password as HTTP response.


Implement asymmetric cryptography using RSA as the following flow chart.


Here is the source code of RSA cryptography.

Install Apache Tomcat 8 On CentOS 7


We were building Web Service using Spring with spring-boot which is provieded Tomcat. So that we have to export WAR file and deploy it on a Tomcat server.

What did I do at first?

At first, I followed the procedure from this post. It worked fine but Management Interface always displayed with 403 Access Dined as the following screenshot.


Last piece of the puzzle

Now, check the directory /opt/tomcat/conf/Catalina/localhost. It is empty!!!


So… What is the last step? Read the offical document and add the following file under /opt/tomcat/conf/Catalina/localhost for defining docBase of each webapp.

docs.xml  examples.xml  host-manager.xml  manager.xml

The content of each file must following the format. For example, this is for Manager Interface.

<Context path="/manager" docBase="${catalina.home}/webapps/manager" antiResourceLocking="false" privileged="true" />

Don’t forget add other files!

And remember to reload and restart your server.

[root@local]# systemctl daemon-reload
[root@local]# systemctl restart tomcat

The difference CSS selector *= and ~=


I was considering what the difference between *= and ~= and what is the better situation for the each selector.

The below descriptions are both from CSS Selector.

E[foo~=”bar”] an E element whose “foo” attribute value is a list of whitespace-separated values, one of which is exactly equal to “bar” Attribute selectors 2
E[foo*=”bar”] an E element whose “foo” attribute value contains the substring “bar” Attribute selectors 3

For example, we have a HTML and a CSS file on Gist. Enjoy the DEMO. 🙂



Blob In Database Using JPA


My aim is creating a web service for responding as File whose type is oracle.sql.BLOB.

Oh! I could barely find the problem which always shows could not deserialize. At first, I read the section and knew that it was caused by composite key because I did not create both hashCode and equals functions. But it still not worked. Why? See Solution.

I finally inspired by this post.

check whether they are serializable itself and all their fields either serializable too

So that I started searching the method of JPA for Blob and I found this. It described how to insert and retrieve Blob type. Anyway, let’s see the sample.


Retrieve File From Google Drive


I want to retrieve public(shared with anyone and can be found) files without authentication(Google Auth) and I was using drive.files.list Google Drive API v3.

Google Drive Using YQL.001Google Drive Using YQL.002

As you can see, Google API always refused the requests sent by browsers because it needs OAuth. 


I realized that can get file separately instead because drive.files.get doesn’t need OAuth if the files are public. And it only return file content in Google Drive API v2. It’s being much easier. 😀

By the way, we still have to apply API key.

Why Not Google Drive API v3?

The response doesn’t include file content anymore despite Google Drive API v3 migrated from Google Drive API v2.