예제 #1
0
        /// <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, ArraySegment <byte> jwt)
        {
            var raw = algorithm.Unprotect(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
                }
            }
        }
예제 #2
0
        /// <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</param>
        /// <returns>Unprotected/decoded message or null if the protectedMessage is not valid</returns>
        public static IJsonDataObject Unprotect(this ICryptoMessageAlgorithm algorithm, ArraySegment <byte> protectedMessage)
        {
            var raw = algorithm.Unprotect(protectedMessage);

            if (raw == null)
            {
                return(null);
            }
            using (var ms = new MemoryStream(raw))
            {
                try
                {
                    return(JsonReader.DeserializeDataObject(ms, Encoding.UTF8, true));
                }
                catch
                {
                    return(null);//corrupted message
                }
            }
        }