public static SafeKeyHandleImpl GetUserKey(SafeProvHandleImpl providerHandle, int keyNumber) { var keyHandle = SafeKeyHandleImpl.InvalidHandle; if (!CryptoApi.CryptGetUserKey(providerHandle, (uint)keyNumber, ref keyHandle)) { throw CreateWin32Error(); } return(keyHandle); }