Package com.itextpdf.kernel.crypto
Class DigestAlgorithms
- java.lang.Object
-
- com.itextpdf.kernel.crypto.DigestAlgorithms
-
public class DigestAlgorithms extends java.lang.ObjectClass that contains a map with the different message digest algorithms.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.util.Map<java.lang.String,java.lang.String>allowedDigestsMaps the name of a digest algorithm with its ID.private static java.util.Map<java.lang.String,java.lang.Integer>bitLengthsMaps algorithm names to output lengths in bits.private static IBouncyCastleFactoryBOUNCY_CASTLE_FACTORYprivate static java.util.Map<java.lang.String,java.lang.String>digestNamesMaps the digest IDs with the human-readable name of the digest algorithm.private static java.util.Map<java.lang.String,java.lang.String>fixNamesMaps digest algorithm that are unknown by the JDKs MessageDigest object to a known one.private static org.slf4j.LoggerLOGGERstatic java.lang.StringRIPEMD160Algorithm available for signatures since PDF 1.7.static java.lang.StringSHA1Algorithm available for signatures since PDF 1.3.static java.lang.StringSHA256Algorithm available for signatures since PDF 1.6.static java.lang.StringSHA3_256Algorithm available for signatures since PDF 2.0 extended by ISO/TS 32001.static java.lang.StringSHA3_384Algorithm available for signatures since PDF 2.0 extended by ISO/TS 32001.static java.lang.StringSHA3_512Algorithm available for signatures since PDF 2.0 extended by ISO/TS 32001.static java.lang.StringSHA384Algorithm available for signatures since PDF 1.7.static java.lang.StringSHA512Algorithm available for signatures since PDF 1.7.static java.lang.StringSHAKE256Algorithm available for signatures since PDF 2.0 extended by ISO/TS 32001.
-
Constructor Summary
Constructors Constructor Description DigestAlgorithms()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static byte[]digest(java.io.InputStream data, java.lang.String hashAlgorithm, java.lang.String provider)Creates a hash using a specific digest algorithm and a provider.static byte[]digest(java.io.InputStream data, java.security.MessageDigest messageDigest)Create a digest based on the input stream.static java.lang.StringgetAllowedDigest(java.lang.String name)Returns the id of a digest algorithms that is allowed in PDF, or null if it isn't allowed.static java.lang.StringgetDigest(java.lang.String oid)Gets the digest name for a certain id.static java.security.MessageDigestgetMessageDigest(java.lang.String hashAlgorithm, java.lang.String provider)Creates a MessageDigest object that can be used to create a hash.static java.security.MessageDigestgetMessageDigestFromOid(java.lang.String digestOid, java.lang.String provider)Get a digest algorithm.static intgetOutputBitLength(java.lang.String name)Retrieve the output length in bits of the given digest algorithm.static java.lang.StringnormalizeDigestName(java.lang.String algo)Normalize the digest name.
-
-
-
Field Detail
-
SHA1
public static final java.lang.String SHA1
Algorithm available for signatures since PDF 1.3.- See Also:
- Constant Field Values
-
SHA256
public static final java.lang.String SHA256
Algorithm available for signatures since PDF 1.6.- See Also:
- Constant Field Values
-
SHA384
public static final java.lang.String SHA384
Algorithm available for signatures since PDF 1.7.- See Also:
- Constant Field Values
-
SHA512
public static final java.lang.String SHA512
Algorithm available for signatures since PDF 1.7.- See Also:
- Constant Field Values
-
RIPEMD160
public static final java.lang.String RIPEMD160
Algorithm available for signatures since PDF 1.7.- See Also:
- Constant Field Values
-
SHA3_256
public static final java.lang.String SHA3_256
Algorithm available for signatures since PDF 2.0 extended by ISO/TS 32001.- See Also:
- Constant Field Values
-
SHA3_512
public static final java.lang.String SHA3_512
Algorithm available for signatures since PDF 2.0 extended by ISO/TS 32001.- See Also:
- Constant Field Values
-
SHA3_384
public static final java.lang.String SHA3_384
Algorithm available for signatures since PDF 2.0 extended by ISO/TS 32001.- See Also:
- Constant Field Values
-
SHAKE256
public static final java.lang.String SHAKE256
Algorithm available for signatures since PDF 2.0 extended by ISO/TS 32001.The output length is fixed at 512 bits (64 bytes).
- See Also:
- Constant Field Values
-
digestNames
private static final java.util.Map<java.lang.String,java.lang.String> digestNames
Maps the digest IDs with the human-readable name of the digest algorithm.
-
fixNames
private static final java.util.Map<java.lang.String,java.lang.String> fixNames
Maps digest algorithm that are unknown by the JDKs MessageDigest object to a known one.
-
allowedDigests
private static final java.util.Map<java.lang.String,java.lang.String> allowedDigests
Maps the name of a digest algorithm with its ID.
-
bitLengths
private static final java.util.Map<java.lang.String,java.lang.Integer> bitLengths
Maps algorithm names to output lengths in bits.
-
BOUNCY_CASTLE_FACTORY
private static final IBouncyCastleFactory BOUNCY_CASTLE_FACTORY
-
LOGGER
private static final org.slf4j.Logger LOGGER
-
-
Method Detail
-
getMessageDigestFromOid
public static java.security.MessageDigest getMessageDigestFromOid(java.lang.String digestOid, java.lang.String provider) throws java.security.NoSuchAlgorithmException, java.security.NoSuchProviderExceptionGet a digest algorithm.- Parameters:
digestOid- oid of the digest algorithmprovider- the provider you want to use to create the hash- Returns:
- MessageDigest object
- Throws:
java.security.NoSuchAlgorithmException- thrown when a particular cryptographic algorithm is requested but is not available in the environmentjava.security.NoSuchProviderException- thrown when a particular security provider is requested but is not available in the environment
-
getMessageDigest
public static java.security.MessageDigest getMessageDigest(java.lang.String hashAlgorithm, java.lang.String provider) throws java.security.NoSuchAlgorithmException, java.security.NoSuchProviderExceptionCreates a MessageDigest object that can be used to create a hash.- Parameters:
hashAlgorithm- the algorithm you want to use to create a hashprovider- the provider you want to use to create the hash- Returns:
- a MessageDigest object
- Throws:
java.security.NoSuchAlgorithmException- thrown when a particular cryptographic algorithm is requested but is not available in the environmentjava.security.NoSuchProviderException- thrown when a particular security provider is requested but is not available in the environment
-
digest
public static byte[] digest(java.io.InputStream data, java.lang.String hashAlgorithm, java.lang.String provider) throws java.security.GeneralSecurityException, java.io.IOExceptionCreates a hash using a specific digest algorithm and a provider.- Parameters:
data- the message of which you want to create a hashhashAlgorithm- the algorithm used to create the hashprovider- the provider used to create the hash- Returns:
- the hash
- Throws:
java.security.GeneralSecurityException- when requested cryptographic algorithm or security provider is not availablejava.io.IOException- signals that an I/O exception has occurred
-
digest
public static byte[] digest(java.io.InputStream data, java.security.MessageDigest messageDigest) throws java.io.IOExceptionCreate a digest based on the input stream.- Parameters:
data- data to be digestedmessageDigest- algorithm to be used- Returns:
- digest of the data
- Throws:
java.io.IOException- signals that an I/O exception has occurred
-
getDigest
public static java.lang.String getDigest(java.lang.String oid)
Gets the digest name for a certain id.- Parameters:
oid- an id (for instance "1.2.840.113549.2.5")- Returns:
- a digest name (for instance "MD5")
-
normalizeDigestName
public static java.lang.String normalizeDigestName(java.lang.String algo)
Normalize the digest name.- Parameters:
algo- the name to be normalized- Returns:
- normalized name
-
getAllowedDigest
public static java.lang.String getAllowedDigest(java.lang.String name)
Returns the id of a digest algorithms that is allowed in PDF, or null if it isn't allowed.- Parameters:
name- the name of the digest algorithm- Returns:
- an oid
-
getOutputBitLength
public static int getOutputBitLength(java.lang.String name)
Retrieve the output length in bits of the given digest algorithm.- Parameters:
name- the name of the digest algorithm- Returns:
- the length of the output of the algorithm in bits
-
-