Search in sources :

Example 1 with EncryptedData

use of com.github.zhenwei.pkix.util.asn1.cms.EncryptedData in project LinLong-Java by zhenwei1108.

the class CMSEncryptedDataGenerator method doGenerate.

private CMSEncryptedData doGenerate(CMSTypedData content, OutputEncryptor contentEncryptor) throws CMSException {
    AlgorithmIdentifier encAlgId;
    ASN1OctetString encContent;
    ByteArrayOutputStream bOut = new ByteArrayOutputStream();
    try {
        OutputStream cOut = contentEncryptor.getOutputStream(bOut);
        content.write(cOut);
        cOut.close();
    } catch (IOException e) {
        throw new CMSException("");
    }
    byte[] encryptedContent = bOut.toByteArray();
    encAlgId = contentEncryptor.getAlgorithmIdentifier();
    encContent = new BEROctetString(encryptedContent);
    EncryptedContentInfo eci = new EncryptedContentInfo(content.getContentType(), encAlgId, encContent);
    ASN1Set unprotectedAttrSet = null;
    if (unprotectedAttributeGenerator != null) {
        AttributeTable attrTable = unprotectedAttributeGenerator.getAttributes(Collections.EMPTY_MAP);
        unprotectedAttrSet = new BERSet(attrTable.toASN1EncodableVector());
    }
    ContentInfo contentInfo = new ContentInfo(CMSObjectIdentifiers.encryptedData, new EncryptedData(eci, unprotectedAttrSet));
    return new CMSEncryptedData(contentInfo);
}
Also used : ASN1OctetString(com.github.zhenwei.core.asn1.ASN1OctetString) BERSet(com.github.zhenwei.core.asn1.BERSet) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) AttributeTable(com.github.zhenwei.pkix.util.asn1.cms.AttributeTable) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) AlgorithmIdentifier(com.github.zhenwei.core.asn1.x509.AlgorithmIdentifier) BEROctetString(com.github.zhenwei.core.asn1.BEROctetString) ASN1Set(com.github.zhenwei.core.asn1.ASN1Set) EncryptedContentInfo(com.github.zhenwei.pkix.util.asn1.cms.EncryptedContentInfo) ContentInfo(com.github.zhenwei.pkix.util.asn1.cms.ContentInfo) EncryptedData(com.github.zhenwei.pkix.util.asn1.cms.EncryptedData) EncryptedContentInfo(com.github.zhenwei.pkix.util.asn1.cms.EncryptedContentInfo)

Aggregations

ASN1OctetString (com.github.zhenwei.core.asn1.ASN1OctetString)1 ASN1Set (com.github.zhenwei.core.asn1.ASN1Set)1 BEROctetString (com.github.zhenwei.core.asn1.BEROctetString)1 BERSet (com.github.zhenwei.core.asn1.BERSet)1 AlgorithmIdentifier (com.github.zhenwei.core.asn1.x509.AlgorithmIdentifier)1 AttributeTable (com.github.zhenwei.pkix.util.asn1.cms.AttributeTable)1 ContentInfo (com.github.zhenwei.pkix.util.asn1.cms.ContentInfo)1 EncryptedContentInfo (com.github.zhenwei.pkix.util.asn1.cms.EncryptedContentInfo)1 EncryptedData (com.github.zhenwei.pkix.util.asn1.cms.EncryptedData)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1