20 if (c ==
'+') c =
'-';
21 else if (c ==
'/') c =
'_';
23 while (!s.empty() && s.back() ==
'=') {
33 if (c ==
'-') c =
'+';
34 else if (c ==
'_') c =
'/';
36 while (s.length() % 4 != 0) {
44 m_header.Add(
"alg",
"HS256");
45 m_header.Add(
"typ",
"JWT");
95 m_rawTokenWithoutSignature = headerB64Url +
"." + payloadB64Url;
97 return m_rawTokenWithoutSignature +
"." + m_signature;
117 pToken->m_rawTokenWithoutSignature = parts[0] +
"." + parts[1];
118 pToken->m_signature = parts[2];
126 if (m_rawTokenWithoutSignature.IsEmpty() || m_signature.IsEmpty()) {
131 Array<char> tokenBytes(m_rawTokenWithoutSignature.GetLength());
132 std::memcpy(tokenBytes.
GetData(), m_rawTokenWithoutSignature.GetRawString(), m_rawTokenWithoutSignature.GetLength());
142 return m_signature == expectedSignature;
Defines the exception thrown when an invalid argument is provided to a method.
Converts a base data type to another base data type, and encodes/decodes Base64 data.
Hash-based Message Authentication Code using SHA-256 per RFC 2104.
JSON Web Token (JWT) representation and cryptographic operations per RFC 7519.
Provides functionality to serialize objects to JSON strings and deserialize JSON strings into objects...
ArgumentException(const String &sMessage)
Initializes a new instance of the ArgumentException class with a specified error message.
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
int GetLength() const
Gets the total number of elements in all dimensions of the Array.
T * GetData()
Gets a pointer to the contiguous internal element buffer.
Represents a collection of keys and values.
static Array< char > FromBase64String(const String &s)
static String ToBase64String(const Array< char > &inArray)
String GetSignature() const
Gets the cryptographic signature string component of the token.
Collections::Generic::Dictionary< String, String > & GetPayload()
Gets a mutable reference to the payload claims dictionary.
String CreateToken(const String &secretKey)
Encodes and cryptographically signs the token using HMAC-SHA256.
static SmartPointer< JWTToken > Parse(const String &tokenStr)
Parses a serialized compact JWT string into a JWTToken instance.
JWTToken()
Initializes a new instance of the JWTToken class with default header values.
Collections::Generic::Dictionary< String, String > & GetHeader()
Gets a mutable reference to the JOSE header dictionary.
bool Verify(const String &secretKey) const
Verifies the token signature against a specified secret key.
Array< char > ComputeHash(const Array< char > &buffer)
Computes the HMAC hash value for the specified byte array.
A unified smart pointer that supports both unique and shared ownership semantics.
static SmartPointer< T > NewShared()
Creates a Shared SmartPointer, default constructing T.
Represents text as a sequence of UTF-8 code units with culture-invariant operations.
String()
Initializes a new instance of the String class to an empty string.
const char * GetRawString() const
Array< String > Split(char chSeparator) const
static T Deserialize(const String &sJson)
Parses the text representing a single JSON value into an instance of the type specified by a generic ...
static String Serialize(const T &value)
Converts the value of a type specified by a generic type parameter into a JSON string.
static String EncodeDictToBase64Url(const Collections::Generic::Dictionary< String, String > &dict)
static Collections::Generic::Dictionary< String, String > DecodeBase64UrlToDict(const String &b64url)
static String Base64ToBase64Url(const String &base64)
static String ComputeJwtSignature(const String &rawToken, const String &secretKey)
static String Base64UrlToBase64(const String &base64Url)