internal static int GetKeyPropertyInt32(SafeCspKeyHandle keyHandle, CapiNative.KeyProperty property) { byte[] keyProperty = CapiNative.GetKeyProperty(keyHandle, property); if (keyProperty.Length != 4) { return(0); } return(BitConverter.ToInt32(keyProperty, 0)); }
internal static byte[] GetKeyProperty(SafeCspKeyHandle keyHandle, CapiNative.KeyProperty property) { int pdwDataLen = 0; byte[] pbData1 = (byte[])null; if (!CapiNative.UnsafeNativeMethods.CryptGetKeyParam(keyHandle, property, pbData1, out pdwDataLen, 0)) { int lastWin32Error = Marshal.GetLastWin32Error(); if (lastWin32Error != 234) { throw new CryptographicException(lastWin32Error); } } byte[] pbData2 = new byte[pdwDataLen]; if (!CapiNative.UnsafeNativeMethods.CryptGetKeyParam(keyHandle, property, pbData2, out pdwDataLen, 0)) { throw new CryptographicException(Marshal.GetLastWin32Error()); } return(pbData2); }
internal static byte[] GetKeyProperty(SafeCspKeyHandle keyHandle, CapiNative.KeyProperty property) { int num = 0; byte[] array = null; if (!CapiNative.UnsafeNativeMethods.CryptGetKeyParam(keyHandle, property, array, ref num, 0)) { int lastWin32Error = Marshal.GetLastWin32Error(); if (lastWin32Error != 234) { throw new CryptographicException(lastWin32Error); } } array = new byte[num]; if (!CapiNative.UnsafeNativeMethods.CryptGetKeyParam(keyHandle, property, array, ref num, 0)) { throw new CryptographicException(Marshal.GetLastWin32Error()); } return(array); }
internal static extern bool CryptGetKeyParam(SafeCspKeyHandle hKey, CapiNative.KeyProperty dwParam, [MarshalAs(UnmanagedType.LPArray), In, Out] byte[] pbData, [In, Out] ref int pdwDataLen, int dwFlags);