org.spongycastle.operator.bc.BcUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of scprov-jdk15 Show documentation
Show all versions of scprov-jdk15 Show documentation
Spongy Castle is a package-rename (org.bouncycastle.* to org.spongycastle.*) of Bouncy Castle intended for Android.
Android ships with a stripped-down version of Bouncy Castle - this causes classloader collisions if you try to add
an alternative (updated/complete) Bouncy Castle jar.
This jar contains JCE provider and lightweight API for the Bouncy Castle Cryptography APIs for JDK 1.5.
package org.spongycastle.operator.bc;
import org.spongycastle.asn1.nist.NISTObjectIdentifiers;
import org.spongycastle.asn1.oiw.OIWObjectIdentifiers;
import org.spongycastle.asn1.pkcs.PKCSObjectIdentifiers;
import org.spongycastle.asn1.x509.AlgorithmIdentifier;
import org.spongycastle.crypto.Digest;
import org.spongycastle.crypto.digests.MD4Digest;
import org.spongycastle.crypto.digests.MD5Digest;
import org.spongycastle.crypto.digests.SHA1Digest;
import org.spongycastle.crypto.digests.SHA224Digest;
import org.spongycastle.crypto.digests.SHA256Digest;
import org.spongycastle.crypto.digests.SHA384Digest;
import org.spongycastle.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;
}
}