diff options
Diffstat (limited to 'libraries/spongycastle/pkix/src/main/java/org/spongycastle/cms/KEKRecipientInfoGenerator.java')
-rw-r--r-- | libraries/spongycastle/pkix/src/main/java/org/spongycastle/cms/KEKRecipientInfoGenerator.java | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/libraries/spongycastle/pkix/src/main/java/org/spongycastle/cms/KEKRecipientInfoGenerator.java b/libraries/spongycastle/pkix/src/main/java/org/spongycastle/cms/KEKRecipientInfoGenerator.java new file mode 100644 index 000000000..480fb5fe9 --- /dev/null +++ b/libraries/spongycastle/pkix/src/main/java/org/spongycastle/cms/KEKRecipientInfoGenerator.java @@ -0,0 +1,39 @@ +package org.spongycastle.cms; + +import org.spongycastle.asn1.ASN1OctetString; +import org.spongycastle.asn1.DEROctetString; +import org.spongycastle.asn1.cms.KEKIdentifier; +import org.spongycastle.asn1.cms.KEKRecipientInfo; +import org.spongycastle.asn1.cms.RecipientInfo; +import org.spongycastle.operator.GenericKey; +import org.spongycastle.operator.OperatorException; +import org.spongycastle.operator.SymmetricKeyWrapper; + +public abstract class KEKRecipientInfoGenerator + implements RecipientInfoGenerator +{ + private final KEKIdentifier kekIdentifier; + + protected final SymmetricKeyWrapper wrapper; + + protected KEKRecipientInfoGenerator(KEKIdentifier kekIdentifier, SymmetricKeyWrapper wrapper) + { + this.kekIdentifier = kekIdentifier; + this.wrapper = wrapper; + } + + public final RecipientInfo generate(GenericKey contentEncryptionKey) + throws CMSException + { + try + { + ASN1OctetString encryptedKey = new DEROctetString(wrapper.generateWrappedKey(contentEncryptionKey)); + + return new RecipientInfo(new KEKRecipientInfo(kekIdentifier, wrapper.getAlgorithmIdentifier(), encryptedKey)); + } + catch (OperatorException e) + { + throw new CMSException("exception wrapping content key: " + e.getMessage(), e); + } + } +}
\ No newline at end of file |