Inheritance: ICryptographyHelper
Ejemplo n.º 1
0
        public void SaveRefreshToken(string cacheKey, string item)
        {
            ApplicationDataCompositeValue composite = new ApplicationDataCompositeValue();

            SetCacheValue(composite, item);
            _refreshTokenContainer.Values[CryptographyHelper.CreateBase64UrlEncodedSha256Hash(cacheKey)] = composite;
        }
        public void DeleteRefreshToken(TokenCacheKey key)
        {
            CryptographyHelper helper = new CryptographyHelper();
            string             hashed = helper.CreateSha256Hash(key.ToString());

            _refreshTokenContainer.Values.Remove(hashed);
        }
Ejemplo n.º 3
0
        internal static byte[] GetCacheValue(ApplicationDataCompositeValue composite)
        {
            if (!composite.ContainsKey(CacheValueLength))
            {
                return(null);
            }

            int encyptedValueLength = (int)composite[CacheValueLength];
            int segmentCount        = (int)composite[CacheValueSegmentCount];

            byte[] encryptedValue = new byte[encyptedValueLength];
            if (segmentCount == 1)
            {
                encryptedValue = (byte[])composite[CacheValue + 0];
            }
            else
            {
                for (int i = 0; i < segmentCount - 1; i++)
                {
                    Array.Copy((byte[])composite[CacheValue + i], 0, encryptedValue, i * MaxCompositeValueLength,
                               MaxCompositeValueLength);
                }
            }

            Array.Copy((byte[])composite[CacheValue + (segmentCount - 1)], 0, encryptedValue,
                       (segmentCount - 1) * MaxCompositeValueLength,
                       encyptedValueLength - (segmentCount - 1) * MaxCompositeValueLength);

            return(CryptographyHelper.Decrypt(encryptedValue));
        }
Ejemplo n.º 4
0
        internal static void SetCacheValue(IPropertySet containerValues, byte[] value)
        {
            byte[] encryptedValue = CryptographyHelper.Encrypt(value);
            containerValues[CacheValueLength] = encryptedValue.Length;
            if (encryptedValue == null)
            {
                containerValues[CacheValueSegmentCount] = 1;
                containerValues[CacheValue + 0]         = null;
            }
            else
            {
                int    segmentCount = (encryptedValue.Length / MaxCompositeValueLength) + ((encryptedValue.Length % MaxCompositeValueLength == 0) ? 0 : 1);
                byte[] subValue     = new byte[MaxCompositeValueLength];
                for (int i = 0; i < segmentCount - 1; i++)
                {
                    Array.Copy(encryptedValue, i * MaxCompositeValueLength, subValue, 0, MaxCompositeValueLength);
                    containerValues[CacheValue + i] = subValue;
                }

                int copiedLength = (segmentCount - 1) * MaxCompositeValueLength;
                Array.Copy(encryptedValue, copiedLength, subValue, 0, encryptedValue.Length - copiedLength);
                containerValues[CacheValue + (segmentCount - 1)] = subValue;
                containerValues[CacheValueSegmentCount]          = segmentCount;
            }
        }
        public void SaveRefreshToken(RefreshTokenCacheItem refreshTokenItem)
        {
            CryptographyHelper            helper          = new CryptographyHelper();
            string                        hashed          = helper.CreateSha256Hash(refreshTokenItem.GetTokenCacheKey().ToString());
            ApplicationDataCompositeValue composite       = new ApplicationDataCompositeValue();
            string                        serializedToken = JsonHelper.SerializeToJson(refreshTokenItem);

            SetCacheValue(composite, serializedToken);
            _refreshTokenContainer.Values[hashed] = composite;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Constructor to create credential with assertion and assertionType
        /// </summary>
        /// <param name="assertion">Assertion representing the user.</param>
        /// <param name="assertionType">Type of the assertion representing the user.</param>
        public UserAssertion(string assertion, string assertionType)
        {
            if (string.IsNullOrWhiteSpace(assertion))
            {
                throw new ArgumentNullException(nameof(assertion));
            }

            if (string.IsNullOrWhiteSpace(assertionType))
            {
                throw new ArgumentNullException(nameof(assertionType));
            }

            AssertionType = assertionType;
            Assertion     = assertion;
            AssertionHash =
                CryptographyHelper.CreateBase64UrlEncodedSha256Hash(Assertion);
        }
Ejemplo n.º 7
0
        internal static void SetCacheValue(ApplicationDataCompositeValue composite, string stringValue)
        {
            byte[] encryptedValue = CryptographyHelper.Encrypt(stringValue.ToByteArray());
            composite[CacheValueLength] = encryptedValue.Length;

            int segmentCount = (encryptedValue.Length / MaxCompositeValueLength) +
                               ((encryptedValue.Length % MaxCompositeValueLength == 0) ? 0 : 1);

            byte[] subValue = new byte[MaxCompositeValueLength];
            for (int i = 0; i < segmentCount - 1; i++)
            {
                Array.Copy(encryptedValue, i * MaxCompositeValueLength, subValue, 0, MaxCompositeValueLength);
                composite[CacheValue + i] = subValue;
            }

            int copiedLength = (segmentCount - 1) * MaxCompositeValueLength;

            Array.Copy(encryptedValue, copiedLength, subValue, 0, encryptedValue.Length - copiedLength);
            composite[CacheValue + (segmentCount - 1)] = subValue;
            composite[CacheValueSegmentCount]          = segmentCount;
        }
        /// <summary>
        ///
        /// </summary>
        public byte[] Sign(string message)
        {
            CryptographyHelper helper = new CryptographyHelper();

            return(helper.SignWithCertificate(message, this.Certificate));
        }
Ejemplo n.º 9
0
 public void DeleteRefreshToken(string cacheKey)
 {
     _refreshTokenContainer.Values.Remove(CryptographyHelper.CreateBase64UrlEncodedSha256Hash(cacheKey));
 }
Ejemplo n.º 10
0
 public string GetRefreshToken(string refreshTokenKey)
 {
     return(MsalHelpers.ByteArrayToString(
                GetCacheValue((ApplicationDataCompositeValue)_refreshTokenContainer.Values[
                                  CryptographyHelper.CreateBase64UrlEncodedSha256Hash(refreshTokenKey)])));
 }
 /// <summary>
 /// 
 /// </summary>
 public byte[] Sign(string message)
 {
     CryptographyHelper helper = new CryptographyHelper();
     return helper.SignWithCertificate(message, this.Certificate);
 }
Ejemplo n.º 12
0
        internal byte[] Sign(string message)
        {
            CryptographyHelper helper = new CryptographyHelper();

            return(helper.SignWithCertificate(message, Certificate));
        }