All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.gatling.recorder.internal.bouncycastle.its.ETSIEncryptedDataBuilder Maven / Gradle / Ivy

There is a newer version: 1.78.1
Show newest version
package io.gatling.recorder.internal.bouncycastle.its;

import java.util.ArrayList;
import java.util.List;

import io.gatling.recorder.internal.bouncycastle.its.operator.ETSIDataEncryptor;
import io.gatling.recorder.internal.bouncycastle.oer.its.ieee1609dot2.AesCcmCiphertext;
import io.gatling.recorder.internal.bouncycastle.oer.its.ieee1609dot2.EncryptedData;
import io.gatling.recorder.internal.bouncycastle.oer.its.ieee1609dot2.SequenceOfRecipientInfo;
import io.gatling.recorder.internal.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 - 2024 Weber Informatics LLC | Privacy Policy