P
Peter Laman
I'm currently sorting out how to use CAPICOM in an Excel macro (Excel 2000).
This is the macro:
Sub TryCapicom()
Dim PlainText As String
Dim MyStore As New Store
Dim SignObj As New SignedData
Dim Autograph As New CAPICOM.Signer
Dim TimeStamp As New CAPICOM.Attribute
Dim EncData As String
Dim Cert As Certificate
On Error GoTo ErrorHandler
PlainText = Range("A1")
MyStore.Open CAPICOM_CURRENT_USER_STORE, "MY", _
CAPICOM_STORE_OPEN_READ_ONLY
Set Cert = MyStore.Certificates.Select("a", "b", False).Item(1)
Set Autograph.Certificate = Cert
SignObj.Content = PlainText
TimeStamp.Name = CAPICOM_AUTHENTICATED_ATTRIBUTE_SIGNING_TIME
TimeStamp.Value = Now
Autograph.AuthenticatedAttributes.Add TimeStamp
EncData = SignObj.Sign(Autograph, False, CAPICOM_ENCODE_BASE64)
MsgBox EncData
Exit Sub
ErrorHandler:
MsgBox Err.Description
End Sub
The following line fails:
Set Autograph.Certificate = Cert
The error message is ""The Signer object has not been properly initialized."
The tragic thing is, that I modelled the macro after the example found in
http://msdn.microsoft.com/library/d...-us/seccrypto/security/signing_a_document.asp
What am I doing wrong?
This is the macro:
Sub TryCapicom()
Dim PlainText As String
Dim MyStore As New Store
Dim SignObj As New SignedData
Dim Autograph As New CAPICOM.Signer
Dim TimeStamp As New CAPICOM.Attribute
Dim EncData As String
Dim Cert As Certificate
On Error GoTo ErrorHandler
PlainText = Range("A1")
MyStore.Open CAPICOM_CURRENT_USER_STORE, "MY", _
CAPICOM_STORE_OPEN_READ_ONLY
Set Cert = MyStore.Certificates.Select("a", "b", False).Item(1)
Set Autograph.Certificate = Cert
SignObj.Content = PlainText
TimeStamp.Name = CAPICOM_AUTHENTICATED_ATTRIBUTE_SIGNING_TIME
TimeStamp.Value = Now
Autograph.AuthenticatedAttributes.Add TimeStamp
EncData = SignObj.Sign(Autograph, False, CAPICOM_ENCODE_BASE64)
MsgBox EncData
Exit Sub
ErrorHandler:
MsgBox Err.Description
End Sub
The following line fails:
Set Autograph.Certificate = Cert
The error message is ""The Signer object has not been properly initialized."
The tragic thing is, that I modelled the macro after the example found in
http://msdn.microsoft.com/library/d...-us/seccrypto/security/signing_a_document.asp
What am I doing wrong?