internal void SetCacheValue(IPropertySet containerValues, byte[] value)
        {
            byte[] encryptedValue = _cryptographyManager.Encrypt(value);
            containerValues[CacheValueLength] = encryptedValue.Length;
            if (encryptedValue.Length == 0)
            {
                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;
            }
        }
        private void OnAfterAccessAsync(TokenCacheNotificationArgs args)
        {
            if (args.HasStateChanged)
            {
                StorageFile cacheFile = ApplicationData.Current.LocalFolder.CreateFileAsync(
                    CacheFileName,
                    CreationCollisionOption.ReplaceExisting).AsTask().GetAwaiter().GetResult();

                byte[] blob          = args.TokenCache.SerializeMsalV3();
                byte[] encryptedBlob = _cryptographyManager.Encrypt(blob);

                FileIO.WriteBytesAsync(cacheFile, encryptedBlob).GetAwaiter().GetResult();
            }
        }
Beispiel #3
0
        internal void SetCacheValue(ApplicationDataCompositeValue composite, string stringValue)
        {
            byte[] encryptedValue = _cryptographyManager.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;
        }