2017-09-04 75 views
0

我正在通过RSACryptoServiceProvider使用数字证书作为键签署一个字符串。设置RSACryptoServiceProvider的认证窗口句柄

这个过程是由一个delphi应用程序调用的COM DLL里面完成的。

在证书有可能通过该方法传递手柄的选择

scollection = X509Certificate2UI.SelectFromCollection (fcollection, "Available digital certificate (s)", "Select digital certificate", X509SelectionFlag.SingleSelection, ptr); 

,但在认证屏幕,我不能做同样的事情,任何人都可以帮我这个?

回答

1

假设你的意思是你想要父一些HWND PIN或同意提示,你要像

private static RSACryptoServiceProvider AssociateHwnd(
    RSACryptoServiceProvider rsaCsp, 
    IntPtr hwnd) 
{ 
    CspKeyContainerInfo containerInfo = rsaCsp.CspKeyContainerInfo; 

    CspParameters newParameters = new CspParameters(
     containerInfo.ProviderType, 
     containerInfo.ProviderName, 
     containerInfo.KeyContainerName) 
    { 
     KeyNumber = (int)containerInfo.KeyNumber, 
     Flags = CspProviderFlags.UseExistingKey, 
     ParentWindowHandle = hwnd, 
    }; 

    if (containerInfo.MachineKeyStore) 
    { 
     newParameters.Flags |= CspProviderFlags.UseMachineKeyStore; 
    } 

    return new RSACryptoServiceProvider(newParameters); 
} 

请注意,此代码假定你有.NET 4.7作为运行时,使用中所描述的坦途https://docs.microsoft.com/en-us/dotnet/framework/migration-guide/mitigation-cspparameters-parentwindowhandle-expects-an-hwnd