internal byte[] GetCacheValue(IPropertySet containerValues)
        {
            if (!containerValues.ContainsKey(CacheValueLength))
            {
                return(null);
            }

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

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

            Array.Copy((byte[])containerValues[CacheValue + (segmentCount - 1)], 0, encryptedValue, (segmentCount - 1) * MaxCompositeValueLength, encyptedValueLength - (segmentCount - 1) * MaxCompositeValueLength);
            return(_cryptographyManager.Decrypt(encryptedValue));
        }
예제 #2
0
        private byte[] ReadAndDecrypt(IStorageFile cacheFile)
        {
            IBuffer buffer = FileIO.ReadBufferAsync(cacheFile).AsTask().GetAwaiter().GetResult();

            if (buffer.Length != 0)
            {
                byte[] encryptedblob = buffer.ToArray();
                return(_cryptographyManager.Decrypt(encryptedblob));
            }

            return(null);
        }
        private void OnBeforeAccessAsync(TokenCacheNotificationArgs args)
        {
            var cacheFile = ApplicationData.Current.LocalFolder.TryGetItemAsync(CacheFileName)
                            .AsTask().GetAwaiter().GetResult() as IStorageFile;

            if (cacheFile != null)
            {
                IBuffer buffer = FileIO.ReadBufferAsync(cacheFile).AsTask().GetAwaiter().GetResult();

                if (buffer.Length != 0)
                {
                    byte[] encryptedblob = buffer.ToArray();
                    byte[] decryptedBlob = _cryptographyManager.Decrypt(encryptedblob);
                    args.TokenCache.DeserializeMsalV3(decryptedBlob);
                }
            }
        }