Package com.nimbusds.jose.crypto.impl
Class XC20P
java.lang.Object
com.nimbusds.jose.crypto.impl.XC20P
This class defines the XChaCha20 stream cipher as well as the use of the
Poly1305 authenticator.
The eXtended-nonce ChaCha cipher construction (XChaCha) allows for ChaCha-based cipher suites to accept a 192-bit nonce with similar guarantees to the original construction, except with a much lower probability of nonce misuse occurring.
This class is thread-safe.
- Version:
- 2022-02-24
- Author:
- Alexander Martynov
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
The standard authentication tag length (128 bits).static final int
The standard Initialisation Vector (IV) length (192 bits). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]
decryptAuthenticated
(SecretKey secretKey, byte[] iv, byte[] cipherText, byte[] authData, byte[] authTag) Decrypts the specified cipher text using XChaCha20_Poly1305.static AuthenticatedCipherText
encryptAuthenticated
(SecretKey secretKey, Container<byte[]> ivContainer, byte[] plainText, byte[] authData) Encrypts the specified plain text using XChaCha20_Poly1305.
-
Field Details
-
AUTH_TAG_BIT_LENGTH
The standard authentication tag length (128 bits).- See Also:
-
IV_BIT_LENGTH
The standard Initialisation Vector (IV) length (192 bits).- See Also:
-
-
Constructor Details
-
XC20P
public XC20P()
-
-
Method Details
-
encryptAuthenticated
public static AuthenticatedCipherText encryptAuthenticated(SecretKey secretKey, Container<byte[]> ivContainer, byte[] plainText, byte[] authData) throws JOSEException Encrypts the specified plain text using XChaCha20_Poly1305.- Parameters:
secretKey
- The AES key. Must not benull
.plainText
- The plain text. Must not benull
.ivContainer
- The initialisation vector (IV). This is output parameter. On output, it carries the nonce the cipher actually used.authData
- The authenticated data. Must not benull
.- Returns:
- The authenticated cipher text.
- Throws:
JOSEException
- If encryption failed.
-
decryptAuthenticated
public static byte[] decryptAuthenticated(SecretKey secretKey, byte[] iv, byte[] cipherText, byte[] authData, byte[] authTag) throws JOSEException Decrypts the specified cipher text using XChaCha20_Poly1305.- Parameters:
secretKey
- The AES key. Must not benull
.iv
- The initialisation vector (IV). Must not benull
.cipherText
- The cipher text. Must not benull
.authData
- The authenticated data. Must not benull
.authTag
- The authentication tag. Must not benull
.- Returns:
- The decrypted plain text.
- Throws:
JOSEException
- If decryption failed.
-