
org.spongycastle.asn1.bc.SecretKeyData 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.bc;
import org.spongycastle.asn1.ASN1EncodableVector;
import org.spongycastle.asn1.ASN1Object;
import org.spongycastle.asn1.ASN1ObjectIdentifier;
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.util.Arrays;
/**
*
* SecretKeyData ::= SEQUENCE {
* keyAlgorithm OBJECT IDENTIFIER,
* keyBytes OCTET STRING
* }
*
*/
public class SecretKeyData
extends ASN1Object
{
private final ASN1ObjectIdentifier keyAlgorithm;
private final ASN1OctetString keyBytes;
public SecretKeyData(ASN1ObjectIdentifier keyAlgorithm, byte[] keyBytes)
{
this.keyAlgorithm = keyAlgorithm;
this.keyBytes = new DEROctetString(Arrays.clone(keyBytes));
}
private SecretKeyData(ASN1Sequence seq)
{
this.keyAlgorithm = ASN1ObjectIdentifier.getInstance(seq.getObjectAt(0));
this.keyBytes = ASN1OctetString.getInstance(seq.getObjectAt(1));
}
public static SecretKeyData getInstance(Object o)
{
if (o instanceof SecretKeyData)
{
return (SecretKeyData)o;
}
else if (o != null)
{
return new SecretKeyData(ASN1Sequence.getInstance(o));
}
return null;
}
public byte[] getKeyBytes()
{
return Arrays.clone(keyBytes.getOctets());
}
public ASN1ObjectIdentifier getKeyAlgorithm()
{
return keyAlgorithm;
}
public ASN1Primitive toASN1Primitive()
{
ASN1EncodableVector v = new ASN1EncodableVector();
v.add(keyAlgorithm);
v.add(keyBytes);
return new DERSequence(v);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy