本文整理匯總了VB.NET中System.Security.Cryptography.RSACryptoServiceProvider.PersistKeyInCsp屬性的典型用法代碼示例。如果您正苦於以下問題:VB.NET RSACryptoServiceProvider.PersistKeyInCsp屬性的具體用法?VB.NET RSACryptoServiceProvider.PersistKeyInCsp怎麽用?VB.NET RSACryptoServiceProvider.PersistKeyInCsp使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類System.Security.Cryptography.RSACryptoServiceProvider
的用法示例。
在下文中一共展示了RSACryptoServiceProvider.PersistKeyInCsp屬性的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: RSACSPExample
' 導入命名空間
Imports System.Security.Cryptography
Module RSACSPExample
Sub Main()
Dim KeyContainerName As String = "MyKeyContainer"
'Create a new key and persist it in
'the key container.
RSAPersistKeyInCSP(KeyContainerName)
'Delete the key from the key container.
RSADeleteKeyInCSP(KeyContainerName)
End Sub
Sub RSAPersistKeyInCSP(ByVal ContainerName As String)
Try
' Create a new instance of CspParameters. Pass
' 13 to specify a DSA container or 1 to specify
' an RSA container. The default is 1.
Dim cspParams As New CspParameters
' Specify the container name using the passed variable.
cspParams.KeyContainerName = ContainerName
'Create a new instance of RSACryptoServiceProvider to generate
'a new key pair. Pass the CspParameters class to persist the
'key in the container. The PersistKeyInCsp property is True by
'default, allowing the key to be persisted.
Dim RSAalg As New RSACryptoServiceProvider(cspParams)
'Indicate that the key was persisted.
Console.WriteLine("The RSA key was persisted in the container, ""{0}"".", ContainerName)
Catch e As CryptographicException
Console.WriteLine(e.Message)
End Try
End Sub
Sub RSADeleteKeyInCSP(ByVal ContainerName As String)
Try
' Create a new instance of CspParameters. Pass
' 13 to specify a DSA container or 1 to specify
' an RSA container. The default is 1.
Dim cspParams As New CspParameters
' Specify the container name using the passed variable.
cspParams.KeyContainerName = ContainerName
'Create a new instance of RSACryptoServiceProvider.
'Pass the CspParameters class to use the
'key in the container.
Dim RSAalg As New RSACryptoServiceProvider(cspParams)
'Explicitly set the PersistKeyInCsp property to False
'to delete the key entry in the container.
RSAalg.PersistKeyInCsp = False
'Call Clear to release resources and delete the key from the container.
RSAalg.Clear()
'Indicate that the key was persisted.
Console.WriteLine("The RSA key was deleted from the container, ""{0}"".", ContainerName)
Catch e As CryptographicException
Console.WriteLine(e.Message)
End Try
End Sub
End Module
開發者ID:VB.NET開發者,項目名稱:System.Security.Cryptography,代碼行數:72,代碼來源:RSACryptoServiceProvider.PersistKeyInCsp