Exemple #1
0
    internal static unsafe void GetRandomBytes(byte *buffer, int length)
    {
        Debug.Assert(buffer != null);
        Debug.Assert(length >= 0);

        var status = BCrypt.BCryptGenRandom(IntPtr.Zero, buffer, length, BCrypt.BCRYPT_USE_SYSTEM_PREFERRED_RNG);

        if (status != BCrypt.NTSTATUS.STATUS_SUCCESS)
        {
            throw status == BCrypt.NTSTATUS.STATUS_NO_MEMORY
                ? new OutOfMemoryException()
                : new InvalidOperationException();
        }
    }
Exemple #2
0
    internal static unsafe void GetRandomBytes(byte *buffer, int length)
    {
        int status = BCrypt.BCryptGenRandom(buffer, length);

        if (status != BCrypt.STATUS_SUCCESS)
        {
            if (status == BCrypt.STATUS_NO_MEMORY)
            {
                throw new OutOfMemoryException();
            }
            else
            {
                throw new InvalidOperationException();
            }
        }
    }