selwincertform.cpp
来自「著名的SecureBlackBox控件完整源码」· C++ 代码 · 共 124 行
CPP
124 行
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "SelWinCertForm.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TfrmSelWinCert *frmSelWinCert;
//---------------------------------------------------------------------------
__fastcall TfrmSelWinCert::TfrmSelWinCert(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TfrmSelWinCert::FormCreate(TObject *Sender)
{
WinCertStorage = new TElWinCertStorage(NULL);
WinCertStorage->SystemStores->Text = "MY";
UpdateCertificates();
UpdateCertInfo();
}
//---------------------------------------------------------------------------
void __fastcall TfrmSelWinCert::FormDestroy(TObject *Sender)
{
delete WinCertStorage;
}
//---------------------------------------------------------------------------
void __fastcall TfrmSelWinCert::lvCerificatesChange(TObject *Sender,
TListItem *Item, TItemChange Change)
{
if (lvCerificates->Selected != NULL)
FCertificate = ((TElX509Certificate*)(lvCerificates->Selected->Data));
else
FCertificate = NULL;
UpdateCertInfo();
}
//---------------------------------------------------------------------------
void TfrmSelWinCert::UpdateCertInfo(void)
{
TElKeyUsageExtension* KeyUsage;
TElExtendedKeyUsageExtension* ExtKeyUsage;
AnsiString s;
if (FCertificate == NULL)
{
dlbPrivateKey->Caption = "None";
dlbUsage->Caption = "None";
return;
}
if (FCertificate->PrivateKeyExists)
dlbPrivateKey->Caption = "Available";
else
dlbPrivateKey->Caption = "None";
s = "";
if (FCertificate->Extensions->Included.Contains(ceKeyUsage))
{
KeyUsage = FCertificate->Extensions->KeyUsage;
if (KeyUsage->DigitalSignature)
s = s + "Digital Signitare, ";
if (KeyUsage->NonRepudiation)
s = s + "Non-repudiation, ";
if (KeyUsage->KeyEncipherment)
s = s + "Key Transport, ";
if (KeyUsage->DataEncipherment)
s = s + "Data Encipherment, ";
if (KeyUsage->KeyAgreement)
s = s + "Key Agreement, ";
if (KeyUsage->KeyCertSign)
s = s + "Certificate Signing, ";
if (KeyUsage->CRLSign)
s = s + "CRL Signing, ";
if (KeyUsage->EncipherOnly)
s = s + "Encipher only, ";
if (KeyUsage->DecipherOnly)
s = s + "Decipher only, ";
if (s.Length() > 0)
s = s.SubString(1, s.Length() - 2);
}
dlbUsage->Caption = s;
}
//---------------------------------------------------------------------------
void TfrmSelWinCert::UpdateCertificates(void)
{
TElX509Certificate* Cert;
TListItem* Item;
AnsiString s;
for (int i = 0; i<WinCertStorage->Count; i++)
{
Cert = WinCertStorage->Certificates[i];
Item = lvCerificates->Items->Add();
Item->Data = Cert;
// Serial Number
s = Cert->SerialNumber;
Item->Caption = BeautifyBinaryString(BinaryToString(s.c_str(), s.Length()), ' ');
// Subject
s = Cert->SubjectName.CommonName;
if (s == "")
s = Cert->SubjectName.Organization;
Item->SubItems->Add(s);
// Issuer
s = Cert->IssuerName.CommonName;
if (s == "")
s = Cert->IssuerName.Organization;
Item->SubItems->Add(s);
// Valid From
Item->SubItems->Add(DateTimeToStr(Cert->ValidFrom));
// Valid To
Item->SubItems->Add(DateTimeToStr(Cert->ValidTo));
// Private Key
if (Cert->PrivateKeyExists)
Item->SubItems->Add("Yes");
else
Item->SubItems->Add("No");
}
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?