當前位置: 首頁>>代碼示例>>C#>>正文


C# Streams.IBuffer類代碼示例

本文整理匯總了C#中Windows.Storage.Streams.IBuffer的典型用法代碼示例。如果您正苦於以下問題:C# IBuffer類的具體用法?C# IBuffer怎麽用?C# IBuffer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


IBuffer類屬於Windows.Storage.Streams命名空間,在下文中一共展示了IBuffer類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Rc4RandomGenerator

        public Rc4RandomGenerator(IBuffer key)
        {
            if (key == null)
                throw new ArgumentNullException("key");
            
            _state = new byte[256];
            var keyLength = key.Length;

            for (uint w = 0; w < 256; ++w)
                _state[w] = (byte)w;

            unchecked
            {
                byte j = 0;
                uint keyIndex = 0;

                for (uint w = 0; w < 256; ++w) // Key setup
                {
                    j += (byte)(_state[w] + key.GetByte(keyIndex));

                    var temp = _state[0];
                    _state[0] = _state[j];
                    _state[j] = temp;

                    ++keyIndex;
                    if (keyIndex >= keyLength)
                        keyIndex = 0;
                }
            }

            GetRandomBytes(512);
        }
開發者ID:Confuset,項目名稱:7Pass-Remake,代碼行數:32,代碼來源:Rc4RandomGenerator.cs

示例2: EncodeToBase64String

		/// <summary>
		/// Encodes a buffer to a base64 string.
		/// </summary>
		/// <param name="buffer">Input buffer.</param>
		/// <returns>Base64-encoded output string.</returns>
		public static string EncodeToBase64String( IBuffer buffer )
		{
			if (buffer == null)
				throw new ArgumentNullException("buffer");

			return Convert.ToBase64String(buffer.ToArray());
		}
開發者ID:jvlppm,項目名稱:WinRT.NET,代碼行數:12,代碼來源:CryptographicBuffer.cs

示例3: HashData

		public IBuffer HashData (IBuffer data)
		{
			if (data == null)
				return new byte[HashLength].AsBuffer();

			return this.context.ComputeHash (data.AsStream()).AsBuffer();
		}
開發者ID:ermau,項目名稱:WinRT.NET,代碼行數:7,代碼來源:HashAlgorithmProvider.cs

示例4: Read

	uint Read(IBuffer buffer, uint offset, uint count)
	{
		if (this.needSeek) {
			if (this.position < 44)
				asap.Seek(0);
			else {
				ulong bytes = this.position - 44 & ~(BufferSize - 1UL);
				asap.SeekSample((int) (bytes / wavHeader[32]));
			}
			this.needSeek = false;
		}

		ulong left = this.size - this.position;
		if (count > left)
			count = (uint) left;
		if (this.position < 44UL) {
			uint n = Math.Min(44 - (uint) this.position, count);
			this.wavHeader.CopyTo((int) this.position, buffer, offset, (int) n);
			this.position += n;
			offset += n;
			count -= n;
		}
		while (count > 0) {
			int i = (int) this.position - 44 & BufferSize - 1;
			if (i == 0)
				asap.Generate(this.samples, BufferSize, ASAPSampleFormat.S16LE);
			uint n = Math.Min((uint) BufferSize - (uint) i, count);
			this.samples.CopyTo(i, buffer, offset, (int) n);
			this.position += n;
			offset += n;
			count -= n;
		}
		return offset;
	}
開發者ID:hudokkow,項目名稱:audiodecoder.asap,代碼行數:34,代碼來源:MetroASAP.cs

示例5: Decrypt

        /// <summary>
        /// Decrypts the specified input stream.
        /// </summary>
        /// <param name="input">The input stream.</param>
        /// <param name="masterKey">The master key.</param>
        /// <param name="masterSeed">The master seed.</param>
        /// <param name="encryptionIV">The encryption initialization vector.</param>
        /// <returns>The decrypted buffer.</returns>
        /// <exception cref="ArgumentNullException">
        /// The <paramref name="input"/>, <paramref name="masterSeed"/>, <paramref name="masterKey"/>
        /// and <paramref name="encryptionIV"/> cannot be <c>null</c>.
        /// </exception>
        public static async Task<IInputStream> Decrypt(IRandomAccessStream input,
            IBuffer masterKey, IBuffer masterSeed, IBuffer encryptionIV)
        {
            if (input == null) throw new ArgumentNullException("input");
            if (masterSeed == null) throw new ArgumentNullException("masterSeed");
            if (masterKey == null) throw new ArgumentNullException("masterKey");
            if (encryptionIV == null) throw new ArgumentNullException("encryptionIV");

            var sha = HashAlgorithmProvider
                .OpenAlgorithm(HashAlgorithmNames.Sha256)
                .CreateHash();

            sha.Append(masterSeed);
            sha.Append(masterKey);

            var seed = sha.GetValueAndReset();
            var aes = SymmetricKeyAlgorithmProvider
                .OpenAlgorithm(SymmetricAlgorithmNames.AesCbcPkcs7)
                .CreateSymmetricKey(seed);

            var buffer = WindowsRuntimeBuffer.Create(
                (int)(input.Size - input.Position));
            buffer = await input.ReadAsync(buffer, buffer.Capacity);
            buffer = CryptographicEngine.Decrypt(aes, buffer, encryptionIV);

            var stream = new InMemoryRandomAccessStream();
            await stream.WriteAsync(buffer);
            stream.Seek(0);

            return stream;
        }
