public class Utils
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
PROPERTYNAME_HTTPS_NON_PROXY_HOSTS
Constant string "https.nonProxyHosts".
|
static java.lang.String |
PROPERTYNAME_HTTPS_PROXY_HOST
Constant string "https.proxyHost".
|
static java.lang.String |
PROPERTYNAME_HTTPS_PROXY_PASSWORD
Constant string "https.proxyPassword".
|
static java.lang.String |
PROPERTYNAME_HTTPS_PROXY_PORT
Constant string "https.proxyPort".
|
static java.lang.String |
PROPERTYNAME_HTTPS_PROXY_USER
Constant string "https.proxyUser".
|
Modifier and Type | Method and Description |
---|---|
static byte[] |
base64Encode(byte[] in)
Encodes a binary byte array into Base64.
|
static java.lang.String |
certTypeToString(int certType)
Returns a string description of a certificate type.
|
static boolean |
equalsBlock(byte[] a,
byte[] b)
Check two blocks for equality.
|
static boolean |
equalsBlock(byte[] a,
int aOff,
byte[] b,
int bOff,
int len)
Check two blocks for equality.
|
static java.security.KeyPair |
generateKeyPair(java.security.KeyPairGenerator kpg)
Generate a keypair in a way compatible with both JDK 1.1 and JDK 1.2.
|
static java.io.BufferedReader |
getASCIIReader(java.io.InputStream in)
Get a reader that returns data from the stream assuming ASCII encoding
is used.
|
static java.io.PrintWriter |
getASCIIWriter(java.io.OutputStream out)
Get a writer that writes data to the stream in ASCII encoding
is used.
|
static java.io.PrintWriter |
getASCIIWriter(java.io.OutputStream out,
boolean autoflush)
Get a writer that writes data to the stream in ASCII encoding
is used.
|
static int |
getCertificateType(java.security.cert.X509Certificate cert)
Get the type of a certificate.
|
static int |
getCertificateType(java.security.cert.X509Certificate[] certChain)
Get the type of a certificate.
|
static int |
getCertificateTypeWithoutKeyUsage(java.security.cert.X509Certificate cert)
Get the type of a certificate.
|
static int |
getCertificateTypeWithoutKeyUsage(java.security.cert.X509Certificate[] certChain)
Get the type of a certificate.
|
static java.lang.String |
getVersionString(int version)
Returns a String representation of the SSL version number.
|
static SSLSocket |
proxyConnect(java.net.InetAddress address,
int port,
SSLContext context)
Connects to the specified host via HTTPS proxy (if set via properties).
|
static SSLSocket |
proxyConnect(java.net.InetAddress address,
int port,
SSLContext context,
java.net.InetAddress proxyAddress,
int proxyPort)
Connects to the specified host via HTTPS proxy.
|
static SSLSocket |
proxyConnect(java.lang.String host,
int port,
SSLContext context)
Connects to the specified host via HTTPS proxy (if set via properties).
|
static SSLSocket |
proxyConnect(java.lang.String host,
int port,
SSLContext context,
java.net.InetAddress proxyAddress,
int proxyPort)
Connects to the specified host via HTTPS proxy.
|
static SSLSocket |
proxyConnect(java.lang.String host,
int port,
SSLContext context,
java.net.Socket proxySocket)
Connects to the specified host via HTTPS proxy.
|
static SSLSocket |
proxyConnect(java.lang.String host,
int port,
SSLContext context,
java.net.Socket proxySocket,
java.lang.String authenticationMechanism,
java.lang.String authenticationMessage,
int timeout)
Connects to the specified host via HTTPS proxy.
|
static java.lang.String |
toString(byte[] b)
Returns a hexadecimal representation of the contents of the
given byte array.
|
static java.lang.String |
toString(int a) |
static java.lang.String |
versionToName(int version)
Gets a the protocol version name of the given version number.
|
public static final java.lang.String PROPERTYNAME_HTTPS_PROXY_HOST
public static final java.lang.String PROPERTYNAME_HTTPS_PROXY_PORT
public static final java.lang.String PROPERTYNAME_HTTPS_PROXY_USER
public static final java.lang.String PROPERTYNAME_HTTPS_PROXY_PASSWORD
public static final java.lang.String PROPERTYNAME_HTTPS_NON_PROXY_HOSTS
public static boolean equalsBlock(byte[] a, int aOff, byte[] b, int bOff, int len)
a
- the first byte array to be comparedaOff
- the offset indicating the start position of the sub-block of a
b
- the second byte array to be comparedbOff
- the offset indicating the start position of the sub-block of b
len
- the number of bytes to be comparedtrue
, if the two sub-blocks are equal, false
otherwisepublic static boolean equalsBlock(byte[] a, byte[] b)
a
- the first byte array to be comparedb
- the second byte array to be comparedtrue
, if the two blocks are equal, false
otherwisepublic static java.lang.String toString(byte[] b)
b
- the byte array for which to get a hexadecimal representationpublic static java.lang.String toString(int a)
public static java.lang.String versionToName(int version)
version
- the version number as integerjava.lang.IllegalArgumentException
- if the given protocol is not supportedpublic static SSLSocket proxyConnect(java.net.InetAddress address, int port, SSLContext context) throws java.io.IOException
address
- the target host addressport
- the target portcontext
- the SSLContext for configuring the SSLSocketjava.io.IOException
- if an error occurs while trying to connectpublic static SSLSocket proxyConnect(java.lang.String host, int port, SSLContext context) throws java.io.IOException
host
- the target hostport
- the target portcontext
- the SSLContext for configuring the SSLSocketjava.io.IOException
- if an error occurs while trying to connectpublic static SSLSocket proxyConnect(java.net.InetAddress address, int port, SSLContext context, java.net.InetAddress proxyAddress, int proxyPort) throws java.io.IOException
address
- the address target hostport
- the target portcontext
- the SSLContext for configuring the SSLSocketproxyAddress
- the address of the proxyproxyPort
- the port of the proxyIOExcaption
- if an error occurs while trying to connectjava.io.IOException
public static SSLSocket proxyConnect(java.lang.String host, int port, SSLContext context, java.net.InetAddress proxyAddress, int proxyPort) throws java.io.IOException
host
- the target hostport
- the target portcontext
- the SSLContext for configuring the SSLSocketproxyAddress
- the address of the proxyproxyPort
- the port of the proxyIOExcaption
- if an error occurs while trying to connectjava.io.IOException
public static SSLSocket proxyConnect(java.lang.String host, int port, SSLContext context, java.net.Socket proxySocket) throws java.io.IOException
host
- the target hostport
- the target portcontext
- the SSLContext for configuring the SSLSocketproxySocket
- the socket for talking with the proxyjava.io.IOException
- if an error occurs while trying to connectpublic static SSLSocket proxyConnect(java.lang.String host, int port, SSLContext context, java.net.Socket proxySocket, java.lang.String authenticationMechanism, java.lang.String authenticationMessage, int timeout) throws java.io.IOException
host
- the target hostport
- the target portcontext
- the SSLContext for configuring the SSLSocketproxySocket
- the socket for talking with the proxyauthenticationMechanism
- the authentication mechanism (e.g. "Basic..."); must
not be set by the application (i.e. can be null)authenticationMessage
- the authentication string specifying authentication method
(e.g. "Basic" and base64 encoded proxy username and password;
maybe null in which case proxy username and password have to
be set via system properties "https.proxyUser"
and "https.proxyPassword"
timeout
- the timeout for the proxy response (default: 30 seconds)java.io.IOException
- if an error occurs while trying to connectpublic static int getCertificateType(java.security.cert.X509Certificate cert)
cert
- the certificate for which to get the cert typepublic static int getCertificateType(java.security.cert.X509Certificate[] certChain)
certChain
- the certificate chain for which to get the cert type
(for the certificate at index 0)public static int getCertificateTypeWithoutKeyUsage(java.security.cert.X509Certificate cert)
cert
- the certificate for which to get the cert typepublic static int getCertificateTypeWithoutKeyUsage(java.security.cert.X509Certificate[] certChain)
certChain
- the certificate chain for which to get the cert type
(for the certificate at index 0)public static java.lang.String certTypeToString(int certType)
certType
- the certificate type for which to get a string descriptionpublic static java.io.BufferedReader getASCIIReader(java.io.InputStream in)
public static java.io.PrintWriter getASCIIWriter(java.io.OutputStream out)
public static java.io.PrintWriter getASCIIWriter(java.io.OutputStream out, boolean autoflush)
public static java.lang.String getVersionString(int version)
version
- the SSL version numberpublic static java.security.KeyPair generateKeyPair(java.security.KeyPairGenerator kpg)
public static byte[] base64Encode(byte[] in) throws java.io.IOException
Base64 is the encoding format used by Multipurpose Internet Mail Extension (Mime) for transmitting non-text material over text-only communications channels. Base64 is based on a 65-character subset of US-ASCII, enabling 6 bits to be represented per printable character (see RFC 1521).
in
- the binary data to be Base64 encodedjava.io.IOException