Package es.gob.afirma.utils
Class CryptoUtil
- java.lang.Object
-
- es.gob.afirma.utils.CryptoUtil
-
- All Implemented Interfaces:
ICryptoUtil
public final class CryptoUtil extends java.lang.Object implements ICryptoUtil
Utility class contains encryption and hash functions for digital signature.
Project:Library for the integration with the services of @Firma, eVisor and TS@.
- Version:
- 1.2, 14/03/2017.
-
-
Field Summary
-
Fields inherited from interface es.gob.afirma.utils.ICryptoUtil
ENCRYPTION_ALGORITHM_RSA, HASH_ALGORITHM_RIPEMD160, HASH_ALGORITHM_SHA, HASH_ALGORITHM_SHA1, HASH_ALGORITHM_SHA256, HASH_ALGORITHM_SHA384, HASH_ALGORITHM_SHA512
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static byte[]digest(java.lang.String algorithm, byte[] data)Method that obtains the hash computation from a array bytes.static org.bouncycastle.asn1.tsp.MessageImprintgenerateMessageImprintFromXMLAlgorithm(java.lang.String hashAlgXML, byte[] data)Method that obtains the MessageImprint from the digest method algorithm URI.static org.bouncycastle.asn1.x509.AlgorithmIdentifiergetAlgorithmIdentifierByName(java.lang.String hashAlgorithm)Method that obtains the OID of a hash algorithm from the name.static java.lang.StringgetDigestAlgorithmName(java.lang.String pseudoName)Method that gets the name of a digest algorithm by name or alias.static java.lang.StringtranslateAlgorithmIdentifier(org.bouncycastle.asn1.x509.AlgorithmIdentifier algorithmIdentifier)Method that translates aAlgorithmIdentifierobject to a digest algorithm string.static java.lang.StringtranslateXmlDigestAlgorithm(java.lang.String digestAlg)Method that translates aAlgorithmIdentifierobject to a digest algorithm string.
-
-
-
Method Detail
-
digest
public static byte[] digest(java.lang.String algorithm, byte[] data) throws SigningExceptionMethod that obtains the hash computation from a array bytes.- Parameters:
algorithm- Parameter that represents the algorithm used in the hash computation.data- Parameter that represents the source data.- Returns:
- the hash value.
- Throws:
SigningException- If a MessageDigestSpi implementation for the specified algorithm is not available from the specified Provider object.
-
translateAlgorithmIdentifier
public static java.lang.String translateAlgorithmIdentifier(org.bouncycastle.asn1.x509.AlgorithmIdentifier algorithmIdentifier)
Method that translates aAlgorithmIdentifierobject to a digest algorithm string.- Parameters:
algorithmIdentifier- Parameter that represents the OID of the digest algorithm.- Returns:
- the digest algorithm name.
-
getAlgorithmIdentifierByName
public static org.bouncycastle.asn1.x509.AlgorithmIdentifier getAlgorithmIdentifierByName(java.lang.String hashAlgorithm)
Method that obtains the OID of a hash algorithm from the name.- Parameters:
hashAlgorithm- Parameter that represents the name of the hash algorithm.- Returns:
- the OID value.
-
translateXmlDigestAlgorithm
public static java.lang.String translateXmlDigestAlgorithm(java.lang.String digestAlg)
Method that translates aAlgorithmIdentifierobject to a digest algorithm string.- Parameters:
digestAlg- Parameter that represents the digest method algorithm URI.- Returns:
- the digest algorithm name.
-
getDigestAlgorithmName
public static java.lang.String getDigestAlgorithmName(java.lang.String pseudoName)
Method that gets the name of a digest algorithm by name or alias.- Parameters:
pseudoName- Parameter that represents the name or alias of the digest algorithm.- Returns:
- the name of the digest algorithm.
-
generateMessageImprintFromXMLAlgorithm
public static org.bouncycastle.asn1.tsp.MessageImprint generateMessageImprintFromXMLAlgorithm(java.lang.String hashAlgXML, byte[] data)Method that obtains the MessageImprint from the digest method algorithm URI.- Parameters:
hashAlgXML- Parameter that represents the digest method algorithm URI.data- Parameter that represents the hashed message.- Returns:
- the generated MessageImprint.
-
-