開發者ID:Confuset,項目名稱:7Pass-Remake,代碼行數:43,代碼來源:FileFormat.cs

示例6: SaveToPicturesLibrary

        public void SaveToPicturesLibrary(IBuffer imageBuffer, [CallerMemberName] string fileName = "", [CallerFilePath]string callerFilePath = "")
        {
            fileName = Path.GetFileNameWithoutExtension(callerFilePath) + "_" + fileName;

            if (!Path.HasExtension(fileName))
            {
                fileName = Path.ChangeExtension(fileName, "jpg");
            }

            lock (m_lockObject)
            {
                if (m_isClosed)
                {
                    throw new InvalidOperationException("ImageResults closed, cannot queue more operations.");
                }

                m_saveTask = m_saveTask.ContinueWith(async _ =>
                {
                    m_stopwatch.Start();

                    var file = await m_folder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting).AsTask().ConfigureAwait(false);

                    await FileIO.WriteBufferAsync(file, imageBuffer).AsTask().ConfigureAwait(false);

                    m_stopwatch.Stop();

                });
            }
        }
開發者ID:nagyistoce,項目名稱:Lumia-Imaging-SDK-Extras,代碼行數:29,代碼來源:ImageResults.cs

示例7: GetNewFrameAndApplyEffect

        public async Task GetNewFrameAndApplyEffect(IBuffer frameBuffer, Size frameSize)
        {
            if (_semaphore.WaitOne(500))
            {
                var scanlineByteSize = (uint)frameSize.Width * 4; // 4 bytes per pixel in BGRA888 mode
                var bitmap = new Bitmap(frameSize, ColorMode.Bgra8888, scanlineByteSize, frameBuffer);

                try
                {
                    if (_blendEffect != null)
                    {
                        _blendEffect.GlobalAlpha = GlobalAlpha;

                        var renderer = new BitmapRenderer(_blendEffect, bitmap);
                        await renderer.RenderAsync();
                    }
                    else
                    {
                        var renderer = new BitmapRenderer(_cameraPreviewImageSource, bitmap);
                        await renderer.RenderAsync();
                    }
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine("RealtimeBlendDemo.GetNewFrameAndApplyEffect(): "
                        + ex.ToString());
                }

                _semaphore.Release();
            }
        }
開發者ID:roachhd,項目名稱:real-time-blend-demo,代碼行數:31,代碼來源:Effects.cs

示例8: Encrypt

        public static IBuffer Encrypt(IBuffer data,
                                            CryptographicKey key,
                                            out IBuffer iv,
                                            String AlgorithmName = null)
        {
            //declares
            var strAlgName = AlgorithmName != null ? AlgorithmName : DefaultAlgorithm;
            iv = null;

            // Open a symmetric algorithm provider for the specified algorithm. 
            var objAlg = SymmetricKeyAlgorithmProvider.OpenAlgorithm(strAlgName);

            // Determine whether the message length is a multiple of the block length.
            // This is not necessary for PKCS #7 algorithms which automatically pad the
            // message to an appropriate length.
            if (!strAlgName.Contains("PKCS7"))
            {
                if ((data.Length % objAlg.BlockLength) != 0)
                    throw new Exception("Message buffer length must be multiple of block length.");
            }

            // CBC algorithms require an initialization vector. Here, a random
            // number is used for the vector.
            if (strAlgName.Contains("CBC"))
                iv = CryptographicBuffer.GenerateRandom(objAlg.BlockLength);

            // Encrypt the data and return.
            return CryptographicEngine.Encrypt(key, data, iv);
        }
開發者ID:yodiwo,項目名稱:plegma,代碼行數:29,代碼來源:CryptoEngine.Universal.cs

