/// <summary> /// Unprotected the JWT payload (middle) segment with the default public algorithm /// </summary> /// <param name="algorithm">App chassis sec manager</param> /// <param name="jwt">JSON web token: `header.payload.hash`</param> /// <returns>JsonDataMap filled with payload/claims or null if message is corrupt/not authentic</returns> public static JsonDataMap UnprotectJWTPayload(this ICryptoMessageAlgorithm algorithm, string jwt) { var raw = algorithm.UnprotectFromString(jwt); if (raw == null) { return(null); } using (var ms = new MemoryStream(raw)) { try { return(JsonReader.DeserializeDataObject(ms, UTF8_NO_BOM, true) as JsonDataMap); } catch { return(null);//corrupted message } } }
/// <summary> /// Tries to decode/unprotect the message, returning null if the protectedMessage does not represent a valid protected message /// </summary> /// <param name="algorithm">Algorithm to use</param> /// <param name="protectedMessage">Protected message content encoded as string</param> /// <returns>Unprotected/decoded message or null if the protectedMessage is not valid</returns> public static IJsonDataObject UnprotectObject(this ICryptoMessageAlgorithm algorithm, string protectedMessage) { var raw = algorithm.UnprotectFromString(protectedMessage); if (raw == null) { return(null); } using (var ms = new MemoryStream(raw)) { try { return(JsonReader.DeserializeDataObject(ms, UTF8_NO_BOM, true)); } catch { return(null);//corrupted message } } }