@ThreadSafe public class AESEncrypter extends Object implements JWEEncrypter
JWE objects
. This class
is thread-safe.
Supports the following JWE algorithms:
JWEAlgorithm.A128KW
JWEAlgorithm.A192KW
JWEAlgorithm.A256KW
JWEAlgorithm.A128GCMKW
JWEAlgorithm.A192GCMKW
JWEAlgorithm.A256GCMKW
Supports the following encryption methods:
Modifier and Type | Field and Description |
---|---|
static Map<Integer,Set<JWEAlgorithm>> |
COMPATIBLE_ALGORITHMS
The JWE algorithms compatible with each key size.
|
protected Provider |
contentEncryptionProvider
The JCA provider for the content encryption,
null if not
specified (implies default one). |
protected Provider |
keyEncryptionProvider
The JCA provider for the key encryption,
null if not
specified (implies default one). |
protected Provider |
macProvider
The JCA provider for the MAC computation,
null if not
specified (implies default one). |
static Set<JWEAlgorithm> |
SUPPORTED_ALGORITHMS
The supported JWE algorithms.
|
static Set<EncryptionMethod> |
SUPPORTED_ENCRYPTION_METHODS
The supported encryption methods.
|
Constructor and Description |
---|
AESEncrypter(byte[] keyBytes)
Creates a new AES encrypter.
|
AESEncrypter(SecretKey kek)
Creates a new AES encrypter.
|
Modifier and Type | Method and Description |
---|---|
JWECryptoParts |
encrypt(JWEHeader header,
byte[] bytes)
Encrypts the specified clear text of a
JWE object . |
SecretKey |
getKey()
Gets the Key Encrypting Key.
|
protected SecureRandom |
getSecureRandom()
Returns the secure random generator for this JWE provider.
|
void |
setContentEncryptionProvider(Provider provider)
Sets a specific JCA provider for the content encryption.
|
void |
setKeyEncryptionProvider(Provider provider)
Sets a specific JCA provider for the key encryption.
|
void |
setMACProvider(Provider provider)
Sets a specific JCA provider for MAC computation (where required by
the JWE encryption method).
|
void |
setProvider(Provider provider)
Sets a specific JCA provider, to be used for all operations.
|
void |
setSecureRandom(SecureRandom randomGen)
Sets a specific secure random generator for the initialisation
vector and other purposes requiring a random number.
|
Set<JWEAlgorithm> |
supportedAlgorithms()
Returns the names of the supported JWE algorithms.
|
Set<EncryptionMethod> |
supportedEncryptionMethods()
Returns the names of the supported encryption methods.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
setContentEncryptionProvider, setKeyEncryptionProvider, setMACProvider, setSecureRandom, supportedAlgorithms, supportedEncryptionMethods
setProvider
public static final Set<JWEAlgorithm> SUPPORTED_ALGORITHMS
public static final Set<EncryptionMethod> SUPPORTED_ENCRYPTION_METHODS
public static final Map<Integer,Set<JWEAlgorithm>> COMPATIBLE_ALGORITHMS
protected Provider keyEncryptionProvider
null
if not
specified (implies default one).protected Provider contentEncryptionProvider
null
if not
specified (implies default one).protected Provider macProvider
null
if not
specified (implies default one).public AESEncrypter(SecretKey kek)
kek
- The Key Encrypting Key. Must be 128 bits (16 bytes), 192
bits (24 bytes) or 256 bits (32 bytes). Must not be
null
.public AESEncrypter(byte[] keyBytes)
keyBytes
- The Key Encrypting Key, as a byte array. Must be 128
bits (16 bytes), 192 bits (24 bytes) or 256 bits (32
bytes). Must not be null
.public JWECryptoParts encrypt(JWEHeader header, byte[] bytes) throws JOSEException
JWEEncrypter
JWE object
.encrypt
in interface JWEEncrypter
header
- The JSON Web Encryption (JWE) header. Must specify a
supported JWE algorithm and must not be
null
.bytes
- The clear text to encrypt. Must not be null
.JOSEException
- If the JWE algorithm is not supported or if
encryption failed for some other reason.public Set<JWEAlgorithm> supportedAlgorithms()
JWEAlgorithmProvider
alg
JWE header parameter.supportedAlgorithms
in interface JWEAlgorithmProvider
public Set<EncryptionMethod> supportedEncryptionMethods()
JWEAlgorithmProvider
enc
JWE header parameter.supportedEncryptionMethods
in interface JWEAlgorithmProvider
public void setProvider(Provider provider)
AlgorithmProvider
setProvider
in interface AlgorithmProvider
provider
- The JCA provider, or null
to use the default
one.public void setKeyEncryptionProvider(Provider provider)
JWEAlgorithmProvider
setKeyEncryptionProvider
in interface JWEAlgorithmProvider
provider
- The JCA provider, or null
to use the default
one.public void setContentEncryptionProvider(Provider provider)
JWEAlgorithmProvider
setContentEncryptionProvider
in interface JWEAlgorithmProvider
provider
- The JCA provider, or null
to use the default
one.public void setMACProvider(Provider provider)
JWEAlgorithmProvider
setMACProvider
in interface JWEAlgorithmProvider
provider
- The JCA provider, or null
to use the default
one.public void setSecureRandom(SecureRandom randomGen)
JWEAlgorithmProvider
setSecureRandom
in interface JWEAlgorithmProvider
randomGen
- The secure random generator, or null
to use
the default one.protected SecureRandom getSecureRandom()
Copyright © 2015 Connect2id Ltd.. All Rights Reserved.