org.bouncycastle.operator.bc.BcUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bcmail-jdk16 Show documentation
Show all versions of bcmail-jdk16 Show documentation
The Bouncy Castle Java CMS and S/MIME APIs for handling the CMS and S/MIME protocols. This jar contains CMS and S/MIME APIs for JDK 1.6. The APIs can be used in conjunction with a JCE/JCA provider such as the one provided with the Bouncy Castle Cryptography APIs. If the S/MIME API is used, the JavaMail API and the Java activation framework will also be needed.
The newest version!
package org.bouncycastle.operator.bc;
import org.bouncycastle.asn1.nist.NISTObjectIdentifiers;
import org.bouncycastle.asn1.oiw.OIWObjectIdentifiers;
import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.crypto.Digest;
import org.bouncycastle.crypto.digests.MD4Digest;
import org.bouncycastle.crypto.digests.MD5Digest;
import org.bouncycastle.crypto.digests.SHA1Digest;
import org.bouncycastle.crypto.digests.SHA224Digest;
import org.bouncycastle.crypto.digests.SHA256Digest;
import org.bouncycastle.crypto.digests.SHA384Digest;
import org.bouncycastle.operator.OperatorCreationException;
class BcUtil
{
static Digest createDigest(AlgorithmIdentifier digAlg)
throws OperatorCreationException
{
Digest dig;
if (digAlg.getAlgorithm().equals(OIWObjectIdentifiers.idSHA1))
{
dig = new SHA1Digest();
}
else if (digAlg.getAlgorithm().equals(NISTObjectIdentifiers.id_sha224))
{
dig = new SHA224Digest();
}
else if (digAlg.getAlgorithm().equals(NISTObjectIdentifiers.id_sha256))
{
dig = new SHA256Digest();
}
else if (digAlg.getAlgorithm().equals(NISTObjectIdentifiers.id_sha384))
{
dig = new SHA384Digest();
}
else if (digAlg.getAlgorithm().equals(NISTObjectIdentifiers.id_sha512))
{
dig = new SHA384Digest();
}
else if (digAlg.getAlgorithm().equals(PKCSObjectIdentifiers.md5))
{
dig = new MD5Digest();
}
else if (digAlg.getAlgorithm().equals(PKCSObjectIdentifiers.md4))
{
dig = new MD4Digest();
}
else
{
throw new OperatorCreationException("cannot recognise digest");
}
return dig;
}
}