How can I display a dialog box that contains the properties of an X.509 certificate?

不问归期 提交于 2019-12-25 05:36:13

问题


I want to display dialog box that contains properties of an X509 Cert. That box includes three tabs:

  1. General
  2. Details
  3. Certification path

As in this image.

With C# i use a statement:

X509Certificate2UI.DisplayCertificate(X509Certificate2 cert);

But with Java, I can't find similar statement!

How can I display a dialog box that contains the properties of an X.509 certificate?


回答1:


As far as I could track, the .NET will use following function to display the cert information:

[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
internal class CRYPTUI_VIEWCERTIFICATE_STRUCTW
{
    internal uint dwSize;
    internal IntPtr hwndParent;
    internal uint dwFlags;
    internal string szTitle;
    internal IntPtr pCertContext;
    internal IntPtr rgszPurposes;
    internal uint cPurposes;
    internal IntPtr pCryptProviderData;
    internal bool fpCryptProviderDataTrustedUsage;
    internal uint idxSigner;
    internal uint idxCert;
    internal bool fCounterSigner;
    internal uint idxCounterSigner;
    internal uint cStores;
    internal IntPtr rghStores;
    internal uint cPropSheetPages;
    internal IntPtr rgPropSheetPages;
    internal uint nStartPage;
    public CRYPTUI_VIEWCERTIFICATE_STRUCTW();
}

[DllImport("cryptui.dll", CharSet=CharSet.Unicode, SetLastError=true)]
internal static extern bool CryptUIDlgViewCertificateW(
    [In, MarshalAs(UnmanagedType.LPStruct)] CRYPTUI_VIEWCERTIFICATE_STRUCTW ViewInfo, 
    [In, Out] IntPtr pfPropertiesChanged);

I am not a java expert, and unsure how is it possible to call Windows functions from java, but there must be a way. Look at MSDN for CryptUIDlgViewCertificate function, and you will know the details



来源:https://stackoverflow.com/questions/7330796/how-can-i-display-a-dialog-box-that-contains-the-properties-of-an-x-509-certific

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!