org.bouncycastle.asn1.bc.EncryptedPrivateKeyData Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bcprov-ext-jdk15on Show documentation
Show all versions of bcprov-ext-jdk15on Show documentation
The Bouncy Castle Crypto package is a Java implementation of cryptographic algorithms. This jar contains JCE provider and lightweight API for the Bouncy Castle Cryptography APIs for JDK 1.5 to JDK 1.7. Note: this package includes the IDEA and NTRU encryption algorithms.
package org.bouncycastle.asn1.bc;
import org.bouncycastle.asn1.ASN1EncodableVector;
import org.bouncycastle.asn1.ASN1Object;
import org.bouncycastle.asn1.ASN1Primitive;
import org.bouncycastle.asn1.ASN1Sequence;
import org.bouncycastle.asn1.DERSequence;
import org.bouncycastle.asn1.pkcs.EncryptedPrivateKeyInfo;
import org.bouncycastle.asn1.x509.Certificate;
/**
*
* EncryptedPrivateKeyObjectData ::= SEQUENCE {
* encryptedPrivateKeyInfo EncryptedPrivateKeyInfo,
* certificates SEQUENCE OF Certificate
* }
*
*/
public class EncryptedPrivateKeyData
extends ASN1Object
{
private final EncryptedPrivateKeyInfo encryptedPrivateKeyInfo;
private final Certificate[] certificateChain;
public EncryptedPrivateKeyData(EncryptedPrivateKeyInfo encryptedPrivateKeyInfo, Certificate[] certificateChain)
{
this.encryptedPrivateKeyInfo = encryptedPrivateKeyInfo;
this.certificateChain = new Certificate[certificateChain.length];
System.arraycopy(certificateChain, 0, this.certificateChain, 0, certificateChain.length);
}
private EncryptedPrivateKeyData(ASN1Sequence seq)
{
encryptedPrivateKeyInfo = EncryptedPrivateKeyInfo.getInstance(seq.getObjectAt(0));
ASN1Sequence certSeq = ASN1Sequence.getInstance(seq.getObjectAt(1));
certificateChain = new Certificate[certSeq.size()];
for (int i = 0; i != certificateChain.length; i++)
{
certificateChain[i] = Certificate.getInstance(certSeq.getObjectAt(i));
}
}
public static EncryptedPrivateKeyData getInstance(Object o)
{
if (o instanceof EncryptedPrivateKeyData)
{
return (EncryptedPrivateKeyData)o;
}
else if (o != null)
{
return new EncryptedPrivateKeyData(ASN1Sequence.getInstance(o));
}
return null;
}
public Certificate[] getCertificateChain()
{
Certificate[] tmp = new Certificate[certificateChain.length];
System.arraycopy(certificateChain, 0, tmp, 0, certificateChain.length);
return tmp;
}
public EncryptedPrivateKeyInfo getEncryptedPrivateKeyInfo()
{
return encryptedPrivateKeyInfo;
}
public ASN1Primitive toASN1Primitive()
{
ASN1EncodableVector v = new ASN1EncodableVector();
v.add(encryptedPrivateKeyInfo);
v.add(new DERSequence(certificateChain));
return new DERSequence(v);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy