Class Util


  • public abstract class Util
    extends java.lang.Object
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static byte CASE_DIFF  
    • Constructor Summary

      Constructors 
      Constructor Description
      Util()  
    • Method Summary

      All Methods Static Methods Concrete Methods Deprecated Methods 
      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, AbstractResponse resp)  
      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​(java.lang.String handle, HandleValue[] values)  
      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 getSiteFromBytes​(byte[] data)  
      static SiteInfo getSiteFromFile​(java.lang.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 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
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Util

        public Util()
    • Method Detail

      • looksLikeBinary

        public static final boolean looksLikeBinary​(byte[] buf)
      • duplicateByteArray

        public static final byte[] duplicateByteArray​(byte[] buf)
      • decodeHexString

        public static final java.lang.String decodeHexString​(byte[] buf,
                                                             int offset,
                                                             int len,
                                                             boolean formatNicely)
      • decodeHexString

        public static final java.lang.String decodeHexString​(byte[] buf,
                                                             boolean formatNicely)
      • encodeHexString

        public static final byte[] encodeHexString​(java.lang.String s)
      • encodeString

        public static final byte[] encodeString​(java.lang.String s)
        Encoded the specified string into a byte array
      • decodeString

        public static final java.lang.String decodeString​(byte[] buf)
      • decodeString

        public static final java.lang.String decodeString​(byte[] buf,
                                                          int offset,
                                                          int len)
      • 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
        public static final byte[] getIDPart​(byte[] handle)
        Deprecated.
        use getSuffixPart(byte[]) instead
        Get only the suffix part of this handle.
      • getNAPart

        @Deprecated
        public static final byte[] getNAPart​(byte[] handle)
        Deprecated.
        use getPrefixPart(byte[]) instead
        Get only the prefix part of this handle.
      • getNAHandle

        @Deprecated
        public static final byte[] getNAHandle​(byte[] handle)
        Deprecated.
        use getZeroNAHandle(byte[]) instead
        Get 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

        public static java.lang.String getZeroNAHandle​(java.lang.String handle)
      • convertSlashlessHandleToZeroNaHandle

        public static final byte[] convertSlashlessHandleToZeroNaHandle​(byte[] handle)
      • isSubNAHandle

        public static final boolean isSubNAHandle​(byte[] handle)
        only for 0.NA/derived.prefix handles
      • isSubNAHandle

        public static boolean isSubNAHandle​(java.lang.String handle)
      • 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

        public static java.lang.String getParentNAOfNAHandle​(java.lang.String naHandle)
      • isHandleUnderPrefix

        public static boolean isHandleUnderPrefix​(java.lang.String handle,
                                                  java.lang.String prefix)
      • isDerivedFrom

        public static boolean isDerivedFrom​(java.lang.String handle,
                                            java.lang.String ancestorHandle)
      • getPrefixPart

        public static final byte[] getPrefixPart​(byte[] handle)
        Get only the prefix part of this handle.
      • getPrefixPart

        public static java.lang.String getPrefixPart​(java.lang.String handle)
      • getSuffixPart

        public static final byte[] getSuffixPart​(byte[] handle)
        Get only the suffix part of this handle.
      • getSuffixPart

        public static java.lang.String getSuffixPart​(java.lang.String handle)
      • 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

        public static java.lang.String upperCase​(java.lang.String s)
      • 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

        public static java.lang.String upperCasePrefix​(java.lang.String s)
      • 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

        public static boolean equalsCI​(java.lang.String s1,
                                       java.lang.String s2)
      • 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

        public static final 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.
      • 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

        public static boolean startsWithCI​(java.lang.String s1,
                                           java.lang.String s2)
      • 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

        public static final int countValuesOfType​(HandleValue[] values,
                                                  byte[] type)
      • rfcIpPortRepr

        public static java.lang.String rfcIpPortRepr​(java.net.InetAddress addr,
                                                     int port)
      • rfcIpRepr

        public static java.lang.String rfcIpRepr​(byte[] ipv6Address)
      • rfcIpRepr

        public static java.lang.String rfcIpRepr​(java.net.InetAddress addr)
      • 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

        public static final int getNextUnusedIndex​(HandleValue[] values,
                                                   int firstIdx)
      • fill16

        public static byte[] fill16​(byte[] bytes)
      • getSitesFromValues

        public static SiteInfo[] getSitesFromValues​(HandleValue[] values)
        Extract and return all of the SiteInfo records from the given list of handle values. Returns null if no site values were found.
      • getSitesAndAltSitesFromValues

        public static SiteInfo[] getSitesAndAltSitesFromValues​(HandleValue[] values)
        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

        public static SiteInfo[] getSitesAndAltSitesFromValues​(HandleValue[] values,
                                                               byte[][] types)
      • getNamespaceFromValues

        public static NamespaceInfo getNamespaceFromValues​(HandleValue[] values)
        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

        public static NamespaceInfo getNamespaceFromValues​(java.lang.String handle,
                                                           HandleValue[] values)
      • orderSitesByPreference

        public 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. If a preferred site is listed in the server configuration file, it is accessed first.
      • filterValues

        public static HandleValue[] filterValues​(HandleValue[] allValues,
                                                 int[] indexList,
                                                 byte[][] typeList)
      • filterOnlyPublicValues

        public static java.util.List<HandleValue> filterOnlyPublicValues​(java.util.List<HandleValue> values)
      • getPassphrase

        public static final byte[] getPassphrase​(java.lang.String prompt)
                                          throws java.lang.Exception
        Get a passphrase from the user.
        Throws:
        java.lang.Exception
      • getHashAlgIdFromSigId

        public static byte[] getHashAlgIdFromSigId​(java.lang.String signatureAlgorithm)
                                            throws HandleException
        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 java.lang.String getSigIdFromHashAlgId​(byte[] hashAlgId,
                                                             java.lang.String sigKeyType)
                                                      throws HandleException
        Throws:
        HandleException
      • getDefaultSigId

        public static java.lang.String getDefaultSigId​(java.lang.String algorithm)
      • getBytesFromPrivateKey

        public static byte[] getBytesFromPrivateKey​(java.security.PrivateKey key)
                                             throws java.lang.Exception
        Throws:
        java.lang.Exception
      • getPrivateKeyFromBytes

        public static java.security.PrivateKey getPrivateKeyFromBytes​(byte[] pkBuf)
                                                               throws HandleException,
                                                                      java.security.spec.InvalidKeySpecException
        Throws:
        HandleException
        java.security.spec.InvalidKeySpecException
      • getPrivateKeyFromBytes

        public static java.security.PrivateKey getPrivateKeyFromBytes​(byte[] pkBuf,
                                                                      int offset)
                                                               throws HandleException,
                                                                      java.security.spec.InvalidKeySpecException
        Throws:
        HandleException
        java.security.spec.InvalidKeySpecException
      • getPublicKeyFromFile

        public static java.security.PublicKey getPublicKeyFromFile​(java.lang.String filename)
                                                            throws java.lang.Exception
        Throws:
        java.lang.Exception
      • getPublicKeyFromBytes

        public static java.security.PublicKey getPublicKeyFromBytes​(byte[] pkBuf)
                                                             throws java.lang.Exception
        Throws:
        java.lang.Exception
      • getPublicKeyFromBytes

        public static java.security.PublicKey getPublicKeyFromBytes​(byte[] pkBuf,
                                                                    int offset)
                                                             throws java.lang.Exception
        Throws:
        java.lang.Exception
      • getPublicKeysFromValues

        public static java.util.List<java.security.PublicKey> getPublicKeysFromValues​(HandleValue[] values)
      • encrypt

        public static byte[] encrypt​(byte[] cleartext,
                                     byte[] secretKey)
                              throws java.lang.Exception
        Encrypt the given set of bytes using the specified secret key and the default encryption algorithm.
        Throws:
        java.lang.Exception
      • encrypt

        public static byte[] encrypt​(byte[] cleartext,
                                     byte[] secretKey,
                                     int encType)
                              throws java.lang.Exception
        Encrypt the given set of bytes using the specified secret key and encryption algorithm.
        Throws:
        java.lang.Exception
      • doPBKDF2

        public static byte[] doPBKDF2​(byte[] password,
                                      byte[] salt,
                                      int iterations,
                                      int length)
                               throws java.security.NoSuchAlgorithmException,
                                      java.security.spec.InvalidKeySpecException
        Throws:
        java.security.NoSuchAlgorithmException
        java.security.spec.InvalidKeySpecException
      • constructPbkdf2Encoding

        public static byte[] constructPbkdf2Encoding​(byte[] salt,
                                                     int iterations,
                                                     int keyLength,
                                                     byte[] mac)
      • requiresSecretKey

        public static final boolean requiresSecretKey​(byte[] ciphertext)
                                               throws java.lang.Exception
        Returns true is the given ciphertext requires a secret key to be decrypted (ie if the encryption algorithm is ENCRYPT_NONE).
        Throws:
        java.lang.Exception
      • decrypt

        public static byte[] decrypt​(byte[] ciphertext,
                                     byte[] secretKey)
                              throws java.lang.Exception
        Decrypt the given set of bytes using the specified secret key
        Throws:
        java.lang.Exception
      • doPbkdf2HmacSHA1

        public static byte[] doPbkdf2HmacSHA1​(byte[] buf,
                                              byte[] key,
                                              byte[] paramsToMatch)
                                       throws HandleException
        Throws:
        HandleException
      • doMac

        public static final byte[] doMac​(byte digestType,
                                         byte[] buf,
                                         byte[] key,
                                         byte[] paramsToMatch)
                                  throws HandleException
        Throws:
        HandleException
      • equalsIgnoreCaseAndPunctuation

        public static boolean equalsIgnoreCaseAndPunctuation​(byte[] a,
                                                             byte[] b)
      • sortNumberArray

        public static void sortNumberArray​(java.lang.Number[] a)
      • encrypt

        @Deprecated
        public static byte[] encrypt​(java.security.PublicKey encryptingKey,
                                     byte[] secretKey)
                              throws java.lang.Exception
        Deprecated.
        Throws:
        java.lang.Exception
      • encrypt

        public static byte[] encrypt​(java.security.PublicKey encryptingKey,
                                     byte[] secretKey,
                                     int majorProtocolVersion,
                                     int minorProtocolVersion)
                              throws java.lang.Exception
        encrypt with Public key
        Throws:
        java.lang.Exception
      • getBytesFromFile

        public static byte[] getBytesFromFile​(java.lang.String file)
        convert a file into a byte stream
      • getBytesFromFile

        public static byte[] getBytesFromFile​(java.io.File file)
      • getBytesFromInputStream

        public static byte[] getBytesFromInputStream​(java.io.InputStream in)
                                              throws java.io.IOException
        Throws:
        java.io.IOException
      • readFully

        public static void readFully​(java.io.InputStream in,
                                     byte[] b)
                              throws java.io.IOException
        Like in.read(b), but attempts to read as many bytes as possible
        Throws:
        java.io.IOException
      • readFully

        public static void readFully​(java.io.InputStream in,
                                     byte[] b,
                                     int off,
                                     int len)
                              throws java.io.IOException
        Like in.read(b, off, len), but attempts to read as many bytes as possible
        Throws:
        java.io.IOException
      • writeBytesToFile

        public static boolean writeBytesToFile​(java.lang.String file,
                                               byte[] keyBytes)
        write byte array into a given file name
      • writeBytesToFile

        public static boolean writeBytesToFile​(java.io.File file,
                                               byte[] keyBytes)
      • isMatchingKeyPair

        public static boolean isMatchingKeyPair​(java.security.PublicKey pubkey,
                                                java.security.PrivateKey privkey)
                                         throws HandleException
        check that a given PublicKey and a given PrivateKey are a pair
        Throws:
        HandleException
      • decrypt

        @Deprecated
        public static byte[] decrypt​(java.security.PrivateKey privKey,
                                     byte[] ciphertext)
                              throws java.lang.Exception
        Deprecated.
        Throws:
        java.lang.Exception
      • decrypt

        public static byte[] decrypt​(java.security.PrivateKey privKey,
                                     byte[] ciphertext,
                                     int majorProtocolVersion,
                                     int minorProtocolVersion)
                              throws java.lang.Exception
        Throws:
        java.lang.Exception
      • getPrivateKeyFromFileWithPassphrase

        public static java.security.PrivateKey getPrivateKeyFromFileWithPassphrase​(java.io.File privKeyFile,
                                                                                   java.lang.String passphrase)
                                                                            throws java.lang.Exception
        Throws:
        java.lang.Exception
      • concat

        public static byte[] concat​(byte[] first,
                                    byte[] second)
      • getSiteFromFile

        public static SiteInfo getSiteFromFile​(java.lang.String filename)
                                        throws java.lang.Exception
        Reads a SiteInfo from a file formatted as either siteinfo.bin or siteinfo.json.
        Throws:
        java.lang.Exception
      • getSiteFromBytes

        public static SiteInfo getSiteFromBytes​(byte[] data)
                                         throws java.lang.Exception
        Throws:
        java.lang.Exception