Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.Security.Cryptography
- Imports System.IO
- Imports System.IO.IsolatedStorage
- Public Class Form1
- Dim ue As New System.Text.UTF8Encoding
- Dim sec As New RSACryptoServiceProvider
- Dim bytString() As Byte, bytCifrado() As Byte, bytDescifrado() As Byte
- Dim ISF As IsolatedStorage = IsolatedStorageFile.GetuserStoreForAssembly
- Sub cifrado(texto As String)
- bytString = ue.GetBytes(texto)
- bytCifrado = sec.Encrypt(bytString, False)
- txtCifrado.Text = Convert.ToBase64String(bytCifrado)
- End Sub
- Private Sub btnCifrar_Click(sender As Object, e As EventArgs) Handles btnCifrar.Click
- Call cifrado(txtTexto.Text)
- End Sub
- Private Sub btnGrabar_Click(sender As Object, e As EventArgs) Handles btnGrabar.Click
- Dim nombre$ = InputBox("Ingrese en nombre del archivo")
- Using fs As New IsolatedStorageFileStream(nombre, FileMode.Create, ISF)
- Using sw As New StreamWriter(fs)
- sw.Write(txtCifrado.Text)
- End Using
- End Using
- End Sub
- Private Sub btnAbrir_Click(sender As Object, e As EventArgs) Handles btnAbrir.Click
- Dim nombre$ = InputBox("Ingrese en nombre del archivo a abrir")
- Dim texto$ = ""
- Using fs As New IsolatedStorageFileStream(nombre, FileMode.Open, ISF)
- texto = New StreamReader(fs).ReadToEnd
- descifrado(texto)
- End Using
- End Sub
- Sub descifrado(texto As String)
- bytDescifrado = sec.Decrypt(Convert.FromBase64String(texto), False)
- txtCifrado.Text = ue.GetString(bytDescifrado)
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement