本文整理汇总了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);
}
示例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());
}
示例3: HashData
public IBuffer HashData (IBuffer data)
{
if (data == null)
return new byte[HashLength].AsBuffer();
return this.context.ComputeHash (data.AsStream()).AsBuffer();
}
示例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;
}
示例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;
}
示例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();
});
}
}
示例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();
}
}
示例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);
}
示例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();
}
}
示例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
示例11: ReadAsync
public IAsyncOperationWithProgress<IBuffer, uint> ReadAsync (IBuffer buffer, uint count, InputStreamOptions options)
{
if (disposed)
throw new ObjectDisposedException(GetType().FullName);
throw new NotImplementedException();
}
示例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;
}
示例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);
}
示例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);
}
}
示例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;
}