![JAR search and dependency download from the Maven repository](/logo.png)
org.spongycastle.asn1.pkcs.MacData Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of core Show documentation
Show all versions of core Show documentation
Spongy Castle is a package-rename (org.bouncycastle.* to org.spongycastle.*) of Bouncy Castle
intended for the Android platform. Android unfortunately ships with a stripped-down version of
Bouncy Castle, which prevents easy upgrades - Spongy Castle overcomes this and provides a full,
up-to-date version of the Bouncy Castle cryptographic libs.
The newest version!
package org.spongycastle.asn1.pkcs;
import java.math.BigInteger;
import org.spongycastle.asn1.ASN1EncodableVector;
import org.spongycastle.asn1.ASN1Integer;
import org.spongycastle.asn1.ASN1Object;
import org.spongycastle.asn1.ASN1OctetString;
import org.spongycastle.asn1.ASN1Primitive;
import org.spongycastle.asn1.ASN1Sequence;
import org.spongycastle.asn1.DEROctetString;
import org.spongycastle.asn1.DERSequence;
import org.spongycastle.asn1.x509.DigestInfo;
import org.spongycastle.util.Arrays;
public class MacData
extends ASN1Object
{
private static final BigInteger ONE = BigInteger.valueOf(1);
DigestInfo digInfo;
byte[] salt;
BigInteger iterationCount;
public static MacData getInstance(
Object obj)
{
if (obj instanceof MacData)
{
return (MacData)obj;
}
else if (obj != null)
{
return new MacData(ASN1Sequence.getInstance(obj));
}
return null;
}
private MacData(
ASN1Sequence seq)
{
this.digInfo = DigestInfo.getInstance(seq.getObjectAt(0));
this.salt = Arrays.clone(((ASN1OctetString)seq.getObjectAt(1)).getOctets());
if (seq.size() == 3)
{
this.iterationCount = ((ASN1Integer)seq.getObjectAt(2)).getValue();
}
else
{
this.iterationCount = ONE;
}
}
public MacData(
DigestInfo digInfo,
byte[] salt,
int iterationCount)
{
this.digInfo = digInfo;
this.salt = Arrays.clone(salt);
this.iterationCount = BigInteger.valueOf(iterationCount);
}
public DigestInfo getMac()
{
return digInfo;
}
public byte[] getSalt()
{
return Arrays.clone(salt);
}
public BigInteger getIterationCount()
{
return iterationCount;
}
/**
*
* MacData ::= SEQUENCE {
* mac DigestInfo,
* macSalt OCTET STRING,
* iterations INTEGER DEFAULT 1
* -- Note: The default is for historic reasons and its use is deprecated. A
* -- higher value, like 1024 is recommended.
*
* @return the basic ASN1Primitive construction.
*/
public ASN1Primitive toASN1Primitive()
{
ASN1EncodableVector v = new ASN1EncodableVector();
v.add(digInfo);
v.add(new DEROctetString(salt));
if (!iterationCount.equals(ONE))
{
v.add(new ASN1Integer(iterationCount));
}
return new DERSequence(v);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy