本文整理汇总了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