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 polaris-all Show documentation
Show all versions of polaris-all Show documentation
All in one project for polaris-java
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