Package org.apache.sshd.common.digest
Class DigestUtils
- java.lang.Object
-
- org.apache.sshd.common.digest.DigestUtils
-
public final class DigestUtils extends java.lang.Object
-
-
Constructor Summary
Constructors Modifier Constructor Description private
DigestUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
checkSupported(java.lang.String algorithm)
static <D extends Digest>
DfindDigestByAlgorithm(java.lang.String algo, java.util.Comparator<? super java.lang.String> comp, java.util.Collection<? extends D> digests)
static <F extends DigestFactory>
FfindFactoryByAlgorithm(java.lang.String algo, java.util.Comparator<? super java.lang.String> comp, java.util.Collection<? extends F> factories)
static java.lang.String
getFingerPrint(Digest d, byte... buf)
static java.lang.String
getFingerPrint(Digest d, byte[] buf, int offset, int len)
static java.lang.String
getFingerPrint(Digest d, java.lang.String s)
static java.lang.String
getFingerPrint(Digest d, java.lang.String s, java.nio.charset.Charset charset)
static java.lang.String
getFingerPrint(Factory<? extends Digest> f, byte... buf)
static java.lang.String
getFingerPrint(Factory<? extends Digest> f, byte[] buf, int offset, int len)
static java.lang.String
getFingerPrint(Factory<? extends Digest> f, java.lang.String s)
static java.lang.String
getFingerPrint(Factory<? extends Digest> f, java.lang.String s, java.nio.charset.Charset charset)
static byte[]
getRawFingerprint(Digest d, byte... buf)
static byte[]
getRawFingerprint(Digest d, byte[] buf, int offset, int len)
-
-
-
Method Detail
-
checkSupported
public static boolean checkSupported(java.lang.String algorithm)
- Parameters:
algorithm
- The digest algorithm - nevernull
/empty- Returns:
true
if this digest algorithm is supported- See Also:
SecurityUtils.getMessageDigest(String)
-
findDigestByAlgorithm
public static <D extends Digest> D findDigestByAlgorithm(java.lang.String algo, java.util.Comparator<? super java.lang.String> comp, java.util.Collection<? extends D> digests)
- Type Parameters:
D
- The generic type of digest factory- Parameters:
algo
- The required algorithm name - ignored ifnull
/emptycomp
- TheComparator
to use to compare algorithm namesdigests
- The factories to check - ignored ifnull
/empty- Returns:
- The first
DigestFactory
whose algorithm matches the required one according to the comparator -null
if no match found
-
findFactoryByAlgorithm
public static <F extends DigestFactory> F findFactoryByAlgorithm(java.lang.String algo, java.util.Comparator<? super java.lang.String> comp, java.util.Collection<? extends F> factories)
- Type Parameters:
F
- The generic type of digest factory- Parameters:
algo
- The required algorithm name - ignored ifnull
/emptycomp
- TheComparator
to use to compare algorithm namesfactories
- The factories to check - ignored ifnull
/empty- Returns:
- The first
DigestFactory
whose algorithm matches the required one according to the comparator -null
if no match found
-
getFingerPrint
public static java.lang.String getFingerPrint(Factory<? extends Digest> f, java.lang.String s) throws java.lang.Exception
- Parameters:
f
- TheFactory
to create theDigest
to uses
- TheString
to digest - ignored ifnull
/empty, otherwise its UTF-8 representation is used as input for the fingerprint- Returns:
- The fingerprint -
null
ifnull
/empty input - Throws:
java.lang.Exception
- If failed to calculate the digest- See Also:
getFingerPrint(Digest, String, Charset)
-
getFingerPrint
public static java.lang.String getFingerPrint(Factory<? extends Digest> f, java.lang.String s, java.nio.charset.Charset charset) throws java.lang.Exception
- Parameters:
f
- TheFactory
to create theDigest
to uses
- TheString
to digest - ignored ifnull
/emptycharset
- TheCharset
to use in order to convert the string to its byte representation to use as input for the fingerprint- Returns:
- The fingerprint -
null
ifnull
/empty input - Throws:
java.lang.Exception
- If failed to calculate the digest
-
getFingerPrint
public static java.lang.String getFingerPrint(Digest d, java.lang.String s) throws java.lang.Exception
- Parameters:
d
- TheDigest
to uses
- TheString
to digest - ignored ifnull
/empty, otherwise its UTF-8 representation is used as input for the fingerprint- Returns:
- The fingerprint -
null
ifnull
/empty input - Throws:
java.lang.Exception
- If failed to calculate the digest- See Also:
getFingerPrint(Digest, String, Charset)
-
getFingerPrint
public static java.lang.String getFingerPrint(Digest d, java.lang.String s, java.nio.charset.Charset charset) throws java.lang.Exception
- Parameters:
d
- TheDigest
to uses
- TheString
to digest - ignored ifnull
/emptycharset
- TheCharset
to use in order to convert the string to its byte representation to use as input for the fingerprint- Returns:
- The fingerprint -
null
ifnull
/empty input - Throws:
java.lang.Exception
- If failed to calculate the digest
-
getFingerPrint
public static java.lang.String getFingerPrint(Factory<? extends Digest> f, byte... buf) throws java.lang.Exception
- Parameters:
f
- TheFactory
to create theDigest
to usebuf
- The data buffer to be fingerprint-ed- Returns:
- The fingerprint -
null
if empty data buffer - Throws:
java.lang.Exception
- If failed to calculate the fingerprint- See Also:
getFingerPrint(Factory, byte[], int, int)
-
getFingerPrint
public static java.lang.String getFingerPrint(Factory<? extends Digest> f, byte[] buf, int offset, int len) throws java.lang.Exception
- Parameters:
f
- TheFactory
to create theDigest
to usebuf
- The data buffer to be fingerprint-edoffset
- The offset of the data in the bufferlen
- The length of data - ignored if non-positive- Returns:
- The fingerprint -
null
if non-positive length - Throws:
java.lang.Exception
- If failed to calculate the fingerprint
-
getFingerPrint
public static java.lang.String getFingerPrint(Digest d, byte... buf) throws java.lang.Exception
- Parameters:
d
- TheDigest
to usebuf
- The data buffer to be fingerprint-ed- Returns:
- The fingerprint -
null
if empty data buffer - Throws:
java.lang.Exception
- If failed to calculate the fingerprint- See Also:
getFingerPrint(Digest, byte[], int, int)
-
getFingerPrint
public static java.lang.String getFingerPrint(Digest d, byte[] buf, int offset, int len) throws java.lang.Exception
- Parameters:
d
- TheDigest
to usebuf
- The data buffer to be fingerprint-edoffset
- The offset of the data in the bufferlen
- The length of data - ignored if non-positive- Returns:
- The fingerprint -
null
if non-positive length - Throws:
java.lang.Exception
- If failed to calculate the fingerprint- See Also:
getRawFingerprint(Digest, byte[], int, int)
-
getRawFingerprint
public static byte[] getRawFingerprint(Digest d, byte... buf) throws java.lang.Exception
- Throws:
java.lang.Exception
-
getRawFingerprint
public static byte[] getRawFingerprint(Digest d, byte[] buf, int offset, int len) throws java.lang.Exception
- Throws:
java.lang.Exception
-
-