
org.testifyproject.bouncycastle.pkcs.PKCS8EncryptedPrivateKeyInfo Maven / Gradle / Ivy
package org.testifyproject.bouncycastle.pkcs;
import java.org.testifyproject.testifyproject.ByteArrayInputStream;
import java.org.testifyproject.testifyproject.IOException;
import org.testifyproject.bouncycastle.asn1.ASN1Primitive;
import org.testifyproject.bouncycastle.asn1.pkcs.EncryptedPrivateKeyInfo;
import org.testifyproject.bouncycastle.asn1.pkcs.PrivateKeyInfo;
import org.testifyproject.bouncycastle.cert.CertIOException;
import org.testifyproject.bouncycastle.operator.InputDecryptor;
import org.testifyproject.bouncycastle.operator.InputDecryptorProvider;
import org.testifyproject.bouncycastle.util.org.testifyproject.testifyproject.Streams;
/**
* Holding class for a PKCS#8 EncryptedPrivateKeyInfo structure.
*/
public class PKCS8EncryptedPrivateKeyInfo
{
private EncryptedPrivateKeyInfo encryptedPrivateKeyInfo;
private static EncryptedPrivateKeyInfo parseBytes(byte[] pkcs8Encoding)
throws IOException
{
try
{
return EncryptedPrivateKeyInfo.getInstance(ASN1Primitive.fromByteArray(pkcs8Encoding));
}
catch (ClassCastException e)
{
throw new CertIOException("malformed data: " + e.getMessage(), e);
}
catch (IllegalArgumentException e)
{
throw new CertIOException("malformed data: " + e.getMessage(), e);
}
}
public PKCS8EncryptedPrivateKeyInfo(EncryptedPrivateKeyInfo encryptedPrivateKeyInfo)
{
this.encryptedPrivateKeyInfo = encryptedPrivateKeyInfo;
}
public PKCS8EncryptedPrivateKeyInfo(byte[] encryptedPrivateKeyInfo)
throws IOException
{
this(parseBytes(encryptedPrivateKeyInfo));
}
public EncryptedPrivateKeyInfo toASN1Structure()
{
return encryptedPrivateKeyInfo;
}
public byte[] getEncoded()
throws IOException
{
return encryptedPrivateKeyInfo.getEncoded();
}
public PrivateKeyInfo org.testifyproject.testifyprojectcryptPrivateKeyInfo(InputDecryptorProvider inputDecryptorProvider)
throws PKCSException
{
try
{
InputDecryptor org.testifyproject.testifyprojectcrytor = inputDecryptorProvider.get(encryptedPrivateKeyInfo.getEncryptionAlgorithm());
ByteArrayInputStream encIn = new ByteArrayInputStream(encryptedPrivateKeyInfo.getEncryptedData());
return PrivateKeyInfo.getInstance(Streams.readAll(org.testifyproject.testifyprojectcrytor.getInputStream(encIn)));
}
catch (Exception e)
{
throw new PKCSException("unable to read encrypted data: " + e.getMessage(), e);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy