VB.Net by API/System.Security.Cryptography/RSACryptoServiceProvider — различия между версиями

Материал из VB Эксперт
Перейти к: навигация, поиск
м (1 версия)
 
м (1 версия)
 
(нет различий)

Текущая версия на 12:50, 26 мая 2010

New RSACryptoServiceProvider

  

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


RSACryptoServiceProvider.Decrypt

  

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


RSACryptoServiceProvider.Encrypt

  

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