SequentialGenRandom.cs 910 B

1234567891011121314151617181920212223242526272829303132
  1. // Copyright (c) .NET Foundation. All rights reserved.
  2. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
  3. using System;
  4. using Microsoft.AspNetCore.DataProtection.Cng;
  5. using Microsoft.AspNetCore.DataProtection.Managed;
  6. namespace Microsoft.AspNetCore.DataProtection
  7. {
  8. internal unsafe class SequentialGenRandom : IBCryptGenRandom, IManagedGenRandom
  9. {
  10. private byte _value;
  11. public byte[] GenRandom(int numBytes)
  12. {
  13. byte[] bytes = new byte[numBytes];
  14. for (int i = 0; i < bytes.Length; i++)
  15. {
  16. bytes[i] = _value++;
  17. }
  18. return bytes;
  19. }
  20. public void GenRandom(byte* pbBuffer, uint cbBuffer)
  21. {
  22. for (uint i = 0; i < cbBuffer; i++)
  23. {
  24. pbBuffer[i] = _value++;
  25. }
  26. }
  27. }
  28. }