當前位置: 首頁>>代碼示例>>VB.NET>>正文


VB.NET AsymmetricKeyExchangeDeformatter類代碼示例

本文整理匯總了VB.NET中System.Security.Cryptography.AsymmetricKeyExchangeDeformatter的典型用法代碼示例。如果您正苦於以下問題:VB.NET AsymmetricKeyExchangeDeformatter類的具體用法?VB.NET AsymmetricKeyExchangeDeformatter怎麽用?VB.NET AsymmetricKeyExchangeDeformatter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了AsymmetricKeyExchangeDeformatter類的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。

示例1: New

' 導入命名空間
Imports System.Security.Cryptography

Namespace Contoso
    Public Class ContosoDeformatter
        Inherits AsymmetricKeyExchangeDeformatter

        Private rsaKey As RSA

        ' Default constructor.
        Public Sub New()

        End Sub

        ' Constructor with the public key to use for encryption.
        Public Sub New(ByVal key As AsymmetricAlgorithm)
            SetKey(key)
        End Sub

        ' Set the public key for encyption operations.
        Public Overrides Sub SetKey(ByVal key As AsymmetricAlgorithm)
            If (Not key Is Nothing) Then
                rsaKey = CType(key, RSA)
            Else
                Throw New ArgumentNullException("key")
            End If
        End Sub

        ' Disallow access to the parameters of the formatter.
        Public Overrides ReadOnly Property Parameters() As String
            Get
                Return Nothing
            End Get
            Set(ByVal Value As String)

            End Set
        End Property

        ' Create the encrypted key exchange data from the specified input
        ' data. This method uses the RSACryptoServiceProvider only. To
        ' support additional providers or provide custom decryption logic,
        ' add logic to this member.
        Public Overrides Function DecryptKeyExchange(
            ByVal rgbData() As Byte) As Byte()

            Dim decryptedBytes() As Byte

            If (Not rsaKey Is Nothing) Then
                If (TypeOf (rsaKey) Is RSACryptoServiceProvider) Then
                    Dim rsaProvider As RSACryptoServiceProvider
                    rsaProvider = CType(rsaKey, RSACryptoServiceProvider)

                    decryptedBytes = rsaProvider.Decrypt(rgbData, True)
                End If

                ' Add custom decryption logic here.

            Else
                Throw New CryptographicUnexpectedOperationException(
                    "Cryptography_MissingKey")
            End If

            Return decryptedBytes
        End Function

    End Class
End Namespace
開發者ID:VB.NET開發者,項目名稱:System.Security.Cryptography,代碼行數:67,代碼來源:AsymmetricKeyExchangeDeformatter

輸出:

Data to encrypt : Sample Contoso encryption application.
Encrypted data: Kh34dfg-(*&834d+3
Data decrypted : Sample Contoso encryption application.

This sample completed successfully; press Exit to continue.


注:本文中的System.Security.Cryptography.AsymmetricKeyExchangeDeformatter類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。