当前位置: 首页>>代码示例>>VB.NET>>正文


VB.NET RSACryptoServiceProvider.Encrypt方法代码示例

本文整理汇总了VB.NET中System.Security.Cryptography.RSACryptoServiceProvider.Encrypt方法的典型用法代码示例。如果您正苦于以下问题:VB.NET RSACryptoServiceProvider.Encrypt方法的具体用法?VB.NET RSACryptoServiceProvider.Encrypt怎么用?VB.NET RSACryptoServiceProvider.Encrypt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Security.Cryptography.RSACryptoServiceProvider的用法示例。


在下文中一共展示了RSACryptoServiceProvider.Encrypt方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。

示例1: RSACSPSample

' 导入命名空间
Imports System.Security.Cryptography

Class RSACSPSample

    Shared Sub Main()
        Try
            'initialze the byte arrays to the public key information.
            Dim PublicKey As Byte() = {214, 46, 220, 83, 160, 73, 40, 39, 201, 155, 19, 202, 3, 11, 191, 178, 56, 74, 90, 36, 248, 103, 18, 144, 170, 163, 145, 87, 54, 61, 34, 220, 222, 207, 137, 149, 173, 14, 92, 120, 206, 222, 158, 28, 40, 24, 30, 16, 175, 108, 128, 35, 230, 118, 40, 121, 113, 125, 216, 130, 11, 24, 90, 48, 194, 240, 105, 44, 76, 34, 57, 249, 228, 125, 80, 38, 9, 136, 29, 117, 207, 139, 168, 181, 85, 137, 126, 10, 126, 242, 120, 247, 121, 8, 100, 12, 201, 171, 38, 226, 193, 180, 190, 117, 177, 87, 143, 242, 213, 11, 44, 180, 113, 93, 106, 99, 179, 68, 175, 211, 164, 116, 64, 148, 226, 254, 172, 147}

            Dim Exponent As Byte() = {1, 0, 1}

            'Values to store encrypted symmetric keys.
            Dim EncryptedSymmetricKey() As Byte
            Dim EncryptedSymmetricIV() As Byte

            'Create a new instance of RSACryptoServiceProvider.
            Dim RSA As New RSACryptoServiceProvider()

            'Create a new instance of RSAParameters.
            Dim RSAKeyInfo As New RSAParameters()

            'Set RSAKeyInfo to the public key values. 
            RSAKeyInfo.Modulus = PublicKey
            RSAKeyInfo.Exponent = Exponent

            'Import key parameters into RSA.
            RSA.ImportParameters(RSAKeyInfo)

            'Create a new instance of the RijndaelManaged class.
            Dim RM As New RijndaelManaged()

            'Encrypt the symmetric key and IV.
            EncryptedSymmetricKey = RSA.Encrypt(RM.Key, False)
            EncryptedSymmetricIV = RSA.Encrypt(RM.IV, False)

            Console.WriteLine("RijndaelManaged Key and IV have been encrypted with RSACryptoServiceProvider.")

            'Catch and display a CryptographicException  
            'to the console.
        Catch e As CryptographicException
            Console.WriteLine(e.Message)
        End Try
    End Sub
End Class
开发者ID:VB.NET开发者,项目名称:System.Security.Cryptography,代码行数:45,代码来源:RSACryptoServiceProvider.Encrypt

示例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
开发者ID:VB程序员,项目名称:System.Security.Cryptography,代码行数:38,代码来源:RSACryptoServiceProvider.Encrypt


注:本文中的System.Security.Cryptography.RSACryptoServiceProvider.Encrypt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。