示例#1
0
        internal static PasetoInstance ParsePayload(string payload, string footer, bool validateTimes = true)
        {
            IDictionary <string, object> payloadJson;

            try
            {
                payloadJson = SimpleJson.DeserializeObject(payload) as IDictionary <string, object>;
                if (payloadJson == null)
                {
                    return(null);
                }
            }
            catch (SerializationException e)
            {
                throw new PasetoFormatException("Serialization error. " + e);
            }

            var footerJson = footer == "" ? null : SimpleJson.DeserializeObject(footer) as IDictionary <string, object>;

            var pasetoInstance = new PasetoInstance(payloadJson)
            {
                Footer = footerJson
            };

            if (validateTimes)
            {
                if (pasetoInstance.Expiration != null && pasetoInstance.Expiration.Value < DateTime.UtcNow)
                {
                    return(null);
                }

                if (pasetoInstance.NotBefore != null && pasetoInstance.NotBefore.Value > DateTime.UtcNow)
                {
                    return(null);
                }
            }

            return(pasetoInstance);
        }
示例#2
0
 public static string Encrypt(byte[] symmetricKey, PasetoInstance payload, byte[] nonce = null) =>
 EncryptBytes(symmetricKey, Encoding.UTF8.GetBytes(SimpleJson.SerializeObject(payload.ToDictionary())), SimpleJson.SerializeObject(payload.Footer), nonce);
示例#3
0
 public static string Sign(byte[] publicKey, byte[] privateKey, PasetoInstance claims)
 {
     return(SignBytes(publicKey, privateKey, Encoding.UTF8.GetBytes(SimpleJson.SerializeObject(claims.ToDictionary())), SimpleJson.SerializeObject(claims.Footer)));
 }