인증서 수집 및 확인
[CAPICOM은 Windows Server 2008, Windows Vista 및 Windows XP 운영 체제에서 사용할 수 있는 32비트 전용 구성 요소입니다. 대신 .NET Framework 사용하여 보안 기능을 구현합니다. 자세한 내용은 CAPICOM 사용에 대한 대안을 참조하세요.]
인증서 그룹을 수집하고 확인해야 하는 경우가 많습니다 . 이 작업은 받는 사람 그룹이 봉투 메시지를 받을 수 있도록 준비하기 위해 수행되는 경우가 많습니다. 다음 예제에서는 로컬 저장소의 인증서가 열거되고 유효성이 검사됩니다. 다음으로 Active Directory 저장소가 열리고 로컬 저장소에 새 인증서를 검색하고 추가합니다. Active Directory 저장소에서 검색된 인증서가 유효성을 검사하고 유효한 경우 로컬 저장소에 추가됩니다. 그런 다음 두 매장이 모두 닫힙니다.
CAPICOM 오류에서 Err.Number 의 음수 10진수 값이 반환됩니다. 자세한 내용은 CAPICOM_ERROR_CODE 참조하세요. Err.Number의 양의 10진수 값에 대한 자세한 내용은 Winerror.h를 참조하세요.
이 예제에서는 로컬 저장소의 이름이 문자열 매개 변수로 전달됩니다. Active Directory 저장소의 인증서 검색 조건을 나타내는 문자열도 매개 변수로 전달됩니다.
Sub CollectValidCerts(ByVal storename As String, ByVal _
certname As String)
On Error GoTo errorhandler
' Prepare a local certificate store to contain valid
' certificates for the recipients of an enveloped
' message.
' Open the local store and go to the certificates in the store
' 1. Display the certificate
' 2. Check the validity of the certificate
' 3. Remove certificates that are not valid from the store
Dim LocalStore As New Store
Dim ADStore As New Store
Dim i As Long
LocalStore.Open(CAPICOM_CURRENT_USER_STORE, storename, _
CAPICOM_STORE_OPEN_READ_WRITE)
MsgBox("There are " & LocalStore.Certificates.Count & _
" certificates in this store ")
For i = 1 To LocalStore.Certificates.Count
If LocalStore.Certificates.Item(i).IsValid Then
LocalStore.Certificates.Item(i).Display()
Else
MsgBox("A certificate that is not valid was found.")
End If
Next i
' Open the AD store and retrieve a certificate based
' on a string passed into the function. Add any valid
' certificates found to the local store.
ADStore.Open(CAPICOM_ACTIVE_DIRECTORY_USER_STORE, certname, _
CAPICOM_STORE_OPEN_READ_ONLY)
MsgBox("There are " & ADStore.Certificates.Count & _
" certificates in the AD store.")
For i = 1 To ADStore.Certificates.Count
If ADStore.Certificates.Item(i).IsValid Then
ADStore.Certificates.Item(i).Display()
LocalStore.Add(ADStore.Certificates.Item(i))
Else
MsgBox("the certificate from the AD store is not valid.")
End If
Next i
LocalStore = Nothing
ADStore = Nothing
MsgBox("Sub finished without error ")
Exit Sub
errorhandler:
If Err.Number > 0 Then
MsgBox("Visual Basic error found:" & Err.Description)
Else
MsgBox("CAPICOM error found : " & Err.Number)
End If
End Sub