Cryptography.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #include "il2cpp-config.h"
  2. #if IL2CPP_TARGET_WINDOWS_DESKTOP
  3. #include "os/Win32/WindowsHeaders.h"
  4. #include "os/Cryptography.h"
  5. #include <Wincrypt.h>
  6. namespace il2cpp
  7. {
  8. namespace os
  9. {
  10. void* Cryptography::GetCryptographyProvider()
  11. {
  12. HCRYPTPROV provider = 0;
  13. if (!CryptAcquireContext(&provider, NULL, NULL, PROV_INTEL_SEC, CRYPT_VERIFYCONTEXT))
  14. {
  15. if (!CryptAcquireContext(&provider, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT))
  16. {
  17. provider = 0;
  18. }
  19. }
  20. return (void*)provider;
  21. }
  22. bool Cryptography::OpenCryptographyProvider()
  23. {
  24. return false;
  25. }
  26. void Cryptography::ReleaseCryptographyProvider(void* provider)
  27. {
  28. CryptReleaseContext((HCRYPTPROV)provider, 0);
  29. }
  30. bool Cryptography::FillBufferWithRandomBytes(void* provider, intptr_t length, unsigned char* data)
  31. {
  32. ULONG const size = (ULONG)(length < ULONG_MAX ? length : ULONG_MAX); // This is how mono solves the type size difference
  33. return CryptGenRandom((HCRYPTPROV)provider, size, data) == TRUE;
  34. }
  35. }
  36. }
  37. #endif