public class Common extends Object
| Modifier and Type | Field and Description |
|---|---|
static int |
MAX_NDN_PACKET_SIZE
The practical limit of the size of a network-layer packet.
|
| Constructor and Description |
|---|
Common() |
| Modifier and Type | Method and Description |
|---|---|
static byte[] |
base64Decode(String encoding)
Decode the input as base64 using the appropriate base64Converter_ from
establishBase64Converter(), for ANDROID or Java 7+.
|
static String |
base64Encode(byte[] input)
Encode the input as base64 using the appropriate base64Converter_ from
establishBase64Converter(), for ANDROID or Java 7+.
|
static String |
base64Encode(byte[] input,
boolean addNewlines)
Encode the input as base64 using the appropriate base64Converter_ from
establishBase64Converter(), for ANDROID or Java 7+.
|
static byte[] |
computeHmacWithSha256(byte[] key,
ByteBuffer data)
Compute the HMAC with SHA-256 of data, as defined in
http://tools.ietf.org/html/rfc2104#section-2 .
|
static byte[] |
computePbkdf2WithHmacSha1(byte[] password,
byte[] salt,
int nIterations,
int resultLength)
Compute the PBKDF2 with HMAC SHA1 of the password.
|
static byte[] |
computePbkdf2WithHmacSha1(char[] password,
byte[] salt,
int nIterations,
int resultLength)
Compute the PBKDF2 with HMAC SHA1 of the password.
|
static long |
dateToMillisecondsSince1970(Date date)
Convert a Date object milliseconds.
|
static byte[] |
digestSha256(byte[] data)
Compute the sha-256 digest of data.
|
static byte[] |
digestSha256(ByteBuffer data)
Compute the sha-256 digest of data.
|
static File |
getCurrentDirectory()
Get the current directory.
|
static File |
getHomeDirectory()
Get the user's home directory.
|
static double |
getNowMilliseconds()
Get the current time in milliseconds.
|
static Random |
getRandom()
Get the library-wide random number generator.
|
static Date |
millisecondsSince1970ToDate(long millisecondsSince1970)
Convert the milliseconds to a Date object.
|
static boolean |
platformIsOSX()
Return true if the platform is OS X.
|
static void |
setRandom(Random randomNumberGenerator)
Set the library-wide random number generator; this method will only allow the generator to be set once.
|
static String |
toHex(byte[] buffer)
Return a hex string of the contents of buffer.
|
public static final int MAX_NDN_PACKET_SIZE
public static double getNowMilliseconds()
public static Random getRandom()
setRandom(Random) or (by default) a SecureRandompublic static void setRandom(Random randomNumberGenerator)
randomNumberGenerator - the random number generatorUnsupportedOperationException - if a user attempts to set the generator a second timepublic static byte[] digestSha256(ByteBuffer data)
data - The input byte buffer. This does not change the position.public static byte[] digestSha256(byte[] data)
data - The input byte buffer.public static byte[] computeHmacWithSha256(byte[] key,
ByteBuffer data)
key - The key byte array.data - The input byte buffer.public static byte[] computePbkdf2WithHmacSha1(char[] password,
byte[] salt,
int nIterations,
int resultLength)
throws NoSuchAlgorithmException,
InvalidKeySpecException
password - The input password, which should have characters in the
range of 1 to 127.salt - The 8-byte salt.nIterations - The number of iterations of the hashing algorithm.resultLength - The number of bytes of the result array.NoSuchAlgorithmExceptionInvalidKeySpecExceptionpublic static byte[] computePbkdf2WithHmacSha1(byte[] password,
byte[] salt,
int nIterations,
int resultLength)
throws NoSuchAlgorithmException,
InvalidKeySpecException
password - The input password, which should have values in the
range of 1 to 127.salt - The 8-byte salt.nIterations - The number of iterations of the hashing algorithm.resultLength - The number of bytes of the result array.NoSuchAlgorithmExceptionInvalidKeySpecExceptionpublic static String toHex(byte[] buffer)
buffer - The buffer.public static String base64Encode(byte[] input)
input - The bytes to encode.UnsupportedOperationException - If can't establish a base64 converter for
this platform.public static String base64Encode(byte[] input, boolean addNewlines)
input - The bytes to encode.addNewlines - If true, add newlines to the output (good for writing to
a file). If false, do not add newlines.UnsupportedOperationException - If can't establish a base64 converter for
this platform.public static byte[] base64Decode(String encoding) throws SecurityException
encoding - The base64 string.UnsupportedOperationException - If can't establish a base64 converter for
this platform.SecurityExceptionpublic static Date millisecondsSince1970ToDate(long millisecondsSince1970)
millisecondsSince1970 - The milliseconds since 1970.public static long dateToMillisecondsSince1970(Date date)
date - the Date object.public static boolean platformIsOSX()
public static File getHomeDirectory()
public static File getCurrentDirectory()
Copyright © 2019. All rights reserved.