Displaying keyword search results 1 - 10
Created by Dr. Xi on May 02, 2011 15:59:37 Last update: February 25, 2012 09:16:37
This code snippet gets the default keystore used by the Java keytool and displays the list of aliases along with the key type (certificate or private key).
import java.io.File; import java.io.FileInputSt...The default keystore used by the above code is: $HOME/.keystore .
Created by Dr. Xi on April 05, 2011 08:04:37 Last update: April 05, 2011 08:11:37
There's no difference between a Java HTTP client and a Java HTTPS client. Ignore JavaWorld Java Tip 96 , it's way too old. The following code gets an HTTP page as well as an HTTPS page.
import java.io.*; import java.net.*; pub...There's one catch . If you are using the code on a test server with a self-signed certificate, it fails. In that case, I would suggest that you download the certificate from the server and import it to your keystore as a trusted key. You may also need to add a subject alternative name to the certificate if the host name does not match the certificate. You may also choose to use a custom TrustManager and HostnameVerifier to ignore the certificate verification errors.
Created by Dr. Xi on October 16, 2008 20:45:40 Last update: March 28, 2011 20:23:22
Java's built-in classes are way too complex/flexible for a simple protocol like HTTP. This is a wrapper to simplify HTTP GET and POST.
import java.io.*; import java.net.*; imp...A simple test:
import java.io.*; import java.util.*; ...
Created by Dr. Xi on December 12, 2007 22:57:22 Last update: March 25, 2011 15:05:40
1. Install windows resource kit . 2. Install srvany as a service:
C:\tools\putty>instsrv ssh_tunnel "C:\Program File...3. Edit the following registry template to suite your environment:
Windows Registry Editor Version 5.00 [H...4. Import the registry entry. 5. Start the service with "net start ssh_tunnel" or from the services applet. You may choose to use a batch file for srvany (instead of plink.exe ), but you won't be able to shut down the tunnel when you stop the service. Also, if the Windows SYSTEM user cannot see the host key for SSH connection, the tunnel cannot be established.
Created by Dr. Xi on November 08, 2010 20:44:12 Last update: November 08, 2010 20:44:12
Key points: Java String.matches() matches the entire string, not a partial string. Use java.util.regex.Matcher.find() to match a partial String. For case insensitive match, use Pattern.compile with case insensitive flags:
// Case insensitive for ASCII Pattern p = P...Use (?i) or (?iu) (for unicode) to inline case-insensitive flag:
boolean b = "StringToMatchAgainst".matches("(?...Test code:
import java.util.regex.*; public class Test...
Created by Dr. Xi on October 26, 2010 16:07:40 Last update: October 26, 2010 16:07:40
This is a more generic version, which can be expanded to accommodate additional file signatures.
import java.io.*; import java.util.*; pu...
Created by Dr. Xi on July 19, 2010 21:58:34 Last update: July 23, 2010 21:37:23
Parsing XML in Java is really simple:
import java.io.*; import javax.xml.parsers.Docu...The parser implementation details are hidden behind the JAXP API. In case you want to know which parser implementation is used, this is what the JavaDoc for DocumentBuilderFactory.newInstance says: Use the javax.xml.parsers.DocumentBuilderFactory system property. Use the properties file " lib/jaxp.properties " in the JRE directory. This configuration file is in standard java.util.Properties format and contains the fully qualified name of the implementation class with the key being the system property defined above. The jaxp.properties file is read only once by the JAXP implementation and it's values are then cached for future use. If the file does not exist when the first attempt is made to read from it, no further attempts are made to...
Created by Dr. Xi on June 20, 2010 14:35:17 Last update: June 20, 2010 14:35:17
This XML signature validator comes from the Apache XML Security project. It validates the signature according to the core validation processing rules . It does not verify that the key used to generate the signature is a trusted key. You can override the KeySelector class to make sure that the signing key is from a trusted store.
import javax.xml.crypto.*; import javax.xml.cry...
Created by Dr. Xi on June 19, 2010 04:34:01 Last update: June 19, 2010 04:39:13
Java SE 6 contains built-in utilities to generate XML signatures. This is an example that generates XML signatures using a Java keystore. It has options to generate signature for the whole document, for an element with a specific ID, or for elements matched by an XPATH expression. The XML document used to test is taken from Getting Started with XML Security :
<?xml version="1.0"?> <PatientRecord> ...This is the Java code:
import java.io.FileInputStream; import java.io....However, it looks like the XPATH transform is not working. The digest generated with XPATH filter is exactly the same as that without it (i.e., the whole document)! Another reference: Programming With the Java XML Digital Signature API
Created by Dr. Xi on February 24, 2010 21:13:05 Last update: February 24, 2010 21:19:54
This program demonstrates the use of the java.nio package to implement a single thread echo server.
import java.io.IOException; import java.net.Ine...