Nuta
Dostęp do tej strony wymaga autoryzacji. Możesz spróbować się zalogować lub zmienić katalog.
Dostęp do tej strony wymaga autoryzacji. Możesz spróbować zmienić katalogi.
[CAPICOM to składnik tylko 32-bitowy, który jest dostępny do użycia w następujących systemach operacyjnych: Windows Server 2008, Windows Vista i Windows XP. Zamiast tego użyj programu .NET Framework, aby zaimplementować funkcje zabezpieczeń. Aby uzyskać więcej informacji, zobacz Alternatywy dla używania CAPICOM.]
Ta podprokutyna używa ciągu hasła do wygenerowania klucza szyfrowania sesji oraz nazwy pliku, z którego będzie odczytywany zaszyfrowany komunikat. Wszystkie parametry są przekazywane do podprogramu według wartości.
Notatka
CAPICOM nie obsługuje zawartości PKCS #7 EncryptedData, ale używa niestandardowej struktury ASN do EncryptedData. W związku z tym tylko CAPICOM może odszyfrować obiekt CAPICOM EncryptedData.
W przypadku niepowodzenia odszyfrowywania wartość Err.Number jest sprawdzana w celu ustalenia, czy błąd został spowodowany użyciem hasła, które nie pasuje do hasła użytego do zaszyfrowania wiadomości. W takim przypadku zwracany jest błąd NTE_BAD_DATA.
W przypadku dowolnego błędu CAPICOM zwracana jest ujemna wartość dziesiętna Err.Number. Aby uzyskać więcej informacji, zobacz CAPICOM_ERROR_CODE. Aby uzyskać informacje o dodatnich wartościach dziesiętnych Err.Number, zobacz Winerror.h.
Sub DecryptMessage(ByVal hidden As String, ByVal filename As String)
On Error goto ErrorHandler
'Declare an EncryptedData object
Dim message As New EncryptedData
'Declare a string variable to hold the encrypted message.
Dim encrypted As String
' Open an input file and read in the encrypted message
Open filename For Input As #1
Input #1, encrypted
Close #1
' If a message was read in (the length of the input string is
' greater than 0), set the password and decrypt the message.
If Len(encrypted) > 0 then
' Set the password used to generate the key
' used to decrypt the message. If the password
' not the same as the password used when the message
' was encrypted, decryption will fail.
' The algorithm name and key length set in the encrypting
' process are automatically used to decrypt the message.
message.SetSecret hidden
message.Decrypt encrypted
' Display the decrypted message.
MsgBox message.Content
else
msgbox "No encrypted message was read in.
endif
' Release the EncryptedData object and exit the subroutine.
Set message = Nothing
Exit Sub
ErrorHandler:
If Err.Number > 0 Then
MsgBox "Visual Basic error found:" & Err.Description
Else
' Check for a bad password error.
If Err.Number = -2146893819 Then
MsgBox "Error. The password may not be correct."
Else
MsgBox "CAPICOM error found : " & Err.Number
End If
End If
End Sub