Entropy.cs 800 B

12345678910111213141516171819202122232425262728293031
  1. using System;
  2. using System.IdentityModel.Tokens;
  3. using System.Security.Cryptography;
  4. namespace System.IdentityModel.Protocols.WSTrust
  5. {
  6. public class Entropy : ProtectedKey
  7. {
  8. public Entropy (ProtectedKey protectedKey) : base (protectedKey.GetKeyBytes (), protectedKey.WrappingCredentials)
  9. { }
  10. public Entropy (byte[] secret) : base (secret)
  11. { }
  12. public Entropy (int entropySizeInBits)
  13. : this(Entropy.GetRandomByteArray(entropySizeInBits / 8))
  14. { }
  15. public Entropy (byte[] secret, EncryptingCredentials wrappingCredentials) : base (secret, wrappingCredentials)
  16. { }
  17. private static byte[] GetRandomByteArray (int arraySize) {
  18. byte[] b = new byte[arraySize];
  19. RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
  20. rng.GetNonZeroBytes(b);
  21. return b;
  22. }
  23. }
  24. }