Package jenkins.security
Class HMACConfidentialKey
java.lang.Object
jenkins.security.ConfidentialKey
jenkins.security.HMACConfidentialKey
ConfidentialKey
that's used for creating a token by hashing some information with secret
(such as hash(msg|secret)
).
This provides more secure version of it by using HMAC. See this blog post for background. This implementation also never leaks the secret value to outside, so it makes it impossible for the careless caller to misuse the key (thus protecting ourselves from our own stupidity!)
- Since:
- 1.498
- Author:
- Kohsuke Kawaguchi
-
Constructor Summary
ConstructorDescriptionHMACConfidentialKey
(Class owner, String shortName) HMACConfidentialKey
(Class owner, String shortName, int length) Calls intoHMACConfidentialKey(String, int)
by combining the class name and the shortName as the ID.Calls intoHMACConfidentialKey(String, int)
with the longest possible HMAC length.HMACConfidentialKey
(String id, int length) -
Method Summary
Modifier and TypeMethodDescriptionboolean
checkMac
(byte[] message, byte[] mac) Convenience method for verifying the MAC code.boolean
Verifies MAC constructed frommac(String)
Creates a newMac
object.byte[]
mac
(byte[] message) Computes the message authentication code for the specified byte sequence.Computes the message authentication code and return it as a string.Methods inherited from class jenkins.security.ConfidentialKey
getId, load, store
-
Constructor Details
-
HMACConfidentialKey
- Parameters:
length
- Byte length of the HMAC code. By default we use HMAC-SHA256, which produces 256bit (=32bytes) HMAC, but if different use cases requires a shorter HMAC, specify the desired length here. Note that when usingmac(String)
, string encoding causes the length to double. So if you want to get 16-letter HMAC, you specify 8 here.
-
HMACConfidentialKey
Calls intoHMACConfidentialKey(String, int)
with the longest possible HMAC length. -
HMACConfidentialKey
Calls intoHMACConfidentialKey(String, int)
by combining the class name and the shortName as the ID. -
HMACConfidentialKey
-
-
Method Details
-
mac
public byte[] mac(byte[] message) Computes the message authentication code for the specified byte sequence. -
checkMac
public boolean checkMac(byte[] message, byte[] mac) Convenience method for verifying the MAC code. -
mac
Computes the message authentication code and return it as a string. While redundant, often convenient. -
checkMac
Verifies MAC constructed frommac(String)
-
createMac
Creates a newMac
object.
-