示例9: GetNewFrameAndApplyEffect

        public async Task GetNewFrameAndApplyEffect(IBuffer frameBuffer, Size frameSize)
        {
            if (_semaphore.WaitOne(500))
            {
                var scanlineByteSize = (uint)frameSize.Width * 4; // 4 bytes per pixel in BGRA888 mode
                var bitmap = new Bitmap(frameSize, ColorMode.Bgra8888, scanlineByteSize, frameBuffer);

                if (_filterEffect != null)
                {
                    var renderer = new BitmapRenderer(_filterEffect, bitmap);
                    await renderer.RenderAsync();
                }
                else if (_customEffect != null)
                {
                    var renderer = new BitmapRenderer(_customEffect, bitmap);
                    await renderer.RenderAsync();
                }
                else
                {
                    var renderer = new BitmapRenderer(_cameraPreviewImageSource, bitmap);
                    await renderer.RenderAsync();
                }

                _semaphore.Release();
            }
        }
開發者ID:Rob-Kachmar,項目名稱:real-time-filter-demo,代碼行數:26,代碼來源:NokiaImagingSDKEffects.cs

示例10: ReadAsync_MemoryStream

        internal static IAsyncOperationWithProgress<IBuffer, UInt32> ReadAsync_MemoryStream(Stream stream, IBuffer buffer, UInt32 count)
        {
            Debug.Assert(stream != null);
            Debug.Assert(stream is SREMemoryStream);
            Debug.Assert(stream.CanRead);
            Debug.Assert(stream.CanSeek);
            Debug.Assert(buffer != null);
            Debug.Assert(buffer is IBufferByteAccess);
            Debug.Assert(0 <= count);
            Debug.Assert(count <= Int32.MaxValue);
            Debug.Assert(count <= buffer.Capacity);
            Contract.EndContractBlock();

            // We will return a different buffer to the user backed directly by the memory stream (avoids memory copy).
            // This is permitted by the WinRT stream contract.
            // The user specified buffer will not have any data put into it:
            buffer.Length = 0;

            SREMemoryStream memStream = stream as SREMemoryStream;
            Debug.Assert(memStream != null);

            try
            {
                IBuffer dataBuffer = memStream.GetWindowsRuntimeBuffer((Int32)memStream.Position, (Int32)count);
                if (dataBuffer.Length > 0)
                    memStream.Seek(dataBuffer.Length, SeekOrigin.Current);

                return AsyncInfo.CreateCompletedOperation<IBuffer, UInt32>(dataBuffer);
            }
            catch (Exception ex)
            {
                return AsyncInfo.CreateFaultedOperation<IBuffer, UInt32>(ex);
            }
        }  // ReadAsync_MemoryStream
開發者ID:dotnet,項目名稱:corefx,代碼行數:34,代碼來源:StreamOperationsImplementation.cs

示例11: ReadAsync

		public IAsyncOperationWithProgress<IBuffer, uint> ReadAsync (IBuffer buffer, uint count, InputStreamOptions options)
		{
			if (disposed)
				throw new ObjectDisposedException(GetType().FullName);

			throw new NotImplementedException();
		}
開發者ID:jvlppm,項目名稱:WinRT.NET,代碼行數:7,代碼來源:StreamToInputStreamAdapter.cs

示例12: CipherEncryption

        /// <summary>
        /// 對字符串依據指定的算法和密鑰進行加密,如果使用 CBC 算法,還需要初始化向量
        /// </summary>
        /// <param name="content">源字符串</param>
        /// <param name="strAlgName">加密算法</param>
        /// <param name="encoding">字符串編碼方式</param>
        /// <param name="key">密鑰</param>
        /// <param name="iniVec">CBC 初始化向量</param>
        /// <returns></returns>
        public static IBuffer CipherEncryption(string content, string strAlgName,
            BinaryStringEncoding encoding, CryptographicKey key, IBuffer iniVec = null)
        {
            // Create a buffer that contains the encoded message to be encrypted. 
            IBuffer buffContent = CryptographicBuffer.ConvertStringToBinary(content, encoding);

            // Open a symmetric algorithm provider for the specified algorithm. 
            SymmetricKeyAlgorithmProvider objAlg = SymmetricKeyAlgorithmProvider.OpenAlgorithm(strAlgName);

            // Determine whether the message length is a multiple of the block length.
            // This is not necessary for PKCS #7 algorithms which automatically pad the
            // message to an appropriate length.
            if (!strAlgName.Contains("PKCS7"))
            {
                if ((buffContent.Length % objAlg.BlockLength) != 0)
                {
                    throw new Exception("Message buffer length must be multiple of block length.");
                }
            }

            if (strAlgName.Contains("CBC") && iniVec == null)
            {
                throw new ArgumentException("Using CBC Encryption, initial vector must have value");
            }
            // Encrypt the data and return.
            IBuffer buffEncrypt = CryptographicEngine.Encrypt(key, buffContent, iniVec);
            return buffEncrypt;
        }
