Package net.solarnetwork.security
Class AuthorizationUtils
java.lang.Object
net.solarnetwork.security.AuthorizationUtils
Utilities for authorization.
- Since:
- 1.78
- Version:
- 1.0
- Author:
- matt
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final DateTimeFormatterDate formatter that formats or parses a date without an offset, such as 20111203, in the GMT time zone.static final DateTimeFormatterDate formatter that formats or parses timestamp values in the HTTP Date header format, similar to RFC 1123 but with 2-digit day values used always.static final DateTimeFormatterDate formatter that formats or parses timestamp values in the ISO 8601 condensed timestamp form with second resolution, in theGMTtime zone.static final StringThe hex-encoded SHA256 value of an empty string.static final StringTheX-SN-Dateheader name. -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]computeHmacSha256(byte[] key, String msg) Compute a HMAC-SHA256 digest from a byte array password.static byte[]computeHmacSha256(String key, String msg) Compute a HMAC-SHA256 digest from UTF-8 string values.static StringcomputeHmacSha256Hex(byte[] signingKey, String signatureData) Compute an HMAC SHA256 hex-encoded signature value from a signing key and signature data.static byte[]computeMacDigest(byte[] key, byte[] msg, String alg) Compute a MAC digest.static byte[]computeMacDigest(String secret, String msg, String alg) Compute a MAC digest from UTF-8 string values.static StringsemiColonDelimitedList(String[] list) Format a string array into a semicolon delimited string.static StringuriEncode(CharSequence input) Formal implementation of "uri encoding" using UTF-8 encoding for SolarNetwork authentication.
-
Field Details
-
SN_DATE_HEADER
TheX-SN-Dateheader name.- See Also:
-
EMPTY_STRING_SHA256_HEX
The hex-encoded SHA256 value of an empty string. -
AUTHORIZATION_DATE_FORMATTER
Date formatter that formats or parses a date without an offset, such as 20111203, in the GMT time zone. -
AUTHORIZATION_DATE_HEADER_FORMATTER
Date formatter that formats or parses timestamp values in the HTTP Date header format, similar to RFC 1123 but with 2-digit day values used always.An example of this date format is Fri, 13 Aug 2021 13:55:12 GMT.
-
AUTHORIZATION_TIMESTAMP_FORMATTER
Date formatter that formats or parses timestamp values in the ISO 8601 condensed timestamp form with second resolution, in theGMTtime zone.An example of this date format is 20210813T135512Z.
-
-
Method Details
-
computeHmacSha256
Compute a HMAC-SHA256 digest from UTF-8 string values.- Parameters:
key- the key to sign the digest with, which is assumed to be a UTF-8 encoded string.msg- the message content to sign, which is assumed to be a UTF-8 encoded string.- Returns:
- the computed digest
- Throws:
SecurityException- if the strings cannot be interpreted as UTF-8 orHmacSHA256is not supported by the runtime security provider
-
computeHmacSha256
Compute a HMAC-SHA256 digest from a byte array password.- Parameters:
key- The key to sign the digest with.msg- the message content to sign, which is assumed to be a UTF-8 encoded string- Returns:
- the computed digest
- Throws:
SecurityException- if the strings cannot be interpreted as UTF-8 or HmacSHA256 is not supported by the runtime security provider
-
computeMacDigest
Compute a MAC digest from UTF-8 string values.- Parameters:
secret- the secret to sign the digest with, which is assumed to be a UTF-8 encoded string.msg- the message content to sign, which is assumed to be a UTF-8 encoded stringalg- the MAC algorithm to use, which must be supported by the runtime security provider- Returns:
- the computed digest
- Throws:
SecurityException- if the strings cannot be interpreted as UTF-8 oralgis not supported by the runtime security provider
-
computeMacDigest
Compute a MAC digest.- Parameters:
key- the key to sign the digest withmsg- the message content to signalg- the MAC algorithm to use, which must be supported by the runtime security provider- Returns:
- the computed digest
- Throws:
SecurityException- if the strings cannot be interpreted as UTF-8 oralgis not supported by the runtime security provider
-
computeHmacSha256Hex
Compute an HMAC SHA256 hex-encoded signature value from a signing key and signature data.- Parameters:
signingKey- the signing keysignatureData- the signature data- Returns:
- the hex-encoded signature value
-
uriEncode
Formal implementation of "uri encoding" using UTF-8 encoding for SolarNetwork authentication.- Parameters:
input- the text input to encode- Returns:
- the URI escaped string
-
semiColonDelimitedList
Format a string array into a semicolon delimited string.- Parameters:
list- the list for format- Returns:
- the delimited list
-