Class EnvelopeCodec.Builder
java.lang.Object
org.jwcarman.codec.crypto.EnvelopeCodec.Builder
- Enclosing class:
EnvelopeCodec
Builder for
EnvelopeCodec.-
Method Summary
Modifier and TypeMethodDescriptionaad(byte[] aad) Sets the additional authenticated data (AAD) bound to every message produced by this codec.allowedKeyIds(Predicate<String> allowedKeyIds) Sets the predicate used to admit a wire keyId on decode, overriding the provider'sDataKeyProvider.allowsKeyId(String).build()Builds theEnvelopeCodec.secureRandom(SecureRandom random) Sets the source of randomness used to generate nonces.strategy(DataKeyStrategy strategy) Sets the strategy used to acquire the data key for each message.
-
Method Details
-
strategy
Sets the strategy used to acquire the data key for each message.- Parameters:
strategy- theDataKeyStrategyto use; defaults toDirectDataKeyStrategy- Returns:
- this builder
-
aad
Sets the additional authenticated data (AAD) bound to every message produced by this codec.- Parameters:
aad- the AAD bytes, defensively copied; must not be empty- Returns:
- this builder
- Throws:
IllegalArgumentException- ifaadis empty
-
allowedKeyIds
Sets the predicate used to admit a wire keyId on decode, overriding the provider'sDataKeyProvider.allowsKeyId(String).- Parameters:
allowedKeyIds- the predicate to consult; defaults toprovider::allowsKeyId- Returns:
- this builder
-
secureRandom
Sets the source of randomness used to generate nonces.- Parameters:
random- theSecureRandomto use; defaults to a new instance- Returns:
- this builder
-
provider
Sets theProviderused to look up theAES/GCM/NoPaddingCipherfor every encode and decode, so a FIPS-validated or otherwise pinned provider can be selected per codec instead of being installed as the JVM's globally highest-priority provider.Resolved once at
build()time: if the provider cannot supply the transform,build()throwsIllegalStateExceptionimmediately rather than letting the misconfiguration surface later as aDecryptionExceptionon the first message.- Parameters:
provider- theProviderto use; defaults to the JDK's default provider lookup- Returns:
- this builder
-
build
Builds theEnvelopeCodec.- Returns:
- a new
EnvelopeCodec - Throws:
IllegalStateException- if a provider was set and cannot supplyAES/GCM/NoPadding
-