/// <summary>
        /// Create signature from plain object
        /// </summary>
        /// <param name="privateKey">Private key</param>
        /// <param name="data">Object</param>
        /// <param name="ignoreFields">Ignore some properties</param>
        /// <returns></returns>
        public static string CreateSignatureFromObject(string privateKey, object data, List <string> ignoreFields, HashType hashType = HashType.SHA256)
        {
            var ignoreFieldsList = new List <string>();

            if (ignoreFields != null)
            {
                ignoreFieldsList = ignoreFields;
            }
            var message = string.Empty;

            foreach (var propertyInfo in data.GetType().GetProperties().OrderBy(p => p.Name))
            {
                if (ignoreFieldsList.Contains(propertyInfo.Name) == false)
                {
                    var propertyValue = propertyInfo.GetValue(data);

                    if (propertyInfo.PropertyType == typeof(bool))
                    {
                        propertyValue = propertyValue.ToString().ToLowerInvariant();
                    }

                    if (propertyValue != null)
                    {
                        message = string.Concat(message, propertyInfo.Name, propertyValue.ToString());
                    }
                }
            }

            var signature = SignatureUtility.Hash(privateKey, message, hashType);

            return(signature);
        }
        /// <summary>
        /// Validate signature from plain object
        /// </summary>
        /// <param name="signature">Signature</param>
        /// <param name="privateKey">Private key</param>
        /// <param name="data">Object</param>
        /// <returns></returns>
        public static bool ValidateSignatureFromObject(this string signature, string privateKey, object data, HashType hashType = HashType.SHA256)
        {
            string ignoredField = null;

            return(SignatureUtility.ValidateSignatureFromObject(signature, privateKey, data, ignoredField, hashType));
        }
 /// <summary>
 /// Create signature from string
 /// </summary>
 /// <param name="privateKey"></param>
 /// <param name="message"></param>
 /// <returns></returns>
 public static string CreateSignature(string privateKey, string message, HashType hashType = HashType.SHA256)
 {
     return(SignatureUtility.Hash(privateKey, message, hashType));
 }
        /// <summary>
        /// Create signature plain object
        /// </summary>
        /// <param name="privateKey">Private key</param>
        /// <param name="data">Object</param>
        /// <returns></returns>
        public static string CreateSignatureFromObject(string privateKey, object data, HashType hashType = HashType.SHA256)
        {
            string ignoredField = null;

            return(SignatureUtility.CreateSignatureFromObject(privateKey, data, ignoredField, hashType));
        }
 /// <summary>
 /// Create signature plain object
 /// </summary>
 /// <param name="privateKey">Private key</param>
 /// <param name="data">Object</param>
 /// <param name="ignoreField">Ignore a property</param>
 /// <returns></returns>
 public static string CreateSignatureFromObject(string privateKey, object data, string ignoreField, HashType hashType = HashType.SHA256)
 {
     return(SignatureUtility.CreateSignatureFromObject(privateKey, data, SignatureUtility.GenerateIgnoreFields(ignoreField), hashType));
 }
        /// <summary>
        /// Validate signature from plain object
        /// </summary>
        /// <param name="signature">Signature</param>
        /// <param name="privateKey">Private key</param>
        /// <param name="data">Object</param>
        /// <param name="ignoreFields">Ignore some properties</param>
        /// <returns></returns>
        public static bool ValidateSignatureFromObject(this string signature, string privateKey, object data, List <string> ignoreFields, HashType hashType = HashType.SHA256)
        {
            var computedSignature = SignatureUtility.CreateSignatureFromObject(privateKey, data, ignoreFields, hashType);

            return(string.Compare(computedSignature, signature, StringComparison.OrdinalIgnoreCase) == 0);
        }
        /// <summary>
        /// Validate signature from string
        /// </summary>
        /// <param name="signature">Signature</param>
        /// <param name="privateKey">Private key</param>
        /// <param name="message">Content</param>
        /// <returns></returns>
        public static bool ValidateSignature(this string signature, string privateKey, string message, HashType hashType = HashType.SHA256)
        {
            var computedSignature = SignatureUtility.Hash(privateKey, message, hashType);

            return(string.Compare(computedSignature, signature, StringComparison.OrdinalIgnoreCase) == 0);
        }
Beispiel #8
0
        /// <summary>
        /// Validate signature from plain object
        /// </summary>
        /// <param name="signature">Signature</param>
        /// <param name="privateKey">Private key</param>
        /// <param name="data">Object</param>
        /// <returns></returns>
        public static bool ValidateSignatureFromObject(string signature, string privateKey, object data)
        {
            string ignoredField = null;

            return(SignatureUtility.ValidateSignatureFromObject(signature, privateKey, data, ignoredField));
        }
 /// <summary>
 /// Validate signature from plain object
 /// </summary>
 /// <param name="signature">Signature</param>
 /// <param name="privateKey">Private key</param>
 /// <param name="data">Object</param>
 /// <param name="ignoreField">Ignore a properties</param>
 /// <returns></returns>
 public static bool ValidateSignatureFromObject(this string signature, string privateKey, object data, string ignoreFields, HashType hashType = HashType.SHA256)
 {
     return(SignatureUtility.ValidateSignatureFromObject(signature, privateKey, data, SignatureUtility.GenerateIgnoreFields(ignoreFields), hashType));
 }
Beispiel #10
0
 /// <summary>
 /// Create signature from string
 /// </summary>
 /// <param name="privateKey"></param>
 /// <param name="message"></param>
 /// <returns></returns>
 public static string CreateSignature(string privateKey, string message)
 {
     return(SignatureUtility.Hash(privateKey, message));
 }
Beispiel #11
0
 /// <summary>
 /// Create signature plain object
 /// </summary>
 /// <param name="privateKey">Private key</param>
 /// <param name="data">Object</param>
 /// <param name="ignoreField">Ignore a property</param>
 /// <returns></returns>
 public static string CreateSignatureFromObject(string privateKey, object data, string ignoreField)
 {
     return(SignatureUtility.CreateSignatureFromObject(privateKey, data, SignatureUtility.GenerateIgnoreFields(ignoreField)));
 }
Beispiel #12
0
        /// <summary>
        /// Create signature plain object
        /// </summary>
        /// <param name="privateKey">Private key</param>
        /// <param name="data">Object</param>
        /// <returns></returns>
        public static string CreateSignatureFromObject(string privateKey, object data)
        {
            string ignoredField = null;

            return(SignatureUtility.CreateSignatureFromObject(privateKey, data, ignoredField));
        }
Beispiel #13
0
 /// <summary>
 /// Validate signature from string
 /// </summary>
 /// <param name="signature">Signature</param>
 /// <param name="privateKey">Private key</param>
 /// <param name="message">Content</param>
 /// <returns></returns>
 public static bool ValidateSignature(string signature, string privateKey, string message)
 {
     return(signature == SignatureUtility.CreateSignature(privateKey, message));
 }
Beispiel #14
0
 /// <summary>
 /// Validate signature from plain object
 /// </summary>
 /// <param name="signature">Signature</param>
 /// <param name="privateKey">Private key</param>
 /// <param name="data">Object</param>
 /// <param name="ignoreField">Ignore a properties</param>
 /// <returns></returns>
 public static bool ValidateSignatureFromObject(string signature, string privateKey, object data, string ignoreFields)
 {
     return(SignatureUtility.ValidateSignatureFromObject(signature, privateKey, data, SignatureUtility.GenerateIgnoreFields(ignoreFields)));
 }