本文整理匯總了VB.NET中System.Security.Cryptography.RSACryptoServiceProvider.Decrypt方法的典型用法代碼示例。如果您正苦於以下問題:VB.NET RSACryptoServiceProvider.Decrypt方法的具體用法?VB.NET RSACryptoServiceProvider.Decrypt怎麽用?VB.NET RSACryptoServiceProvider.Decrypt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Security.Cryptography.RSACryptoServiceProvider
的用法示例。
在下文中一共展示了RSACryptoServiceProvider.Decrypt方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: RSACSPExample
' 導入命名空間
Imports System.Security.Cryptography
Imports System.Text
Module RSACSPExample
Sub Main()
Try
'Create a UnicodeEncoder to convert between byte array and string.
Dim ByteConverter As New ASCIIEncoding
Dim dataString As String = "Data to Encrypt"
'Create byte arrays to hold original, encrypted, and decrypted data.
Dim dataToEncrypt As Byte() = ByteConverter.GetBytes(dataString)
Dim encryptedData() As Byte
Dim decryptedData() As Byte
'Create a new instance of the RSACryptoServiceProvider class
' and automatically create a new key-pair.
Dim RSAalg As New RSACryptoServiceProvider
'Display the origianl data to the console.
Console.WriteLine("Original Data: {0}", dataString)
'Encrypt the byte array and specify no OAEP padding.
'OAEP padding is only available on Microsoft Windows XP or
'later.
encryptedData = RSAalg.Encrypt(dataToEncrypt, False)
'Display the encrypted data to the console.
Console.WriteLine("Encrypted Data: {0}", ByteConverter.GetString(encryptedData))
'Pass the data to ENCRYPT and boolean flag specifying
'no OAEP padding.
decryptedData = RSAalg.Decrypt(encryptedData, False)
'Display the decrypted plaintext to the console.
Console.WriteLine("Decrypted plaintext: {0}", ByteConverter.GetString(decryptedData))
Catch e As CryptographicException
'Catch this exception in case the encryption did
'not succeed.
Console.WriteLine(e.Message)
End Try
End Sub
End Module
示例2: Tester
' 導入命名空間
Imports System.Security
Imports System.Security.Cryptography
Imports System.Text
Imports System.IO
Public Class Tester
Public Shared Sub Main
Dim myRSAProvide As New RSACryptoServiceProvider()
Dim strCrypt As String
Dim strResult As String
Dim bteCrypt() As Byte
Dim bteResult() As Byte
Try
strCrypt = "12345678"
bteCrypt = Encoding.ASCII.GetBytes(strCrypt)
bteResult = myRSAProvide.Encrypt(bteCrypt, False)
Console.WriteLine(Encoding.ASCII.GetString(bteResult))
Catch ex As CryptographicException
Console.WriteLine(ex.Message)
End Try
Dim strResault As String
Dim bteDecrypt() As Byte
Try
bteDecrypt = myRSAProvide.Decrypt(bteResult, False)
strResault = Encoding.ASCII.GetString(bteDecrypt)
Console.WriteLine(strResault)
Catch ex As CryptographicException
Console.WriteLine(ex.Message)
End Try
End Sub
End Class