開發者ID:aurora-lzzp,項目名稱:Aurora-Weather,代碼行數:37,代碼來源:CryptoHelper.cs

示例13: PixelBufferInfo

 public PixelBufferInfo(IBuffer pixelBuffer)
 {
     this.pixelStream = WindowsRuntimeBufferExtensions.AsStream(pixelBuffer);
     this.Bytes = new byte[this.pixelStream.Length];
     this.pixelStream.Seek(0L, SeekOrigin.Begin);
     this.pixelStream.Read(this.Bytes, 0, this.Bytes.Length);
 }
開發者ID:vnktajay,項目名稱:Dewinter08142013,代碼行數:7,代碼來源:IBufferExtensions.cs

示例14: SetAsync

        public virtual async Task SetAsync(string key, IBuffer buffer, DateTime expires)
        {
            try
            {
                var names = key.Split('\\');
                var folder = rootFolder;

                for (int i = 0; i < names.Length - 1; i++)
                {
                    folder = await folder.CreateFolderAsync(names[i], CreationCollisionOption.OpenIfExists);
                }

                var file = await folder.CreateFileAsync(names[names.Length - 1], CreationCollisionOption.ReplaceExisting);
                await FileIO.WriteBufferAsync(file, buffer);

                // Use ImageProperties.DateTaken to store expiration date
                var imageProperties = await file.Properties.GetImagePropertiesAsync();
                imageProperties.DateTaken = expires;
                await imageProperties.SavePropertiesAsync();
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }
開發者ID:huoxudong125,項目名稱:XamlMapControl,代碼行數:25,代碼來源:ImageFileCache.cs

示例15: DecrypMode

    /// <summary>
    /// Дешифрования текст
    /// </summary>
    /// <param name="SourceText">Исходный (шифрованный) текст</param>
    /// <param name="InputKey">Ключ шифрования</param>
    /// <param name="AlgorytmName">Имя алгоритма дешифрования</param>
    /// 
    /// <returns>Расшифрованный (открытый) текст</returns>
    public string DecrypMode(string SourceText, string InputKey, string AlgorytmName, string IV, string KeySize)
    {
        SymmetricKeyAlgorithmProvider Algorithm = SymmetricKeyAlgorithmProvider.OpenAlgorithm(AlgorytmName);
        IBuffer KeyBuffer = CryptographicBuffer.ConvertStringToBinary(InputKey, BinaryStringEncoding.Utf16LE);
        IBuffer saltBuffer = CryptographicBuffer.ConvertStringToBinary("[email protected]:Annc!6002mz", BinaryStringEncoding.Utf16LE);
        //CryptoKey = Algorithm.CreateSymmetricKey(keymaterial);

        KeyDerivationAlgorithmProvider keyDerivationProvider = KeyDerivationAlgorithmProvider.OpenAlgorithm(KeyDerivationAlgorithmNames.Pbkdf2Sha512);

        KeyDerivationParameters pbkdf2Parms = KeyDerivationParameters.BuildForPbkdf2(saltBuffer, 10000);

        CryptographicKey keyOriginal = keyDerivationProvider.CreateKey(KeyBuffer);

        IBuffer keyMaterial = CryptographicEngine.DeriveKeyMaterial(keyOriginal, pbkdf2Parms,Convert.ToUInt32(KeySize)/8);

          //  string test= CryptographicBuffer.ConvertBinaryToString(BinaryStringEncoding.Utf16LE, keyMaterial);

        CryptoKey = Algorithm.CreateSymmetricKey(keyMaterial);

        if (AlgorytmName.Contains("CBC"))
        {
            IVBuffer = CryptographicBuffer.ConvertStringToBinary(IV, BinaryStringEncoding.Utf16LE);
        }
        // Set the data to encrypt.
           SourceTextBuffer = CryptographicBuffer.DecodeFromBase64String(SourceText);

        // Decrypt
        DecryptBuffer = Windows.Security.Cryptography.Core.CryptographicEngine.Decrypt(CryptoKey, SourceTextBuffer, IVBuffer);
        DecryptTextOutput = CryptographicBuffer.ConvertBinaryToString(BinaryStringEncoding.Utf16LE, DecryptBuffer);//Надо думать над реализацией Base64

        return DecryptTextOutput;
    }
開發者ID:rachmann,項目名稱:CryptoBox,代碼行數:40,代碼來源:Cryptobox.cs


注:本文中的Windows.Storage.Streams.IBuffer類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。