public abstract class Util
extends java.lang.Object
Modifier and Type | Field | Description |
---|---|---|
static byte |
CASE_DIFF |
Constructor | Description |
---|---|
Util() |
Modifier and Type | Method | Description |
---|---|---|
static byte[] |
concat(byte[] first,
byte[] second) |
|
static byte[] |
constructPbkdf2Encoding(byte[] salt,
int iterations,
int keyLength,
byte[] mac) |
|
static byte[] |
convertSlashlessHandleToZeroNaHandle(byte[] handle) |
|
static int |
countValuesOfType(HandleValue[] values,
byte[] type) |
|
static java.lang.String |
decodeHexString(byte[] buf,
boolean formatNicely) |
|
static java.lang.String |
decodeHexString(byte[] buf,
int offset,
int len,
boolean formatNicely) |
|
static java.lang.String |
decodeString(byte[] buf) |
|
static java.lang.String |
decodeString(byte[] buf,
int offset,
int len) |
|
static byte[] |
decrypt(byte[] ciphertext,
byte[] secretKey) |
Decrypt the given set of bytes using the specified secret key
|
static byte[] |
decrypt(java.security.PrivateKey privKey,
byte[] ciphertext) |
Deprecated.
|
static byte[] |
decrypt(java.security.PrivateKey privKey,
byte[] ciphertext,
int majorProtocolVersion,
int minorProtocolVersion) |
|
static byte[] |
doDigest(byte[] digestType,
byte[]... bufs) |
|
static byte[] |
doDigest(byte digestType,
byte[]... bufs) |
|
static byte[] |
doHmacSHA1(byte[] buf,
byte[] key) |
|
static byte[] |
doHmacSHA256(byte[] buf,
byte[] key) |
|
static byte[] |
doMac(byte[] digestType,
byte[] buf,
byte[] key) |
|
static byte[] |
doMac(byte digestType,
byte[] buf,
byte[] key) |
|
static byte[] |
doMac(byte digestType,
byte[] buf,
byte[] key,
byte[] paramsToMatch) |
|
static byte[] |
doMD5Digest(byte[]... bufs) |
|
static byte[] |
doPBKDF2(byte[] password,
byte[] salt,
int iterations,
int length) |
|
static byte[] |
doPbkdf2HmacSHA1(byte[] buf,
byte[] key,
byte[] paramsToMatch) |
|
static byte[] |
doSHA1Digest(byte[]... bufs) |
|
static byte[] |
doSHA256Digest(byte[]... bufs) |
|
static byte[] |
duplicateByteArray(byte[] buf) |
|
static byte[] |
encodeHexString(java.lang.String s) |
|
static byte[] |
encodeString(java.lang.String s) |
Encoded the specified string into a byte array
|
static byte[] |
encrypt(byte[] cleartext,
byte[] secretKey) |
Encrypt the given set of bytes using the specified secret key and
the default encryption algorithm.
|
static byte[] |
encrypt(byte[] cleartext,
byte[] secretKey,
int encType) |
Encrypt the given set of bytes using the specified secret key
and encryption algorithm.
|
static byte[] |
encrypt(java.security.PublicKey encryptingKey,
byte[] secretKey) |
Deprecated.
|
static byte[] |
encrypt(java.security.PublicKey encryptingKey,
byte[] secretKey,
int majorProtocolVersion,
int minorProtocolVersion) |
encrypt with Public key
|
static boolean |
equals(byte[] b1,
byte[] b2) |
compare the two arrays.
|
static boolean |
equals(byte[] b1,
int b1Start,
byte[] b2,
int b2Start) |
compare the two arrays starting at the given index.
|
static boolean |
equalsCI(byte[] b1,
byte[] b2) |
Determine if the first parameter equals the second
parameter in a case insensitive comparison.
|
static boolean |
equalsCI(byte[] b1,
int b1Len,
byte[] b2,
int b2Len) |
Determine if the first parameter equals the second parameter
in a case insensitive manner over the given length.
|
static boolean |
equalsCI(java.lang.String s1,
java.lang.String s2) |
|
static boolean |
equalsIgnoreCaseAndPunctuation(byte[] a,
byte[] b) |
|
static boolean |
equalsPrefixCI(byte[] b1,
byte[] b2) |
Determine if the first parameter equals the second
parameter in a case insensitive (within prefix) comparison;
for global handles, entire handles are compared case insensitively.
|
static boolean |
equalsPrefixCI(byte[] b1,
int b1Len,
byte[] b2,
int b2Len) |
Determine if the first parameter equals the second parameter
in a case insensitive (within prefix) manner over the given length;
for global handles, entire handles are compared case insensitively.
|
static boolean |
equalsPrefixCI(java.lang.String s1,
java.lang.String s2) |
Determine if the first parameter equals the second
parameter in a case insensitive (within prefix) comparison;
for global handles, entire handles are compared case insensitively.
|
static byte[] |
fill16(byte[] bytes) |
|
static java.util.List<HandleValue> |
filterOnlyPublicValues(java.util.List<HandleValue> values) |
|
static HandleValue[] |
filterValues(HandleValue[] allValues,
int[] indexList,
byte[][] typeList) |
|
static java.lang.String |
getAccessLogString(AbstractRequest req) |
|
static SiteInfo |
getAltSiteInfo(SiteInfo site) |
|
static byte[] |
getBytesFromFile(java.io.File file) |
|
static byte[] |
getBytesFromFile(java.lang.String file) |
convert a file into a byte stream
|
static byte[] |
getBytesFromInputStream(java.io.InputStream in) |
|
static byte[] |
getBytesFromPrivateKey(java.security.PrivateKey key) |
|
static byte[] |
getBytesFromPublicKey(java.security.PublicKey key) |
|
static java.lang.String |
getDefaultSigId(java.lang.String algorithm) |
|
static java.lang.String |
getDefaultSigId(java.lang.String algorithm,
AbstractMessage message) |
|
static byte[] |
getHashAlgIdFromSigId(java.lang.String signatureAlgorithm) |
Get the ID that the handle protocol uses to identify the hash algorithm
used in the given signature algorithm descriptor.
|
static byte[] |
getIDPart(byte[] handle) |
Deprecated.
use getSuffixPart(byte[]) instead
|
static byte[] |
getNAHandle(byte[] handle) |
Deprecated.
use getZeroNAHandle(byte[]) instead
|
static NamespaceInfo |
getNamespaceFromValues(HandleValue[] values) |
Extract and return the namespace information contained in the given
handle values.
|
static byte[] |
getNAPart(byte[] handle) |
Deprecated.
use getPrefixPart(byte[]) instead
|
static int |
getNextUnusedIndex(HandleValue[] values,
int firstIdx) |
|
static byte[] |
getParentNAOfNAHandle(byte[] naHandle) |
Get the parent prefix handle for the given prefix
handle.
|
static java.lang.String |
getParentNAOfNAHandle(java.lang.String naHandle) |
|
static byte[] |
getPassphrase(java.lang.String prompt) |
Get a passphrase from the user.
|
static byte[] |
getPrefixPart(byte[] handle) |
Get only the prefix part of this handle.
|
static java.lang.String |
getPrefixPart(java.lang.String handle) |
|
static SiteInfo |
getPrimarySite(SiteInfo[] sites) |
|
static java.security.PrivateKey |
getPrivateKeyFromBytes(byte[] pkBuf) |
|
static java.security.PrivateKey |
getPrivateKeyFromBytes(byte[] pkBuf,
int offset) |
|
static java.security.PrivateKey |
getPrivateKeyFromFileWithPassphrase(java.io.File privKeyFile,
java.lang.String passphrase) |
|
static java.security.PublicKey |
getPublicKeyFromBytes(byte[] pkBuf) |
|
static java.security.PublicKey |
getPublicKeyFromBytes(byte[] pkBuf,
int offset) |
|
static java.security.PublicKey |
getPublicKeyFromFile(java.lang.String filename) |
|
static java.util.List<java.security.PublicKey> |
getPublicKeysFromValues(HandleValue[] values) |
|
static java.lang.String |
getSigIdFromHashAlgId(byte[] hashAlgId,
java.lang.String sigKeyType) |
|
static SiteInfo[] |
getSitesAndAltSitesFromValues(HandleValue[] values) |
Extract and return all of the SiteInfo records from the given list
of handle values.
|
static SiteInfo[] |
getSitesAndAltSitesFromValues(HandleValue[] values,
byte[][] types) |
|
static SiteInfo[] |
getSitesFromValues(HandleValue[] values) |
Extract and return all of the SiteInfo records from the given list
of handle values.
|
static byte[] |
getSuffixPart(byte[] handle) |
Get only the suffix part of this handle.
|
static java.lang.String |
getSuffixPart(java.lang.String handle) |
|
static byte[] |
getZeroNAHandle(byte[] handle) |
Get the 0.NA authority handle that applies to the specified handle
|
static java.lang.String |
getZeroNAHandle(java.lang.String handle) |
|
static boolean |
hasSlash(byte[] handle) |
Return whether a handle has a slash
|
static int |
indexOf(byte[] b,
byte ch) |
|
static boolean |
isDerivedFrom(java.lang.String handle,
java.lang.String ancestorHandle) |
|
static boolean |
isHandleUnderPrefix(java.lang.String handle,
java.lang.String prefix) |
|
static boolean |
isInArray(byte[][] a,
byte[] val) |
returns true if the given byte array is contained in the
specified byte array array.
|
static boolean |
isInArray(int[] a,
int val) |
returns true if the given int value is in the specified array.
|
static boolean |
isMatchingKeyPair(java.security.PublicKey pubkey,
java.security.PrivateKey privkey) |
check that a given PublicKey and a given PrivateKey are a pair
|
static boolean |
isParentTypeInArray(byte[][] a,
byte[] val) |
Types in the array are either exact types (not ending in '.')
or prefixes of type families (ending in '.').
|
static boolean |
isSubNAHandle(byte[] handle) |
only for 0.NA/derived.prefix handles
|
static boolean |
isSubNAHandle(java.lang.String handle) |
|
static boolean |
isValidString(byte[] buf,
int offset,
int len) |
Returns true is the given byte array represents a valid
text string in the encoding used by the handle protocol (utf8).
|
static boolean |
looksLikeBinary(byte[] buf) |
|
static SiteInfo[] |
orderSitesByPreference(SiteInfo[] sites) |
rearranges the given sites in a more efficient order so that resolution
from the current location should tend to access the faster sites first.
|
static void |
readFully(java.io.InputStream in,
byte[] b) |
Like in.read(b), but attempts to read as many bytes as possible
|
static void |
readFully(java.io.InputStream in,
byte[] b,
int off,
int len) |
Like in.read(b, off, len), but attempts to read as many bytes as possible
|
static boolean |
requiresSecretKey(byte[] ciphertext) |
Returns true is the given ciphertext requires a secret key to be
decrypted (ie if the encryption algorithm is ENCRYPT_NONE).
|
static java.lang.String |
rfcIpPortRepr(java.net.InetAddress addr,
int port) |
|
static java.lang.String |
rfcIpRepr(byte[] ipv6Address) |
|
static java.lang.String |
rfcIpRepr(java.net.InetAddress addr) |
|
static void |
sortNumberArray(java.lang.Number[] a) |
|
static boolean |
startsWith(byte[] b1,
byte[] b2) |
|
static boolean |
startsWithCI(byte[] b1,
byte[] b2) |
Determine if the first parameter begins with the second
parameter in a case insensitive comparison.
|
static boolean |
startsWithCI(java.lang.String s1,
java.lang.String s2) |
|
static byte[] |
substring(byte[] b,
int i1) |
determine if the second UTF8 encoded parameter begins
with the second parameter in a case sensitive comparison.
|
static byte[] |
substring(byte[] b,
int i1,
int i2) |
|
static byte[] |
upperCase(byte[] b) |
create and return an upper-case copy of the given UTF8 byte array
|
static java.lang.String |
upperCase(java.lang.String s) |
|
static byte[] |
upperCaseInPlace(byte[] b) |
Convert all of the characters in the given utf-8 byte array
to upper case.
|
static byte[] |
upperCasePrefix(byte[] b) |
create and return an upper-case (prefix only, or all of a global handle) copy of the given UTF8 byte array
|
static java.lang.String |
upperCasePrefix(java.lang.String s) |
|
static byte[] |
upperCasePrefixInPlace(byte[] b) |
Convert all of the characters in the prefix of the given utf-8 byte array
to upper case; for global handles upper case all.
|
static boolean |
writeBytesToFile(java.io.File file,
byte[] keyBytes) |
|
static boolean |
writeBytesToFile(java.lang.String file,
byte[] keyBytes) |
write byte array into a given file name
|
public static final byte CASE_DIFF
public static final boolean looksLikeBinary(byte[] buf)
public static final byte[] duplicateByteArray(byte[] buf)
public static final java.lang.String decodeHexString(byte[] buf, int offset, int len, boolean formatNicely)
public static final java.lang.String decodeHexString(byte[] buf, boolean formatNicely)
public static final byte[] encodeHexString(java.lang.String s)
public static final byte[] encodeString(java.lang.String s)
public static final java.lang.String decodeString(byte[] buf)
public static final java.lang.String decodeString(byte[] buf, int offset, int len)
public static final boolean isValidString(byte[] buf, int offset, int len)
public static final boolean hasSlash(byte[] handle)
@Deprecated public static final byte[] getIDPart(byte[] handle)
@Deprecated public static final byte[] getNAPart(byte[] handle)
@Deprecated public static final byte[] getNAHandle(byte[] handle)
public static final byte[] getZeroNAHandle(byte[] handle)
public static java.lang.String getZeroNAHandle(java.lang.String handle)
public static final byte[] convertSlashlessHandleToZeroNaHandle(byte[] handle)
public static final boolean isSubNAHandle(byte[] handle)
public static boolean isSubNAHandle(java.lang.String handle)
public static final byte[] getParentNAOfNAHandle(byte[] naHandle)
public static java.lang.String getParentNAOfNAHandle(java.lang.String naHandle)
public static boolean isHandleUnderPrefix(java.lang.String handle, java.lang.String prefix)
public static boolean isDerivedFrom(java.lang.String handle, java.lang.String ancestorHandle)
public static final byte[] getPrefixPart(byte[] handle)
public static java.lang.String getPrefixPart(java.lang.String handle)
public static final byte[] getSuffixPart(byte[] handle)
public static java.lang.String getSuffixPart(java.lang.String handle)
public static final boolean startsWith(byte[] b1, byte[] b2)
public static final boolean equals(byte[] b1, byte[] b2)
public static final boolean equals(byte[] b1, int b1Start, byte[] b2, int b2Start)
public static final byte[] upperCase(byte[] b)
public static java.lang.String upperCase(java.lang.String s)
public static final byte[] upperCaseInPlace(byte[] b)
public static final byte[] upperCasePrefix(byte[] b)
public static java.lang.String upperCasePrefix(java.lang.String s)
public static final byte[] upperCasePrefixInPlace(byte[] b)
public static final boolean equalsCI(byte[] b1, byte[] b2)
public static boolean equalsCI(java.lang.String s1, java.lang.String s2)
public static final boolean equalsCI(byte[] b1, int b1Len, byte[] b2, int b2Len)
public static final boolean equalsPrefixCI(byte[] b1, byte[] b2)
public static final boolean equalsPrefixCI(java.lang.String s1, java.lang.String s2)
public static final boolean equalsPrefixCI(byte[] b1, int b1Len, byte[] b2, int b2Len)
public static final boolean startsWithCI(byte[] b1, byte[] b2)
public static boolean startsWithCI(java.lang.String s1, java.lang.String s2)
public static final byte[] substring(byte[] b, int i1)
public static final byte[] substring(byte[] b, int i1, int i2)
public static final int indexOf(byte[] b, byte ch)
public static final int countValuesOfType(HandleValue[] values, byte[] type)
public static java.lang.String rfcIpPortRepr(java.net.InetAddress addr, int port)
public static java.lang.String rfcIpRepr(byte[] ipv6Address)
public static java.lang.String rfcIpRepr(java.net.InetAddress addr)
public static final boolean isParentTypeInArray(byte[][] a, byte[] val)
public static final boolean isInArray(int[] a, int val)
public static final boolean isInArray(byte[][] a, byte[] val)
public static final int getNextUnusedIndex(HandleValue[] values, int firstIdx)
public static byte[] fill16(byte[] bytes)
public static SiteInfo[] getSitesFromValues(HandleValue[] values)
public static SiteInfo[] getSitesAndAltSitesFromValues(HandleValue[] values)
public static SiteInfo[] getSitesAndAltSitesFromValues(HandleValue[] values, byte[][] types)
public static NamespaceInfo getNamespaceFromValues(HandleValue[] values)
public static final SiteInfo[] orderSitesByPreference(SiteInfo[] sites)
public static HandleValue[] filterValues(HandleValue[] allValues, int[] indexList, byte[][] typeList)
public static java.util.List<HandleValue> filterOnlyPublicValues(java.util.List<HandleValue> values)
public static final byte[] getPassphrase(java.lang.String prompt) throws java.lang.Exception
java.lang.Exception
public static byte[] getHashAlgIdFromSigId(java.lang.String signatureAlgorithm) throws HandleException
HandleException
public static java.lang.String getSigIdFromHashAlgId(byte[] hashAlgId, java.lang.String sigKeyType) throws HandleException
HandleException
public static java.lang.String getDefaultSigId(java.lang.String algorithm)
public static java.lang.String getDefaultSigId(java.lang.String algorithm, AbstractMessage message) throws HandleException
HandleException
public static byte[] getBytesFromPrivateKey(java.security.PrivateKey key) throws java.lang.Exception
java.lang.Exception
public static java.security.PrivateKey getPrivateKeyFromBytes(byte[] pkBuf) throws HandleException, java.security.spec.InvalidKeySpecException
HandleException
java.security.spec.InvalidKeySpecException
public static java.security.PrivateKey getPrivateKeyFromBytes(byte[] pkBuf, int offset) throws HandleException, java.security.spec.InvalidKeySpecException
HandleException
java.security.spec.InvalidKeySpecException
public static byte[] getBytesFromPublicKey(java.security.PublicKey key) throws HandleException
HandleException
public static java.security.PublicKey getPublicKeyFromFile(java.lang.String filename) throws java.lang.Exception
java.lang.Exception
public static java.security.PublicKey getPublicKeyFromBytes(byte[] pkBuf) throws java.lang.Exception
java.lang.Exception
public static java.security.PublicKey getPublicKeyFromBytes(byte[] pkBuf, int offset) throws java.lang.Exception
java.lang.Exception
public static java.util.List<java.security.PublicKey> getPublicKeysFromValues(HandleValue[] values)
public static byte[] encrypt(byte[] cleartext, byte[] secretKey) throws java.lang.Exception
java.lang.Exception
public static byte[] encrypt(byte[] cleartext, byte[] secretKey, int encType) throws java.lang.Exception
java.lang.Exception
public static byte[] doPBKDF2(byte[] password, byte[] salt, int iterations, int length) throws java.security.NoSuchAlgorithmException, java.security.spec.InvalidKeySpecException
java.security.NoSuchAlgorithmException
java.security.spec.InvalidKeySpecException
public static byte[] constructPbkdf2Encoding(byte[] salt, int iterations, int keyLength, byte[] mac)
public static final boolean requiresSecretKey(byte[] ciphertext) throws java.lang.Exception
java.lang.Exception
public static byte[] decrypt(byte[] ciphertext, byte[] secretKey) throws java.lang.Exception
java.lang.Exception
public static final byte[] doSHA1Digest(byte[]... bufs) throws HandleException
HandleException
public static byte[] doHmacSHA1(byte[] buf, byte[] key) throws HandleException
HandleException
public static byte[] doHmacSHA256(byte[] buf, byte[] key) throws HandleException
HandleException
public static byte[] doPbkdf2HmacSHA1(byte[] buf, byte[] key, byte[] paramsToMatch) throws HandleException
HandleException
public static byte[] doSHA256Digest(byte[]... bufs) throws HandleException
HandleException
public static final byte[] doMD5Digest(byte[]... bufs) throws HandleException
HandleException
public static final byte[] doDigest(byte digestType, byte[]... bufs) throws HandleException
HandleException
public static final byte[] doMac(byte digestType, byte[] buf, byte[] key) throws HandleException
HandleException
public static final byte[] doMac(byte digestType, byte[] buf, byte[] key, byte[] paramsToMatch) throws HandleException
HandleException
public static final byte[] doDigest(byte[] digestType, byte[]... bufs) throws HandleException
HandleException
public static final byte[] doMac(byte[] digestType, byte[] buf, byte[] key) throws HandleException
HandleException
public static boolean equalsIgnoreCaseAndPunctuation(byte[] a, byte[] b)
public static void sortNumberArray(java.lang.Number[] a)
@Deprecated public static byte[] encrypt(java.security.PublicKey encryptingKey, byte[] secretKey) throws java.lang.Exception
java.lang.Exception
public static byte[] encrypt(java.security.PublicKey encryptingKey, byte[] secretKey, int majorProtocolVersion, int minorProtocolVersion) throws java.lang.Exception
java.lang.Exception
public static byte[] getBytesFromFile(java.lang.String file)
public static byte[] getBytesFromFile(java.io.File file)
public static byte[] getBytesFromInputStream(java.io.InputStream in) throws java.io.IOException
java.io.IOException
public static void readFully(java.io.InputStream in, byte[] b) throws java.io.IOException
java.io.IOException
public static void readFully(java.io.InputStream in, byte[] b, int off, int len) throws java.io.IOException
java.io.IOException
public static boolean writeBytesToFile(java.lang.String file, byte[] keyBytes)
public static boolean writeBytesToFile(java.io.File file, byte[] keyBytes)
public static boolean isMatchingKeyPair(java.security.PublicKey pubkey, java.security.PrivateKey privkey) throws HandleException
HandleException
@Deprecated public static byte[] decrypt(java.security.PrivateKey privKey, byte[] ciphertext) throws java.lang.Exception
java.lang.Exception
public static byte[] decrypt(java.security.PrivateKey privKey, byte[] ciphertext, int majorProtocolVersion, int minorProtocolVersion) throws java.lang.Exception
java.lang.Exception
public static java.security.PrivateKey getPrivateKeyFromFileWithPassphrase(java.io.File privKeyFile, java.lang.String passphrase) throws java.lang.Exception
java.lang.Exception
public static byte[] concat(byte[] first, byte[] second)
public static java.lang.String getAccessLogString(AbstractRequest req)