org.spongycastle.asn1.mozilla.PublicKeyAndChallenge 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.asn1.mozilla;
import org.spongycastle.asn1.ASN1Encodable;
import org.spongycastle.asn1.DERObject;
import org.spongycastle.asn1.DERIA5String;
import org.spongycastle.asn1.ASN1Sequence;
import org.spongycastle.asn1.x509.SubjectPublicKeyInfo;
/**
* This is designed to parse
* the PublicKeyAndChallenge created by the KEYGEN tag included by
* Mozilla based browsers.
*
* PublicKeyAndChallenge ::= SEQUENCE {
* spki SubjectPublicKeyInfo,
* challenge IA5STRING
* }
*
*
*/
public class PublicKeyAndChallenge
extends ASN1Encodable
{
private ASN1Sequence pkacSeq;
private SubjectPublicKeyInfo spki;
private DERIA5String challenge;
public static PublicKeyAndChallenge getInstance(Object obj)
{
if (obj instanceof PublicKeyAndChallenge)
{
return (PublicKeyAndChallenge)obj;
}
else if (obj instanceof ASN1Sequence)
{
return new PublicKeyAndChallenge((ASN1Sequence)obj);
}
throw new IllegalArgumentException("unkown object in factory: " + obj.getClass().getName());
}
public PublicKeyAndChallenge(ASN1Sequence seq)
{
pkacSeq = seq;
spki = SubjectPublicKeyInfo.getInstance(seq.getObjectAt(0));
challenge = DERIA5String.getInstance(seq.getObjectAt(1));
}
public DERObject toASN1Object()
{
return pkacSeq;
}
public SubjectPublicKeyInfo getSubjectPublicKeyInfo()
{
return spki;
}
public DERIA5String getChallenge()
{
return challenge;
}
}