public interface AeadAlgorithm extends Identifiable, KeyLengthSupplier, KeyBuilderSupplier<SecretKey,SecretKeyBuilder>
Jwts.ENC
.
"enc" identifier
AeadAlgorithm
extends Identifiable
: the value returned from getId()
will be used as the JWE "enc" protected header value.
Key Strength
Encryption strength is in part attributed to how difficult it is to discover the encryption key. As such, cryptographic algorithms often require keys of a minimum length to ensure the keys are difficult to discover and the algorithm's security properties are maintained.
The AeadAlgorithm
interface extends the KeyLengthSupplier
interface to represent the length
in bits a key must have to be used with its implementation. If you do not want to worry about lengths and
parameters of keys required for an algorithm, it is often easier to automatically generate a key that adheres
to the algorithms requirements, as discussed below.
Key Generation
AeadAlgorithm
extends KeyBuilderSupplier
to enable SecretKey
generation. Each AEAD
algorithm instance will return a KeyBuilder
that ensures any created keys will have a sufficient length
and algorithm parameters required by that algorithm. For example:
SecretKey key = aeadAlgorithm.key().build();
The resulting key
is guaranteed to have the correct algorithm parameters and strength/length necessary for
that exact aeadAlgorithm
instance.
Jwts.ENC
,
Identifiable.getId()
,
KeyLengthSupplier
,
KeyBuilderSupplier
,
KeyBuilder
Modifier and Type | Method and Description |
---|---|
void |
decrypt(DecryptAeadRequest request,
OutputStream out)
Decrypts ciphertext and authenticates any
associated data ,
writing the decrypted plaintext to the provided out put stream. |
void |
encrypt(AeadRequest req,
AeadResult res)
Encrypts plaintext and signs any
associated data , placing the resulting
ciphertext, initialization vector and authentication tag in the provided result . |
getId
getKeyBitLength
key
void encrypt(AeadRequest req, AeadResult res) throws SecurityException
associated data
, placing the resulting
ciphertext, initialization vector and authentication tag in the provided result
.req
- the encryption request representing the plaintext to be encrypted, any additional
integrity-protected data and the encryption key.res
- the result to write ciphertext, initialization vector and AAD authentication tag (aka digest)SecurityException
- if there is an encryption problem or AAD authenticity cannot be guaranteed.void decrypt(DecryptAeadRequest request, OutputStream out) throws SecurityException
associated data
,
writing the decrypted plaintext to the provided out
put stream.request
- the decryption request representing the ciphertext to be decrypted, any additional
integrity-protected data, authentication tag, initialization vector, and decryption keyout
- the OutputStream for writing decrypted plaintextSecurityException
- if there is a decryption problem or authenticity assertions fail.Copyright © 2014–2024 jsonwebtoken.io. All rights reserved.