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

 JAVA


  Three images to understand immutability of String in Java

String is immutable in Java. This means once a String object is created and instantiated, that object cannot be changed. Any operation on the String object will create a new Object instead of operating on the original content. Below are three images to help you understand String immutability in Java.Declare a StringString s = "abcd";s stores the reference to the string content created in the heap.Assign the String reference to another String variableString s2 = s;s2 stores the same reference to the same String object. Since the content is not changed, there will be only one actual object ...

4,451 1       JAVA STRING


  Access control in Java -- doPrivileged

Previously we have introduced how Java performs permission check to protect resource access. What if sometimes we need to give some class the temporary access to some resource which it initially doesn't have? AccessController provides six doPrivileged methods to fulfill this requirement.These six methods have below signatures :static T doPrivileged(PrivilegedAction action)static T doPrivileged(PrivilegedAction action, AccessControlContext context)static T doPrivileged(PrivilegedExceptionAction action)static T doPrivileged(PrivilegedExceptionAction action, AccessControlContext context)stat...

3,450 0       JAVA SECURITY DOPRIVILEGED


  Access control in Java -- Permission check order

Previously we showed you how to turn on SecurityManager in Java. After SecurityManager is turned on, a series of permission checks will be applied on the code you are calling in your application to protect some resources against malicious access such as files, sockets etc.To perform these permission checks, a set of Permissions will be created and checked using the AccessController. The AccessController has three purposes :To decide whether an access to a critical system resource is to be allowed or denied, based on the security policy currently in effect,To mark code as being "privileged", th...

3,367 0       JAVA SECURITY ACCESSCONTROLLER


  Canonicalize XML in Java

XML canonicalization is often used when there is need to create digital signature to be sent to peers for verification. Since digital signature is created based on XML data, the XML data has to be canonicalized before its signature value can be calculated. Even an extra space may affect the signature value calculated, hence it must follow some rules to canonicalize the XML data so that it has a standard format. This is why W3C created specification Canonical XML Version 1.1.This specification provides the rules to format element nodes, attribute nodes and namespace nodes etc. Different pr...

15,856 0       JAVA XML JAVA SECURITY


  NIO vs IO in Java

Java 1.4 provides a new API for handling IO -- NIO. This is a non-blocking and buffer oriented IO API.Below are main differences between the NIO and IO in Java.IONIOStream orientedBuffer orientedBlocking IONon-blocking ION/AUsing selectorStream oriented vs Buffer orientedThe main difference is that IO is stream oriented where the data is read byte by byte and the data will not be buffered normally.This means there is no pointer to move forward and backward in the stream. If there is a need to move forward and backward of the stream, the data needs to be explicitly copied to a buffer. While Jav...

5,275 0       JAVA IO NIO


  Using Java keytool programmatically

Java provides a command line tool to access and operate different keystore which store keys and certificates. This tool is named keytool and is located at \bin. On command line, you can issue below command to generate a keystore named mytest.jks which contains a private key and certificate chain.keytool -genkeypair -alias mykey -keyalg RSA -sigalg SHA256withRSA -dname CN=Java -storetype JKS -keypass password -keystore mytest.jks -storepass passwordSometimes, in testing purpose, we may want to issue these command in our applications instead of start a command line terminal. This is...

23,657 14       JAVA KEYTOOL


  Different types of keystore in Java -- Windows-MY

Windows-MY is a type of keystore on Windows which is managed by the Windows operating system. It stores the user keys and certificates which can be used to perform cryptographic operations such as signature verification, data encryption etc. Since it's a kind of native keystore, Java doesn't have a general API to access it.To help Java applications access the keys and certificates stored in Windows-MY keystore, Java provides a separate API -- SunMSCAPI. The SunMSCAPI provider is layered on top of CAPI and helps Java platform applications access CAPI cryptographic services using ...

34,868 6       JAVA KEYSTORE WINDOWS-MY SUNMSCAPI


  Using keytool to create certificate chain

JDK provides a command line tool -- keytool to handle key and certificate generation. This tool has a set of options which can be used to generate keys, create certificates, import keys, install certificate and export certificates etc. In this tutorial, we will show how to create certificate chain using keytool. If you want to understand how to create certificate chain programmably, please refer to Generate certificate in Java -- Certificate chain.To begin, we first generate a key pair which will be used as the CA, ts private key will be used to sign the certificate it issues.keytool -gen...

47,923 1       JAVA CERTIFICATE CERTIFICATE CHAIN KEYTOOL