Package com.nimbusds.jose.crypto.impl
Class ConcatKDF
java.lang.Object
com.nimbusds.jose.crypto.impl.ConcatKDF
- All Implemented Interfaces:
JCAAware<JCAContext>
Concatenation Key Derivation Function (KDF). This class is thread-safe.
See NIST.800-56A.
- Version:
- 2017-06-01
- Author:
- Vladimir Dzhuvinov
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]composeOtherInfo(byte[] algID, byte[] partyUInfo, byte[] partyVInfo, byte[] suppPubInfo, byte[] suppPrivInfo) Composes the other info asalgID || partyUInfo || partyVInfo || suppPubInfo || suppPrivInfo.static byte[]composeOtherInfo(byte[] algID, byte[] partyUInfo, byte[] partyVInfo, byte[] suppPubInfo, byte[] suppPrivInfo, byte[] tag) Composes the other info asalgID || partyUInfo || partyVInfo || suppPubInfo || suppPrivInfo || tag.static intcomputeDigestCycles(int digestLengthBits, int keyLengthBits) Computes the required digest (hashing) cycles for the specified message digest length and derived key length.Derives a key from the specified inputs.deriveKey(SecretKey sharedSecret, int keyLength, byte[] algID, byte[] partyUInfo, byte[] partyVInfo, byte[] suppPubInfo, byte[] suppPrivInfo) Derives a key from the specified inputs.deriveKey(SecretKey sharedSecret, int keyLength, byte[] algID, byte[] partyUInfo, byte[] partyVInfo, byte[] suppPubInfo, byte[] suppPrivInfo, byte[] tag) Derives a key from the specified inputs.static byte[]encodeDataWithLength(byte[] data) Encodes the specified data asdata.length || data.static byte[]Encodes the specified BASE64URL encoded datadata.length || data.static byte[]encodeIntData(int data) Encodes the specified integer data as a four byte array.static byte[]Encodes no / empty data as an empty byte array.static byte[]encodeStringData(String data) Encodes the specified string data asdata.length || data.Returns the JCA name of the hash algorithm.Returns the Java Cryptography Architecture (JCA) context.
-
Constructor Details
-
ConcatKDF
Creates a new concatenation Key Derivation Function (KDF) with the specified hash algorithm.- Parameters:
jcaHashAlg- The JCA name of the hash algorithm. Must be supported and notnull.
-
-
Method Details
-
getHashAlgorithm
Returns the JCA name of the hash algorithm.- Returns:
- The JCA name of the hash algorithm.
-
getJCAContext
Description copied from interface:JCAAwareReturns the Java Cryptography Architecture (JCA) context. May be used to set a specific JCA security provider or secure random generator.- Specified by:
getJCAContextin interfaceJCAAware<JCAContext>- Returns:
- The JCA context. Not
null.
-
deriveKey
public SecretKey deriveKey(SecretKey sharedSecret, int keyLengthBits, byte[] otherInfo) throws JOSEException Derives a key from the specified inputs.- Parameters:
sharedSecret- The shared secret. Must not benull.keyLengthBits- The length of the key to derive, in bits.otherInfo- Other info,nullif not specified.- Returns:
- The derived key, with algorithm set to "AES".
- Throws:
JOSEException- If the key derivation failed.
-
deriveKey
public SecretKey deriveKey(SecretKey sharedSecret, int keyLength, byte[] algID, byte[] partyUInfo, byte[] partyVInfo, byte[] suppPubInfo, byte[] suppPrivInfo) throws JOSEException Derives a key from the specified inputs.- Parameters:
sharedSecret- The shared secret. Must not benull.keyLength- The length of the key to derive, in bits.algID- The algorithm identifier,nullif not specified.partyUInfo- The partyUInfo,nullif not specified.partyVInfo- The partyVInfonullif not specified.suppPubInfo- The suppPubInfo,nullif not specified.suppPrivInfo- The suppPrivInfo,nullif not specified.- Returns:
- The derived key, with algorithm set to "AES".
- Throws:
JOSEException- If the key derivation failed.
-
deriveKey
public SecretKey deriveKey(SecretKey sharedSecret, int keyLength, byte[] algID, byte[] partyUInfo, byte[] partyVInfo, byte[] suppPubInfo, byte[] suppPrivInfo, byte[] tag) throws JOSEException Derives a key from the specified inputs.- Parameters:
sharedSecret- The shared secret. Must not benull.keyLength- The length of the key to derive, in bits.algID- The algorithm identifier,nullif not specified.partyUInfo- The partyUInfo,nullif not specified.partyVInfo- The partyVInfonullif not specified.suppPubInfo- The suppPubInfo,nullif not specified.suppPrivInfo- The suppPrivInfo,nullif not specified.tag- The cctag,nullif not specified.- Returns:
- The derived key, with algorithm set to "AES".
- Throws:
JOSEException- If the key derivation failed.
-
composeOtherInfo
public static byte[] composeOtherInfo(byte[] algID, byte[] partyUInfo, byte[] partyVInfo, byte[] suppPubInfo, byte[] suppPrivInfo) Composes the other info asalgID || partyUInfo || partyVInfo || suppPubInfo || suppPrivInfo.- Parameters:
algID- The algorithm identifier,nullif not specified.partyUInfo- The partyUInfo,nullif not specified.partyVInfo- The partyVInfonullif not specified.suppPubInfo- The suppPubInfo,nullif not specified.suppPrivInfo- The suppPrivInfo,nullif not specified.- Returns:
- The resulting other info.
-
composeOtherInfo
public static byte[] composeOtherInfo(byte[] algID, byte[] partyUInfo, byte[] partyVInfo, byte[] suppPubInfo, byte[] suppPrivInfo, byte[] tag) Composes the other info asalgID || partyUInfo || partyVInfo || suppPubInfo || suppPrivInfo || tag.- Parameters:
algID- The algorithm identifier,nullif not specified.partyUInfo- The partyUInfo,nullif not specified.partyVInfo- The partyVInfonullif not specified.suppPubInfo- The suppPubInfo,nullif not specified.suppPrivInfo- The suppPrivInfo,nullif not specified.tag- The cctag,nullif not specified.- Returns:
- The resulting other info.
-
computeDigestCycles
Computes the required digest (hashing) cycles for the specified message digest length and derived key length.- Parameters:
digestLengthBits- The length of the message digest, in bits.keyLengthBits- The length of the derived key, in bits.- Returns:
- The digest cycles.
-
encodeNoData
Encodes no / empty data as an empty byte array.- Returns:
- The encoded data.
-
encodeIntData
Encodes the specified integer data as a four byte array.- Parameters:
data- The integer data to encode.- Returns:
- The encoded data.
-
encodeStringData
Encodes the specified string data asdata.length || data.- Parameters:
data- The string data, UTF-8 encoded. May benull.- Returns:
- The encoded data.
-
encodeDataWithLength
Encodes the specified data asdata.length || data.- Parameters:
data- The data to encode, may benull.- Returns:
- The encoded data.
-
encodeDataWithLength
Encodes the specified BASE64URL encoded datadata.length || data.- Parameters:
data- The data to encode, may benull.- Returns:
- The encoded data.
-