
org.bouncycastle.its.ETSIEncryptedDataBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bcpkix-fips Show documentation
Show all versions of bcpkix-fips Show documentation
The Bouncy Castle Java APIs for CMS, PKCS, EAC, TSP, CMP, CRMF, OCSP, and certificate generation. The APIs are designed primarily to be used in conjunction with the BC FIPS provider. The APIs may also be used with other providers although if being used in a FIPS context it is the responsibility of the user to ensure that any other providers used are FIPS certified.
package org.bouncycastle.its;
import java.util.ArrayList;
import java.util.List;
import org.bouncycastle.its.operator.ETSIDataEncryptor;
import org.bouncycastle.oer.its.ieee1609dot2.AesCcmCiphertext;
import org.bouncycastle.oer.its.ieee1609dot2.EncryptedData;
import org.bouncycastle.oer.its.ieee1609dot2.SequenceOfRecipientInfo;
import org.bouncycastle.oer.its.ieee1609dot2.SymmetricCiphertext;
public class ETSIEncryptedDataBuilder
{
private final List recipientInfoBuilders = new ArrayList();
public ETSIEncryptedDataBuilder()
{
}
public void addRecipientInfoBuilder(ETSIRecipientInfoBuilder recipientInfoBuilder)
{
recipientInfoBuilders.add(recipientInfoBuilder);
}
public ETSIEncryptedData build(ETSIDataEncryptor encryptor, byte[] content)
{
byte[] opaque = encryptor.encrypt(content);
byte[] key = encryptor.getKey();
byte[] nonce = encryptor.getNonce();
SequenceOfRecipientInfo.Builder builder = SequenceOfRecipientInfo.builder();
for (ETSIRecipientInfoBuilder recipientInfoBuilder : recipientInfoBuilders)
{
builder.addRecipients(recipientInfoBuilder.build(key));
}
// Encryption goes here
return new ETSIEncryptedData(EncryptedData.builder()
.setRecipients(builder.createSequenceOfRecipientInfo())
.setCiphertext(SymmetricCiphertext.aes128ccm(AesCcmCiphertext.builder()
.setCcmCiphertext(opaque)
.setNonce(nonce)
.createAesCcmCiphertext())).createEncryptedData()
);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy