github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/cloudconfig/windowsuserdatafiles/CryptoApi.cs (about) 1 using System; 2 using System.Text; 3 using System.Runtime.InteropServices; 4 5 namespace PSCloudbase 6 { 7 public sealed class Win32CryptApi 8 { 9 public static long CRYPT_SILENT = 0x00000040; 10 public static long CRYPT_VERIFYCONTEXT = 0xF0000000; 11 public static int PROV_RSA_FULL = 1; 12 13 [DllImport("advapi32.dll", CharSet=CharSet.Auto, SetLastError=true)] 14 [return : MarshalAs(UnmanagedType.Bool)] 15 public static extern bool CryptAcquireContext(ref IntPtr hProv, 16 StringBuilder pszContainer, // Don't use string, as Powershell replaces $null with an empty string 17 StringBuilder pszProvider, // Don't use string, as Powershell replaces $null with an empty string 18 uint dwProvType, 19 uint dwFlags); 20 21 [DllImport("Advapi32.dll", EntryPoint = "CryptReleaseContext", CharSet = CharSet.Unicode, SetLastError = true)] 22 public static extern bool CryptReleaseContext(IntPtr hProv, Int32 dwFlags); 23 24 [DllImport("advapi32.dll", SetLastError=true)] 25 public static extern bool CryptGenRandom(IntPtr hProv, uint dwLen, byte[] pbBuffer); 26 27 [DllImport("Kernel32.dll")] 28 public static extern uint GetLastError(); 29 } 30 }