예제 #1
0
        public static byte[][] Parse(string token)
        {
            if (token == null)
            {
                throw new ArgumentNullException(nameof(token));
            }

            string[] parts = token.Split('.');

            var result = new byte[parts.Length][];

            for (int i = 0; i < parts.Length; i++)
            {
                result[i] = Base64Url.Decode(parts[i]);
            }

            return(result);
        }
예제 #2
0
        private static JweToken ParseJson(IDictionary <string, object> json)
        {
            var recipients = new List <JweRecipient>();

            IEnumerable _recipients = Dictionaries.Get <IEnumerable>(json, "recipients");

            if (_recipients != null)
            {
                foreach (IDictionary <string, object> recipient in _recipients)
                {
                    byte[] encryptedCek = Base64Url.Decode(Dictionaries.Get <string>(recipient, "encrypted_key"));
                    recipients.Add(new JweRecipient(encryptedCek, Dictionaries.Get <IDictionary <string, object> >(recipient, "header")));
                }
            }
            else if (recipients.Count == 0)
            {
                byte[] encryptedCek = Base64Url.Decode(Dictionaries.Get <string>(json, "encrypted_key"));
                recipients.Add(new JweRecipient(encryptedCek, new Dictionary <string, object> {
                    { "alg", "A256KW" }
                }));
                //recipients.Add(new JweRecipient(encryptedCek, Dictionaries.Get<IDictionary<string, object>>(json, "header")));
            }

            var _protected = Dictionaries.Get <string>(json, "protected");
            var _aad       = Dictionaries.Get <string>(json, "aad");

            return(new JweToken(
                       protectedHeaderBytes: _protected == null ? new byte[0] : Base64Url.Decode(_protected),
                       unprotectedHeader: Dictionaries.Get <IDictionary <string, object> >(json, "unprotected"),
                       aad: _aad == null ? null : Base64Url.Decode(_aad),
                       recipients: recipients,
                       iv: Base64Url.Decode(Dictionaries.Get <string>(json, "iv")),
                       ciphertext: Base64Url.Decode(Dictionaries.Get <string>(json, "ciphertext")),
                       authTag: Base64Url.Decode(Dictionaries.Get <string>(json, "tag")),
                       encoding: SerializationMode.Json));
        }