Advertisement
hoscanoa

Pregunta 2 Final POO-I

Apr 4th, 2014
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.63 KB | None | 0 0
  1. Imports System.Security.Cryptography
  2. Imports System.IO
  3. Imports System.IO.IsolatedStorage
  4.  
  5. Public Class Form1
  6.  
  7.     Dim ue As New System.Text.UTF8Encoding
  8.     Dim sec As New RSACryptoServiceProvider
  9.  
  10.     Dim bytString() As Byte, bytCifrado() As Byte, bytDescifrado() As Byte
  11.  
  12.     Dim ISF As IsolatedStorage = IsolatedStorageFile.GetuserStoreForAssembly
  13.  
  14.  
  15.     Sub cifrado(texto As String)
  16.         bytString = ue.GetBytes(texto)
  17.         bytCifrado = sec.Encrypt(bytString, False)
  18.         txtCifrado.Text = Convert.ToBase64String(bytCifrado)
  19.     End Sub
  20.  
  21.     Private Sub btnCifrar_Click(sender As Object, e As EventArgs) Handles btnCifrar.Click
  22.         Call cifrado(txtTexto.Text)
  23.     End Sub
  24.  
  25.     Private Sub btnGrabar_Click(sender As Object, e As EventArgs) Handles btnGrabar.Click
  26.         Dim nombre$ = InputBox("Ingrese en nombre del archivo")
  27.         Using fs As New IsolatedStorageFileStream(nombre, FileMode.Create, ISF)
  28.             Using sw As New StreamWriter(fs)
  29.                 sw.Write(txtCifrado.Text)
  30.             End Using
  31.         End Using
  32.     End Sub
  33.  
  34.     Private Sub btnAbrir_Click(sender As Object, e As EventArgs) Handles btnAbrir.Click
  35.         Dim nombre$ = InputBox("Ingrese en nombre del archivo a abrir")
  36.         Dim texto$ = ""
  37.         Using fs As New IsolatedStorageFileStream(nombre, FileMode.Open, ISF)
  38.             texto = New StreamReader(fs).ReadToEnd
  39.             descifrado(texto)
  40.         End Using
  41.     End Sub
  42.  
  43.     Sub descifrado(texto As String)
  44.         bytDescifrado = sec.Decrypt(Convert.FromBase64String(texto), False)
  45.         txtCifrado.Text = ue.GetString(bytDescifrado)
  46.     End Sub
  47.  
  48. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement