Today's Question:  What does your personal desk look like?        GIVE A SHOUT

 JAVA


  Different types of keystore in Java -- Overview

Keystore is a storage facility to store cryptographic keys and certificates. They are most frequently used in SSL communications to prove the identity of servers and clients. A keystore can be a file or a hardware device. Three are three kinds of entries can be stored in a keystore depending on the types of keystores.The three types of entries are:PrivateKey : This is a type of keys which are used in asymmetric cryptography. It is usually protected with password because of its sensitivity. It can also be used to sign a digital signature.Certificate : A certificate contains a public key which c...

135,905 4       JAVA KEYSTORE OVERVIEW JKS PKCS12 JCEKS PKCS11 DKS BKS


  String.length() vs String.getBytes().length in Java

In Java, String.length() is to return the number of characters in the string, while String.getBytes().length is to return the number of bytes to represent the string with the specified encoding. By default, the encoding will be the value of system property file.encoding, the encoding name can be set manually as well by calling System.setProperty("file.encoding", "XXX"). For example, UTF-8, Cp1252. In many cases, String.length() will return the same value as String.getBytes().length, but in some cases it's not the same.String.length() is the number of UTF-16 code units needed to represent the s...

112,044 0       JAVA STRING ENCODING SAMPLE UTF8


  Different types of keystore in Java -- PKCS12

PKCS12 is an active file format for storing cryptography objects as a single file. It can be used to store secret key, private key and certificate.It is a standardized format published by RSA Laboratories which means it can be used not only in Java but also in other libraries in C, C++ or C# etc. This file format is frequently used to import and export entries from or to other keystore types.Next we will explain the operations which can be performed on PKCS12 keystore.Create PKCS12 keystoreBefore storing an entry into a PKCS12 keystore, the keystore has to be loaded first. This means we have t...

77,889 10       JAVA PKCS12 KEYSTORE TUTORIAL


  A HTTPS client and HTTPS server demo in Java

In this post, I will create a HTTPS server and HTTPS client demo which can establish HTTPS communication between a server and a client using Java. This should be very useful when we want to test our understanding about SSL communication. We will use both a detailed SSL client and a simple HttpsURLConnection as the HTTPS client.Before creating the actual HTTPS server and HTTPS client, we first need to generate the keystore and truststore to be used by the server and client. To generate the keystore, we can follow instructions at Different types of keystore in Java -- JKS. In this demo, we ...

69,353 5       JAVA SSL DEMO HTTPS


  try { return } finally {}

Do you know what value will be printed when following program is ran?class Test { public int aaa() { int x = 1; try { return ++x; } catch (Exception e) { } finally { ++x; } return x; } public static void main(String[] args) { Test t = new Test(); int y = t.aaa(); System.out.println(y); }}And before answering the above question, do you have answers to following questions?If there is a return statement in try block, will the finally block be executed when the return is executed?If finally will be exe...

57,166 4       JAVA JAVA INTERVIEW QUESTION


  ConcurrentHashMap vs Collections.synchronizedMap()

ConcurrentHashMap and Collections.synchronizedMap() both provide thread-safe operations of collections of data. They are used in multithreaded programs to provide both thread safety and performance improvements. In many cases, we can use either of them.But the realization of thread safety is different for these two implementations. ConcurrentHashMap will create an HashEntry[] array internally to store the elements passed in from a Map, while Collections.synchronizedMap() will return a SynchronizedMap.The main difference between these two is that ConcurrentHashMap will lock only portion of the ...

56,377 1       CONCURRENTHASHMAP COLLECTIONS.SYNCHRONIZEDMAP


  Android socket programming example

Socket is a kind of interface for different sides t communicate, it usually identified by an IP and a port. There are many server side software on a server and they would provide different service. Each server many create some sockets and bind them to some ports so that clients can listen to.Software on the Internet will exchange data though a bidirectional connection established. Each end of the connection has a socket created. In Java, Socket and ServerSocket are in java.net package, ServerSocket is used for server side and Socket is used when establishing connection. Once a successful conne...

55,832 3       JAVA ANDROID SOCKET


  Different types of keystore in Java -- JCEKS

JCEKS stands for Java Cryptography Extension KeyStore and it is an alternative keystore format for the Java platform. Storing keys in a KeyStore can be a measure to prevent your encryption keys from being exposed. Java KeyStores securely contain individual certificates and keys that can be referenced by an alias for use in a Java program.The process of storing and loading different entries in JCEKS is similar to what JKS does. So please refer to the article Different types of keystore in Java -- JKS. Change the keystore type from JKS to JCEKS accordingly when calling KeyStore.getInstance().In ...

53,112 1       JAVA TUTORIAL KEYSTORE JCEKS