Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. public Task<byte[]> GetEntropy1(int length)
  2. {
  3. RNGCryptoServiceProvider entropyGen = new RNGCryptoServiceProvider();
  4. byte[] entropyBuffer = new byte[2048];
  5.  
  6. try
  7. {
  8. semaphore.Wait();
  9.  
  10. Task t = Task.Run(() =>
  11. {
  12. /* gather entropy from sensors */
  13. });
  14.  
  15. if (!t.Wait(5000))
  16. {
  17. entropyGen.GetBytes(entropyBuffer);
  18. }
  19. return entropyBuffer;
  20. }
  21. catch (Exception)
  22. {
  23. return entropyBuffer;
  24. }
  25. finally
  26. {
  27. this.semaphore.Release();
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement