다음을 통해 공유


인증서 저장소에 인증서 추가

[CAPICOM은 Windows Server 2008, Windows Vista, Windows XP 운영 체제에서 사용할 수 있는 32비트 전용 구성 요소입니다. 대신 .NET Framework 사용하여 보안 기능을 구현합니다. 자세한 내용은 CAPICOM 사용에 대한 대안을 참조하세요.]

저장소가 읽기/쓰기 권한으로 열려 있는 경우 인증서 저장소 에 인증서를 추가하거나 제거할 수 있습니다. 읽기/쓰기 권한은 Active Directory 저장소에 부여되지 않습니다. 인증서를 메모리 저장소에 추가하거나 메모리 저장소에서 제거할 수 있지만 메모리 저장소의 변경 내용은 세션 간에 유지되지 않습니다.

Add 메서드를 사용하여 읽기/쓰기 권한으로 열린 인증서 저장소에 인증서를 추가할 수 있습니다. Remove 메서드를 사용하여 읽기/쓰기 권한으로 열린 인증서 저장소에서 인증서를 제거할 수 있습니다. 새 저장소를 만들고 CAPICOM_CURRENT_USER_STORE 및 CAPICOM_LOCAL_MACHINE_STORE 위치에 저장할 수 있습니다. 이러한 위치 중 하나에 새로 만든 저장소는 읽기/쓰기 권한으로 열 수 있습니다.

다음 예제에서는 두 개의 인증서 저장소가 열립니다. F로 시작하는 성이 있는 주체의 인증서는 Active Directory 저장소에서 검색됩니다. 그런 다음 CAPICOM_CURRENT_USER_STORE CAPICOM_CA_STORE 저장소가 읽기/쓰기 저장소로 열리고 Active Directory 저장소의 인증서 컬렉션에서 첫 번째 인증서가 CAPICOM_CA_STORE 인증서에 추가됩니다.

데모를 위해 예제에서는 CAPICOM_MEMORY_STORE, CAPICOM_CURRENT_USER_STORE 및 CAPICOM_LOCAL_MACHINE_STORE 위치에 저장소를 여는 방법을 보여 있습니다. 이 예제에서는 열려 있는 저장소에서 모든 인증서를 내보내고, 내보낸 인증서를 파일에 쓰고, 다시 읽고, 다른 저장소로 가져오는 방법을 보여 줍니다. 새로 가져온 인증서는 열거되고 표시됩니다.

CAPICOM 오류에서 Err.Number 의 음수 10진수 값이 반환됩니다. 자세한 내용은 CAPICOM_ERROR_CODE 참조하세요. Err.Number의 양의 10진수 값에 대한 자세한 내용은 Winerror.h를 참조하세요.

다음 예제에서는 Store 개체 선언에서 초기 바인딩을 사용하여 인증서 저장소를 열고 해당 개체의 instance 만드는 방법을 보여 있습니다.

Sub AddCert()
On Error GoTo ErrorHandler
' The following shows two different ways to declare and
' create a store object.

Dim myADstore As New Store

Dim myCAstore As Store
Set myCAstore = New Store

' In this example, the Active Directory store will be searched for a 
' certificate with a subject name that begins with the letter F. 
' This is done by using the string "SN=F*" as the name of the store.

Dim SubjectNameSN As String
SubjectNameSN = "SN=F*"

' Active Directory stores can only be opened with read-only
' access.

myADstore.Open CAPICOM_ACTIVE_DIRECTORY_USER_STORE,
                SubjectNameSN , CAPICOM_STORE_OPEN_READ_ONLY

'  This example assumes that the store opened and that
'  at least one certificate was returned.
'  A complete application would ensure that at least one certificate
'  was in the store before proceeding and would
'  also select one or more of the certificates returned
'  to be added instead of using the first certificate
'  in the collection.

'  Open the MY store so that a certificate can be added.

myCAstore.Open CAPICOM_CURRENT_USER_STORE, CAPICOM_MY_STORE,
                    CAPICOM_STORE_OPEN_READ_WRITE

myCAstore.Add myADstore.certificates.Item(1)

' Release the two store objects.

Set myCAstore = Nothing
Set myADstore = Nothing
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