public class SSLUtil extends Object
Constructor and Description |
---|
SSLUtil() |
Modifier and Type | Method and Description |
---|---|
static boolean |
isSSLPacket(byte[] header)
Determines if a given header is a SSL packet
(has a SSL header)
|
static boolean |
isSSLv2HelloPacket(byte[] header)
Determines if a given header is a SSLv2 client or server hello packet
|
static boolean |
isSSLv3Packet(byte[] header)
Determines if a given header is a SSLv3 packet
(has a SSL header) or a backward compatible version of TLS
using the same header format.
|
static int |
read(InputStream in,
byte[] buf,
int off,
int len)
Reads some number of bytes from the input stream.
|
static void |
readFully(InputStream in,
byte[] buf,
int off,
int len)
Reads some number of bytes from the input stream.
|
static byte[] |
readSslMessage(InputStream in)
Reads an entire SSL message from the specified
input stream.
|
static int |
toInt(byte[] buf,
int off)
Converts 4 bytes to an
int at
the specified offset in the given byte array. |
static long |
toLong(byte[] buf,
int off)
Converts 8 bytes to a
long at the
specified offset in the given byte array. |
static short |
toShort(byte a,
byte b)
Converts 2 bytes to a
short . |
static int |
toUnsignedShort(byte a,
byte b)
Converts 2 bytes to a
unsigned short . |
static void |
writeInt(int v,
byte[] buf,
int off)
Converts the specified int value into
4 bytes.
|
public static int read(InputStream in, byte[] buf, int off, int len) throws IOException
in
- the input stream to read the bytes from.buf
- the buffer into which read the data is read.off
- the start offset in array b at which the data is written.len
- the maximum number of bytes to read.IOException
- if I/O error occurs.public static void readFully(InputStream in, byte[] buf, int off, int len) throws IOException
in
- the input stream to read the bytes from.buf
- the buffer into which read the data is read.off
- the start offset in array b at which the data is written.len
- the maximum number of bytes to read.IOException
- if I/O error occurs.public static byte[] readSslMessage(InputStream in) throws IOException
in
- the input stream to read the SSL message
from.IOException
- if I/O error occurs.public static final boolean isSSLPacket(byte[] header)
public static final boolean isSSLv3Packet(byte[] header)
public static final boolean isSSLv2HelloPacket(byte[] header)
public static short toShort(byte a, byte b)
short
.a
- byte 1b
- byte 2short
value of the 2 bytespublic static int toUnsignedShort(byte a, byte b)
unsigned short
.a
- byte 1b
- byte 2unsigned short
value of the 2 bytespublic static int toInt(byte[] buf, int off)
int
at
the specified offset in the given byte array.buf
- the byte array containing the 4 bytes
to be converted to an int
.off
- offset in the byte arrayint
value of the 4 bytes.public static void writeInt(int v, byte[] buf, int off)
v
- the int value to convert into 4 bytes.buf
- the byte array to put the resulting
4 bytes.off
- offset in the byte arraypublic static long toLong(byte[] buf, int off)
long
at the
specified offset in the given byte array.buf
- the byte array containing the 8 bytes
to be converted to a long
.off
- offset in the byte arraylong
value of the 8 bytes.Copyright © 2016. All rights reserved.