org.bouncycastle.cms.CMSEncryptedData Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bcpkix-lts8on Show documentation
Show all versions of bcpkix-lts8on Show documentation
The Bouncy Castle Java APIs for CMS, PKCS, EAC, TSP, CMP, CRMF, OCSP, and certificate generation. This jar contains APIs for JDK 1.8 and up. The APIs are designed primarily to be used in conjunction with the BC LTS provider but may also be used with other providers providing cryptographic services.
package org.bouncycastle.cms;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import org.bouncycastle.asn1.cms.ContentInfo;
import org.bouncycastle.asn1.cms.EncryptedContentInfo;
import org.bouncycastle.asn1.cms.EncryptedData;
import org.bouncycastle.operator.InputDecryptor;
import org.bouncycastle.operator.InputDecryptorProvider;
public class CMSEncryptedData
{
private ContentInfo contentInfo;
private EncryptedData encryptedData;
public CMSEncryptedData(ContentInfo contentInfo)
{
this.contentInfo = contentInfo;
this.encryptedData = EncryptedData.getInstance(contentInfo.getContent());
}
public byte[] getContent(InputDecryptorProvider inputDecryptorProvider)
throws CMSException
{
try
{
return CMSUtils.streamToByteArray(getContentStream(inputDecryptorProvider).getContentStream());
}
catch (IOException e)
{
throw new CMSException("unable to parse internal stream: " + e.getMessage(), e);
}
}
public CMSTypedStream getContentStream(InputDecryptorProvider inputDecryptorProvider)
throws CMSException
{
try
{
EncryptedContentInfo encContentInfo = encryptedData.getEncryptedContentInfo();
InputDecryptor decrytor = inputDecryptorProvider.get(encContentInfo.getContentEncryptionAlgorithm());
ByteArrayInputStream encIn = new ByteArrayInputStream(encContentInfo.getEncryptedContent().getOctets());
return new CMSTypedStream(encContentInfo.getContentType(), decrytor.getInputStream(encIn));
}
catch (Exception e)
{
throw new CMSException("unable to create stream: " + e.getMessage(), e);
}
}
/**
* return the ContentInfo
*/
public ContentInfo toASN1Structure()
{
return contentInfo;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy