// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
namespace Microsoft.AspNet.Security.DataProtection
{
///
/// Helper class to populate buffers with cryptographically random data.
///
public static class CryptRand
{
///
/// Populates a buffer with cryptographically random data.
///
/// The buffer to populate.
public static unsafe void FillBuffer(ArraySegment buffer)
{
// the ArraySegment<> ctor performs bounds checking
var unused = new ArraySegment(buffer.Array, buffer.Offset, buffer.Count);
if (buffer.Count != 0)
{
fixed (byte* pBuffer = &buffer.Array[buffer.Offset])
{
BCryptUtil.GenRandom(pBuffer, buffer.Count);
}
}
}
}
}