Package net.handle.hdllib
Class Util
java.lang.Object
net.handle.hdllib.Util
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]concat(byte[] first, byte[] second) static byte[]constructPbkdf2Encoding(byte[] salt, int iterations, int keyLength, byte[] mac) static final byte[]convertSlashlessHandleToZeroNaHandle(byte[] handle) static final intcountValuesOfType(HandleValue[] values, byte[] type) static final StringdecodeHexString(byte[] buf, boolean formatNicely) static final StringdecodeHexString(byte[] buf, int offset, int len, boolean formatNicely) static final StringdecodeString(byte[] buf) static final StringdecodeString(byte[] buf, int offset, int len) static byte[]decrypt(byte[] ciphertext, byte[] secretKey) Decrypt the given set of bytes using the specified secret keystatic byte[]decrypt(PrivateKey privKey, byte[] ciphertext) Deprecated.static byte[]decrypt(PrivateKey privKey, byte[] ciphertext, int majorProtocolVersion, int minorProtocolVersion) static final byte[]doDigest(byte[] digestType, byte[]... bufs) static final byte[]doDigest(byte digestType, byte[]... bufs) static byte[]doHmacSHA1(byte[] buf, byte[] key) static byte[]doHmacSHA256(byte[] buf, byte[] key) static final byte[]doMac(byte[] digestType, byte[] buf, byte[] key) static final byte[]doMac(byte digestType, byte[] buf, byte[] key) static final byte[]doMac(byte digestType, byte[] buf, byte[] key, byte[] paramsToMatch) static final 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 final byte[]doSHA1Digest(byte[]... bufs) static byte[]doSHA256Digest(byte[]... bufs) static final byte[]duplicateByteArray(byte[] buf) static final byte[]static final byte[]Encoded the specified string into a byte arraystatic 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[]Deprecated.static byte[]encrypt(PublicKey encryptingKey, byte[] secretKey, int majorProtocolVersion, int minorProtocolVersion) encrypt with Public keystatic final booleanequals(byte[] b1, byte[] b2) compare the two arrays.static final booleanequals(byte[] b1, int b1Start, byte[] b2, int b2Start) compare the two arrays starting at the given index.static final booleanequalsCI(byte[] b1, byte[] b2) Determine if the first parameter equals the second parameter in a case insensitive comparison.static final booleanequalsCI(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 booleanstatic booleanequalsIgnoreCaseAndPunctuation(byte[] a, byte[] b) static final booleanequalsPrefixCI(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 final booleanequalsPrefixCI(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 final booleanequalsPrefixCI(String s1, 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 List<HandleValue> filterOnlyPublicValues(List<HandleValue> values) static HandleValue[]filterValues(HandleValue[] allValues, int[] indexList, byte[][] typeList) static StringgetAccessLogString(AbstractRequest req, AbstractResponse resp) static SiteInfogetAltSiteInfo(SiteInfo site) static byte[]getBytesFromFile(File file) static byte[]getBytesFromFile(String file) convert a file into a byte streamstatic byte[]static byte[]static byte[]static StringgetDefaultSigId(String algorithm) static StringgetDefaultSigId(String algorithm, AbstractMessage message) static byte[]getHashAlgIdFromSigId(String signatureAlgorithm) Get the ID that the handle protocol uses to identify the hash algorithm used in the given signature algorithm descriptor.static final byte[]getIDPart(byte[] handle) Deprecated.use getSuffixPart(byte[]) insteadstatic final byte[]getNAHandle(byte[] handle) Deprecated.use getZeroNAHandle(byte[]) insteadstatic NamespaceInfogetNamespaceFromValues(String handle, HandleValue[] values) static NamespaceInfogetNamespaceFromValues(HandleValue[] values) Extract and return the namespace information contained in the given handle values.static final byte[]getNAPart(byte[] handle) Deprecated.use getPrefixPart(byte[]) insteadstatic final intgetNextUnusedIndex(HandleValue[] values, int firstIdx) static final byte[]getParentNAOfNAHandle(byte[] naHandle) Get the parent prefix handle for the given prefix handle.static StringgetParentNAOfNAHandle(String naHandle) static final byte[]getPassphrase(String prompt) Get a passphrase from the user.static final byte[]getPrefixPart(byte[] handle) Get only the prefix part of this handle.static StringgetPrefixPart(String handle) static SiteInfogetPrimarySite(SiteInfo[] sites) static PrivateKeygetPrivateKeyFromBytes(byte[] pkBuf) static PrivateKeygetPrivateKeyFromBytes(byte[] pkBuf, int offset) static PrivateKeygetPrivateKeyFromFileWithPassphrase(File privKeyFile, String passphrase) static PublicKeygetPublicKeyFromBytes(byte[] pkBuf) static PublicKeygetPublicKeyFromBytes(byte[] pkBuf, int offset) static PublicKeygetPublicKeyFromFile(String filename) getPublicKeysFromValues(HandleValue[] values) static StringgetSigIdFromHashAlgId(byte[] hashAlgId, String sigKeyType) static SiteInfogetSiteFromBytes(byte[] data) static SiteInfogetSiteFromFile(String filename) Reads a SiteInfo from a file formatted as either siteinfo.bin or siteinfo.json.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 final byte[]getSuffixPart(byte[] handle) Get only the suffix part of this handle.static StringgetSuffixPart(String handle) static final byte[]getZeroNAHandle(byte[] handle) Get the 0.NA authority handle that applies to the specified handlestatic StringgetZeroNAHandle(String handle) static final booleanhasSlash(byte[] handle) Return whether a handle has a slashstatic final intindexOf(byte[] b, byte ch) static booleanisDerivedFrom(String handle, String ancestorHandle) static booleanisHandleUnderPrefix(String handle, String prefix) static final booleanisInArray(byte[][] a, byte[] val) returns true if the given byte array is contained in the specified byte array array.static final booleanisInArray(int[] a, int val) returns true if the given int value is in the specified array.static booleanisMatchingKeyPair(PublicKey pubkey, PrivateKey privkey) check that a given PublicKey and a given PrivateKey are a pairstatic final booleanisParentTypeInArray(byte[][] a, byte[] val) Types in the array are either exact types (not ending in '.') or prefixes of type families (ending in '.').static final booleanisSubNAHandle(byte[] handle) only for 0.NA/derived.prefix handlesstatic booleanisSubNAHandle(String handle) static final booleanisValidString(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 final booleanlooksLikeBinary(byte[] buf) static final 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 voidreadFully(InputStream in, byte[] b) Like in.read(b), but attempts to read as many bytes as possiblestatic voidreadFully(InputStream in, byte[] b, int off, int len) Like in.read(b, off, len), but attempts to read as many bytes as possiblestatic final booleanrequiresSecretKey(byte[] ciphertext) Returns true is the given ciphertext requires a secret key to be decrypted (ie if the encryption algorithm is ENCRYPT_NONE).static StringrfcIpPortRepr(InetAddress addr, int port) static StringrfcIpRepr(byte[] ipv6Address) static StringrfcIpRepr(InetAddress addr) static voidsortNumberArray(Number[] a) static final booleanstartsWith(byte[] b1, byte[] b2) static final booleanstartsWithCI(byte[] b1, byte[] b2) Determine if the first parameter begins with the second parameter in a case insensitive comparison.static booleanstartsWithCI(String s1, String s2) static final byte[]substring(byte[] b, int i1) determine if the second UTF8 encoded parameter begins with the second parameter in a case sensitive comparison.static final byte[]substring(byte[] b, int i1, int i2) static final byte[]upperCase(byte[] b) create and return an upper-case copy of the given UTF8 byte arraystatic Stringstatic final byte[]upperCaseInPlace(byte[] b) Convert all of the characters in the given utf-8 byte array to upper case.static final byte[]upperCasePrefix(byte[] b) create and return an upper-case (prefix only, or all of a global handle) copy of the given UTF8 byte arraystatic Stringstatic final 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 booleanwriteBytesToFile(File file, byte[] keyBytes) static booleanwriteBytesToFile(String file, byte[] keyBytes) write byte array into a given file name
-
Field Details
-
CASE_DIFF
public static final byte CASE_DIFF- See Also:
-
-
Constructor Details
-
Util
public Util()
-
-
Method Details
-
looksLikeBinary
public static final boolean looksLikeBinary(byte[] buf) -
duplicateByteArray
public static final byte[] duplicateByteArray(byte[] buf) -
decodeHexString
-
decodeHexString
-
encodeHexString
-
encodeString
Encoded the specified string into a byte array -
decodeString
-
decodeString
-
isValidString
public static final 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). -
hasSlash
public static final boolean hasSlash(byte[] handle) Return whether a handle has a slash -
getIDPart
Deprecated.use getSuffixPart(byte[]) insteadGet only the suffix part of this handle. -
getNAPart
Deprecated.use getPrefixPart(byte[]) insteadGet only the prefix part of this handle. -
getNAHandle
Deprecated.use getZeroNAHandle(byte[]) insteadGet the 0.NA authority handle that applies to the specified handle -
getZeroNAHandle
public static final byte[] getZeroNAHandle(byte[] handle) Get the 0.NA authority handle that applies to the specified handle -
getZeroNAHandle
-
convertSlashlessHandleToZeroNaHandle
public static final byte[] convertSlashlessHandleToZeroNaHandle(byte[] handle) -
isSubNAHandle
public static final boolean isSubNAHandle(byte[] handle) only for 0.NA/derived.prefix handles -
isSubNAHandle
-
getParentNAOfNAHandle
public static final byte[] getParentNAOfNAHandle(byte[] naHandle) Get the parent prefix handle for the given prefix handle. The given handle MUST be a prefix handle of form 0.NA/derived.prefix. -
getParentNAOfNAHandle
-
isHandleUnderPrefix
-
isDerivedFrom
-
getPrefixPart
public static final byte[] getPrefixPart(byte[] handle) Get only the prefix part of this handle. -
getPrefixPart
-
getSuffixPart
public static final byte[] getSuffixPart(byte[] handle) Get only the suffix part of this handle. -
getSuffixPart
-
startsWith
public static final boolean startsWith(byte[] b1, byte[] b2) -
equals
public static final boolean equals(byte[] b1, byte[] b2) compare the two arrays. If they are the same true is returned. -
equals
public static final boolean equals(byte[] b1, int b1Start, byte[] b2, int b2Start) compare the two arrays starting at the given index. If they are the same true is returned. -
upperCase
public static final byte[] upperCase(byte[] b) create and return an upper-case copy of the given UTF8 byte array -
upperCase
-
upperCaseInPlace
public static final byte[] upperCaseInPlace(byte[] b) Convert all of the characters in the given utf-8 byte array to upper case. Return the same array. -
upperCasePrefix
public static final 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 -
upperCasePrefix
-
upperCasePrefixInPlace
public static final 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. Return the same array. -
equalsCI
public static final boolean equalsCI(byte[] b1, byte[] b2) Determine if the first parameter equals the second parameter in a case insensitive comparison. -
equalsCI
-
equalsCI
public static final 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. -
equalsPrefixCI
public static final 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. -
equalsPrefixCI
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. -
equalsPrefixCI
public static final 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. -
startsWithCI
public static final boolean startsWithCI(byte[] b1, byte[] b2) Determine if the first parameter begins with the second parameter in a case insensitive comparison. -
startsWithCI
-
substring
public static final byte[] substring(byte[] b, int i1) determine if the second UTF8 encoded parameter begins with the second parameter in a case sensitive comparison. -
substring
public static final byte[] substring(byte[] b, int i1, int i2) -
indexOf
public static final int indexOf(byte[] b, byte ch) -
countValuesOfType
-
rfcIpPortRepr
-
rfcIpRepr
-
rfcIpRepr
-
isParentTypeInArray
public static final boolean isParentTypeInArray(byte[][] a, byte[] val) Types in the array are either exact types (not ending in '.') or prefixes of type families (ending in '.'). Returns true when the given type is equal to an exact type in the array, or is equal to a prefix (ignoring the '.'), or has a prefix ending with '.' in the array. For example: isParentInArray( { "url.", "email", "public_key" }, "url.us" ) returns true isParentInArray( { "url", "email", "public_key" }, "url.us" ) returns false isParentInArray( { "url.jp", "email", "public_key" }, "url" ) returns false -
isInArray
public static final boolean isInArray(int[] a, int val) returns true if the given int value is in the specified array. -
isInArray
public static final boolean isInArray(byte[][] a, byte[] val) returns true if the given byte array is contained in the specified byte array array. -
getNextUnusedIndex
-
getAltSiteInfo
-
fill16
public static byte[] fill16(byte[] bytes) -
getSitesFromValues
Extract and return all of the SiteInfo records from the given list of handle values. Returns null if no site values were found. -
getSitesAndAltSitesFromValues
Extract and return all of the SiteInfo records from the given list of handle values. Include SiteInfos generated using the "alt_addr" attribue. Returns null if no site values were found. -
getSitesAndAltSitesFromValues
-
getNamespaceFromValues
Extract and return the namespace information contained in the given handle values. If there are multiple values with type HS_NAMESPACE then the one with the lowest index value will be used. If no valid namespace values are encountered then this will return null. -
getNamespaceFromValues
-
orderSitesByPreference
rearranges the given sites in a more efficient order so that resolution from the current location should tend to access the faster sites first. If a preferred site is listed in the server configuration file, it is accessed first. -
getPrimarySite
-
filterValues
public static HandleValue[] filterValues(HandleValue[] allValues, int[] indexList, byte[][] typeList) -
filterOnlyPublicValues
-
getPassphrase
Get a passphrase from the user.- Throws:
Exception
-
getHashAlgIdFromSigId
Get the ID that the handle protocol uses to identify the hash algorithm used in the given signature algorithm descriptor.- Throws:
HandleException
-
getSigIdFromHashAlgId
public static String getSigIdFromHashAlgId(byte[] hashAlgId, String sigKeyType) throws HandleException - Throws:
HandleException
-
getDefaultSigId
-
getDefaultSigId
public static String getDefaultSigId(String algorithm, AbstractMessage message) throws HandleException - Throws:
HandleException
-
getBytesFromPrivateKey
- Throws:
Exception
-
getPrivateKeyFromBytes
public static PrivateKey getPrivateKeyFromBytes(byte[] pkBuf) throws HandleException, InvalidKeySpecException -
getPrivateKeyFromBytes
public static PrivateKey getPrivateKeyFromBytes(byte[] pkBuf, int offset) throws HandleException, InvalidKeySpecException -
getBytesFromPublicKey
- Throws:
HandleException
-
getPublicKeyFromFile
- Throws:
Exception
-
getPublicKeyFromBytes
- Throws:
Exception
-
getPublicKeyFromBytes
- Throws:
Exception
-
getPublicKeysFromValues
-
encrypt
Encrypt the given set of bytes using the specified secret key and the default encryption algorithm.- Throws:
Exception
-
encrypt
Encrypt the given set of bytes using the specified secret key and encryption algorithm.- Throws:
Exception
-
doPBKDF2
public static byte[] doPBKDF2(byte[] password, byte[] salt, int iterations, int length) throws NoSuchAlgorithmException, InvalidKeySpecException -
constructPbkdf2Encoding
public static byte[] constructPbkdf2Encoding(byte[] salt, int iterations, int keyLength, byte[] mac) -
requiresSecretKey
Returns true is the given ciphertext requires a secret key to be decrypted (ie if the encryption algorithm is ENCRYPT_NONE).- Throws:
Exception
-
decrypt
Decrypt the given set of bytes using the specified secret key- Throws:
Exception
-
doSHA1Digest
- Throws:
HandleException
-
doHmacSHA1
- Throws:
HandleException
-
doHmacSHA256
- Throws:
HandleException
-
doPbkdf2HmacSHA1
public static byte[] doPbkdf2HmacSHA1(byte[] buf, byte[] key, byte[] paramsToMatch) throws HandleException - Throws:
HandleException
-
doSHA256Digest
- Throws:
HandleException
-
doMD5Digest
- Throws:
HandleException
-
doDigest
- Throws:
HandleException
-
doMac
- Throws:
HandleException
-
doMac
public static final byte[] doMac(byte digestType, byte[] buf, byte[] key, byte[] paramsToMatch) throws HandleException - Throws:
HandleException
-
doDigest
- Throws:
HandleException
-
doMac
- Throws:
HandleException
-
equalsIgnoreCaseAndPunctuation
public static boolean equalsIgnoreCaseAndPunctuation(byte[] a, byte[] b) -
sortNumberArray
-
encrypt
@Deprecated public static byte[] encrypt(PublicKey encryptingKey, byte[] secretKey) throws Exception Deprecated.- Throws:
Exception
-
encrypt
public static byte[] encrypt(PublicKey encryptingKey, byte[] secretKey, int majorProtocolVersion, int minorProtocolVersion) throws Exception encrypt with Public key- Throws:
Exception
-
getBytesFromFile
convert a file into a byte stream -
getBytesFromFile
-
getBytesFromInputStream
- Throws:
IOException
-
readFully
Like in.read(b), but attempts to read as many bytes as possible- Throws:
IOException
-
readFully
Like in.read(b, off, len), but attempts to read as many bytes as possible- Throws:
IOException
-
writeBytesToFile
write byte array into a given file name -
writeBytesToFile
-
isMatchingKeyPair
public static boolean isMatchingKeyPair(PublicKey pubkey, PrivateKey privkey) throws HandleException check that a given PublicKey and a given PrivateKey are a pair- Throws:
HandleException
-
decrypt
Deprecated.- Throws:
Exception
-
decrypt
public static byte[] decrypt(PrivateKey privKey, byte[] ciphertext, int majorProtocolVersion, int minorProtocolVersion) throws Exception - Throws:
Exception
-
getPrivateKeyFromFileWithPassphrase
public static PrivateKey getPrivateKeyFromFileWithPassphrase(File privKeyFile, String passphrase) throws Exception - Throws:
Exception
-
concat
public static byte[] concat(byte[] first, byte[] second) -
getAccessLogString
-
getSiteFromFile
Reads a SiteInfo from a file formatted as either siteinfo.bin or siteinfo.json.- Throws:
Exception
-
getSiteFromBytes
- Throws:
Exception
-