{"id":368,"date":"2018-01-02T01:33:09","date_gmt":"2018-01-02T01:33:09","guid":{"rendered":"https:\/\/garikoitz.info\/blog\/?p=368"},"modified":"2018-01-02T01:46:12","modified_gmt":"2018-01-02T01:46:12","slug":"encriptador-desencriptador-net","status":"publish","type":"post","link":"https:\/\/garikoitz.info\/blog\/2018\/01\/encriptador-desencriptador-net\/","title":{"rendered":"Encriptador\/Desencriptador .NET"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">\u00cdndice<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Alternar tabla de contenidos\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 eztoc-toggle-hide-by-default' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/garikoitz.info\/blog\/2018\/01\/encriptador-desencriptador-net\/#Intro\" >Intro<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/garikoitz.info\/blog\/2018\/01\/encriptador-desencriptador-net\/#Codigo\" >C\u00f3digo<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/garikoitz.info\/blog\/2018\/01\/encriptador-desencriptador-net\/#Video\" >V\u00eddeo<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/garikoitz.info\/blog\/2018\/01\/encriptador-desencriptador-net\/#Enlaces\" >Enlaces<\/a><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"Intro\"><\/span>Intro<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Aqu\u00ed teneis un sencillo encriptador\/desencriptador multi-archivo implementando el algoritmo de encriptaci\u00f3n <a href=\"https:\/\/es.wikipedia.org\/wiki\/Advanced_Encryption_Standard\" target=\"_blank\" rel=\"noopener\">Rijndael<\/a> de 256 bits. El encriptador est\u00e1 basado en el c\u00f3digo de\u00a0<span class=\"author\"><a href=\"https:\/\/www.codeproject.com\/script\/Membership\/View.aspx?mid=1842999\" rel=\"author\">Thad Van den Bosch<\/a>.<\/span><\/p>\n<p>Simplemente abre un nuevo proyecto e introduce <strong>3 botones<\/strong>, un <strong>ListView<\/strong>, una <strong>caja de texto<\/strong> y una <strong>barra de progreso<\/strong>.<\/p>\n<div id='gallery-1' class='gallery galleryid-368 gallery-columns-4 gallery-size-thumbnail'><figure class='gallery-item'>\n\t\t\t<div class='gallery-icon portrait'>\n\t\t\t\t<a href='https:\/\/garikoitz.info\/blog\/wp-content\/uploads\/2018\/01\/Form1.avif'><img loading=\"lazy\" decoding=\"async\" width=\"150\" height=\"150\" src=\"https:\/\/garikoitz.info\/blog\/wp-content\/uploads\/2018\/01\/Form1-150x150.png\" class=\"attachment-thumbnail size-thumbnail\" alt=\"\" aria-describedby=\"gallery-1-375\" \/><\/a>\n\t\t\t<\/div>\n\t\t\t\t<figcaption class='wp-caption-text gallery-caption' id='gallery-1-375'>\n\t\t\t\tElementos del proyecto\n\t\t\t\t<\/figcaption><\/figure><figure class='gallery-item'>\n\t\t\t<div class='gallery-icon portrait'>\n\t\t\t\t<a href='https:\/\/garikoitz.info\/blog\/wp-content\/uploads\/2018\/01\/2018-01-02_012115.avif'><img loading=\"lazy\" decoding=\"async\" width=\"150\" height=\"150\" src=\"https:\/\/garikoitz.info\/blog\/wp-content\/uploads\/2018\/01\/2018-01-02_012115-150x150.png\" class=\"attachment-thumbnail size-thumbnail\" alt=\"\" aria-describedby=\"gallery-1-372\" \/><\/a>\n\t\t\t<\/div>\n\t\t\t\t<figcaption class='wp-caption-text gallery-caption' id='gallery-1-372'>\n\t\t\t\tFormulario Form1\n\t\t\t\t<\/figcaption><\/figure><figure class='gallery-item'>\n\t\t\t<div class='gallery-icon landscape'>\n\t\t\t\t<a href='https:\/\/garikoitz.info\/blog\/wp-content\/uploads\/2018\/01\/2018-01-02_012356.avif'><img loading=\"lazy\" decoding=\"async\" width=\"150\" height=\"150\" src=\"https:\/\/garikoitz.info\/blog\/wp-content\/uploads\/2018\/01\/2018-01-02_012356-150x150.png\" class=\"attachment-thumbnail size-thumbnail\" alt=\"\" aria-describedby=\"gallery-1-373\" \/><\/a>\n\t\t\t<\/div>\n\t\t\t\t<figcaption class='wp-caption-text gallery-caption' id='gallery-1-373'>\n\t\t\t\tArchivo Original y Encriptado\n\t\t\t\t<\/figcaption><\/figure><figure class='gallery-item'>\n\t\t\t<div class='gallery-icon landscape'>\n\t\t\t\t<a href='https:\/\/garikoitz.info\/blog\/wp-content\/uploads\/2018\/01\/2018-01-02_012446.avif'><img loading=\"lazy\" decoding=\"async\" width=\"150\" height=\"150\" src=\"https:\/\/garikoitz.info\/blog\/wp-content\/uploads\/2018\/01\/2018-01-02_012446-150x150.png\" class=\"attachment-thumbnail size-thumbnail\" alt=\"\" aria-describedby=\"gallery-1-374\" \/><\/a>\n\t\t\t<\/div>\n\t\t\t\t<figcaption class='wp-caption-text gallery-caption' id='gallery-1-374'>\n\t\t\t\tArchivos originales y encriptados\n\t\t\t\t<\/figcaption><\/figure>\n\t\t<\/div>\n\n<p><strong>Atenci\u00f3n<\/strong>: Si no se utiliza la misma clave al desencriptar, el proceso de desencriptado se completa pero el archivo resultante ser\u00e1 ilegible.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Codigo\"><\/span>C\u00f3digo<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">Imports System\r\nImports System.IO\r\nImports System.Security\r\nImports System.Security.Cryptography\r\n\r\nPublic Class form1\r\n    Dim ruta, rutabak As String\r\n    Dim duplicado As Boolean = False\r\n\r\n    Public Function CRC32(ByVal sFileName As String) As String\r\n        Try\r\n            Dim FS As FileStream = New FileStream(sFileName, FileMode.Open, FileAccess.Read, FileShare.Read, 8192)\r\n            Dim CRC32Result As Integer = &amp;HFFFFFFFF\r\n            Dim Buffer(4096) As Byte\r\n            Dim ReadSize As Integer = 4096\r\n            Dim Count As Integer = FS.Read(Buffer, 0, ReadSize)\r\n            Dim CRC32Table(256) As Integer\r\n            Dim DWPolynomial As Integer = &amp;HEDB88320\r\n            Dim DWCRC As Integer\r\n            Dim i As Integer, j As Integer, n As Integer\r\n\r\n            'Create CRC32 Table\r\n            For i = 0 To 255\r\n                DWCRC = i\r\n                For j = 8 To 1 Step -1\r\n                    If (DWCRC And 1) Then\r\n                        DWCRC = ((DWCRC And &amp;HFFFFFFFE) \\ 2&amp;) And &amp;H7FFFFFFF\r\n                        DWCRC = DWCRC Xor DWPolynomial\r\n                    Else\r\n                        DWCRC = ((DWCRC And &amp;HFFFFFFFE) \\ 2&amp;) And &amp;H7FFFFFFF\r\n                    End If\r\n                Next j\r\n                CRC32Table(i) = DWCRC\r\n            Next i\r\n\r\n            'Calcualting CRC32 Hash\r\n            Do While (Count &gt; 0)\r\n                For i = 0 To Count - 1\r\n                    n = (CRC32Result And &amp;HFF) Xor Buffer(i)\r\n                    CRC32Result = ((CRC32Result And &amp;HFFFFFF00) \\ &amp;H100) And &amp;HFFFFFF\r\n                    CRC32Result = CRC32Result Xor CRC32Table(n)\r\n                Next i\r\n                Count = FS.Read(Buffer, 0, ReadSize)\r\n            Loop\r\n            Return Hex(Not (CRC32Result))\r\n        Catch ex As Exception\r\n            Return \"\"\r\n        End Try\r\n    End Function\r\n   \r\n    Private Sub form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load\r\n        With ListView1\r\n            .View = View.Details\r\n            .FullRowSelect = True\r\n            .MultiSelect = False\r\n            .HideSelection = False\r\n            .LabelEdit = False\r\n            .Columns.Add(\"Archivo\", 150)\r\n            .Columns.Add(\"KBs\", 60)\r\n            .Columns.Add(\"CRC32\", 70)\r\n            .Columns.Add(\"Ruta\", 120)\r\n        End With\r\n        '\r\n        Me.Text = \"Encriptador [\" &amp; Application.ProductVersion &amp; \"]\"\r\n        '\r\n    End Sub\r\n    \r\n    Private Sub ListView1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles ListView1.DragDrop\r\n        Try\r\n            If e.Data.GetDataPresent(DataFormats.FileDrop) Then\r\n                Dim filePaths As String() = CType(e.Data.GetData(DataFormats.FileDrop), String())\r\n                For Each filePath As String In filePaths\r\n                    'Compruebo duplicados\r\n                    For i = 0 To ListView1.Items.Count - 1\r\n                        If ListView1.Items(i).SubItems(2).Text = CRC32(filePath) Then\r\n                            duplicado = True\r\n                        End If\r\n                    Next\r\n                    If duplicado = False Then\r\n                        Dim chkExt As String = My.Computer.FileSystem.GetFileInfo(filePath).Extension\r\n                        Dim chkSize As String = My.Computer.FileSystem.GetFileInfo(filePath).Length\r\n                        chkSize = chkSize \/ 1024\r\n                        Dim d As Decimal\r\n                        d = Decimal.Round(chkSize, 2, MidpointRounding.AwayFromZero)\r\n                        Dim LI As ListViewItem\r\n                        LI = ListView1.Items.Add(My.Computer.FileSystem.GetFileInfo(filePath).Name)\r\n                        LI.StateImageIndex = 0\r\n                        LI.SubItems.Add(d &amp; \" KB\")\r\n                        LI.SubItems.Add(CRC32(filePath))\r\n                        LI.SubItems.Add(filePath)\r\n                    End If\r\n                    duplicado = False\r\n                Next filePath\r\n            End If\r\n        Catch ex As Exception\r\n            MsgBox(\"Ocurri\u00f3 el siguiente error: \" &amp; ex.Message.ToString)\r\n        End Try\r\n    End Sub\r\n    \r\n    Private Sub ListView1_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles ListView1.DragEnter\r\n        If e.Data.GetDataPresent(DataFormats.FileDrop) Then\r\n            e.Effect = DragDropEffects.Copy\r\n        Else\r\n            e.Effect = DragDropEffects.None\r\n        End If\r\n    End Sub\r\n    \r\n    Private Function Copiar(ByVal path As String, ByVal path2 As String) As Boolean\r\n        Dim sr As New IO.FileStream(path, IO.FileMode.Open, FileAccess.Read) 'lugar de origen\r\n        Dim sw As New IO.FileStream(path2, IO.FileMode.Create, FileAccess.ReadWrite) 'lugar de destino\r\n        Dim len As Long = sr.Length - 1\r\n        For i As Long = 0 To len\r\n            sw.WriteByte(sr.ReadByte)\r\n            If i Mod 1000 = 0 Then\r\n                pbstatus.Value = i * 100 \/ len\r\n                Application.DoEvents()\r\n            End If\r\n        Next\r\n        pbstatus.Value = 0\r\n        sr.Close()\r\n        sr.Dispose()\r\n        sw.Close()\r\n        sw.Dispose()\r\n        Return True\r\n    End Function\r\n    \r\n    Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click\r\n        'BOT\u00d3N ENCRIPTAR\r\n        Try\r\n            If txtpw.Text &lt;&gt; \"\" And txtpw.TextLength &gt; 5 Then\r\n                If ListView1.Items.Count &gt; 0 Then\r\n                    Me.Cursor = Cursors.WaitCursor\r\n                    Application.DoEvents()\r\n                    For i = 0 To ListView1.Items.Count - 1\r\n                        ruta = ListView1.Items(i).SubItems(3).Text\r\n                        rutabak = ListView1.Items(i).SubItems(3).Text &amp; \"_enc\"\r\n                        Do While Copiar(ruta, rutabak) = False\r\n                            'espere\r\n                        Loop\r\n                        Dim bytKey As Byte()\r\n                        Dim bytIV As Byte()\r\n                        bytKey = CreateKey(txtpw.Text)\r\n                        bytIV = CreateIV(txtpw.Text)\r\n                        EncryptOrDecryptFile(ruta, rutabak, bytKey, bytIV, CryptoAction.ActionEncrypt)\r\n                        '\r\n                    Next\r\n                Else\r\n                    MsgBox(\"Lista de archivos vac\u00eda\")\r\n                End If\r\n            Else\r\n                MsgBox(\"Clave no v\u00e1lida\" &amp; vbNewLine &amp; \"Debe tener al menos 6 d\u00edgitos\")\r\n            End If\r\n            Me.Cursor = Cursors.Default\r\n            Application.DoEvents()\r\n        Catch ex As Exception\r\n            MsgBox(\"Ocurri\u00f3 el siguiente error: \" &amp; ex.Message.ToString)\r\n            Me.Cursor = Cursors.Default\r\n            Application.DoEvents()\r\n        End Try\r\n    End Sub\r\n    \r\n    Private Sub Button2_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click\r\n        'BOT\u00d3N DES-ENCRIPTAR\r\n        Try\r\n            If txtpw.Text &lt;&gt; \"\" And txtpw.TextLength &gt; 5 Then\r\n                If ListView1.Items.Count &gt; 0 Then\r\n                    For i = 0 To ListView1.Items.Count - 1\r\n                        Me.Cursor = Cursors.WaitCursor\r\n                        Application.DoEvents()\r\n                        ruta = ListView1.Items(i).SubItems(3).Text\r\n                        'rutabak = ListView1.Items(i).SubItems(3).Text &amp; \"_enc\"\r\n                        rutabak = ruta.Remove(ruta.Length - 4)\r\n                        Do While Copiar(ruta, rutabak) = False\r\n                            'espere\r\n                        Loop\r\n                        'DecryptFile(ruta, rutabak, txtpw.Text)\r\n                        '\r\n                        Dim bytKey As Byte()\r\n                        Dim bytIV As Byte()\r\n                        bytKey = CreateKey(txtpw.Text)\r\n                        bytIV = CreateIV(txtpw.Text)\r\n                        EncryptOrDecryptFile(ruta, rutabak, bytKey, bytIV, CryptoAction.ActionDecrypt)\r\n                    Next\r\n                Else\r\n                    MsgBox(\"Lista de archivos vac\u00eda\")\r\n                End If\r\n            Else\r\n                MsgBox(\"Clave no v\u00e1lida\" &amp; vbNewLine &amp; \"Debe tener al menos 6 d\u00edgitos\")\r\n            End If\r\n            Me.Cursor = Cursors.Default\r\n            Application.DoEvents()\r\n        Catch ex As Exception\r\n            MsgBox(ex.Message.ToString)\r\n            Me.Cursor = Cursors.Default\r\n            Application.DoEvents()\r\n        End Try\r\n    End Sub\r\n    \r\n    Private Sub btn_vaciar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_vaciar.Click\r\n        'BOT\u00d3N VACIAR\r\n        ListView1.Items.Clear()\r\n        pbstatus.Value = 0\r\n    End Sub\r\n\r\n    Private Sub ListView1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles ListView1.KeyDown\r\n        Try\r\n            If e.KeyCode = Keys.Delete Then\r\n                For Each i As ListViewItem In ListView1.SelectedItems\r\n                    ListView1.Items.Remove(i)\r\n                Next\r\n            End If\r\n        Catch ex As Exception\r\n            MsgBox(ex.Message.ToString)\r\n        End Try\r\n    End Sub\r\n    \r\n#Region \"1. Global Variables \"\r\n\r\n    '*************************\r\n    '** Global Variables\r\n    '*************************\r\n\r\n    Dim strFileToEncrypt As String\r\n    Dim strFileToDecrypt As String\r\n    Dim strOutputEncrypt As String\r\n    Dim strOutputDecrypt As String\r\n    Dim fsInput As System.IO.FileStream\r\n    Dim fsOutput As System.IO.FileStream\r\n\r\n#End Region\r\n\r\n#Region \"2. Create A Key \"\r\n\r\n    '*************************\r\n    '** Create A Key\r\n    '*************************\r\n\r\n    Private Function CreateKey(ByVal strPassword As String) As Byte()\r\n        Dim chrData() As Char = strPassword.ToCharArray\r\n        Dim intLength As Integer = chrData.GetUpperBound(0)\r\n        Dim bytDataToHash(intLength) As Byte\r\n        For i As Integer = 0 To chrData.GetUpperBound(0)\r\n            bytDataToHash(i) = CByte(Asc(chrData(i)))\r\n        Next\r\n        Dim SHA512 As New System.Security.Cryptography.SHA512Managed\r\n        Dim bytResult As Byte() = SHA512.ComputeHash(bytDataToHash)\r\n        'Declare bytKey(31).  It will hold 256 bits.\r\n        Dim bytKey(31) As Byte\r\n        For i As Integer = 0 To 31\r\n            bytKey(i) = bytResult(i)\r\n        Next\r\n        Return bytKey 'Return the key.\r\n    End Function\r\n\r\n#End Region\r\n\r\n#Region \"3. Create An IV \"\r\n\r\n    '*************************\r\n    '** Create An IV\r\n    '*************************\r\n\r\n    Private Function CreateIV(ByVal strPassword As String) As Byte()\r\n        Dim chrData() As Char = strPassword.ToCharArray\r\n        Dim intLength As Integer = chrData.GetUpperBound(0)\r\n        Dim bytDataToHash(intLength) As Byte\r\n        For i As Integer = 0 To chrData.GetUpperBound(0)\r\n            bytDataToHash(i) = CByte(Asc(chrData(i)))\r\n        Next\r\n        Dim SHA512 As New System.Security.Cryptography.SHA512Managed\r\n        'Declare bytResult, Hash bytDataToHash and store it in bytResult.\r\n        Dim bytResult As Byte() = SHA512.ComputeHash(bytDataToHash)\r\n        'Declare bytIV(15).  It will hold 128 bits.\r\n        Dim bytIV(15) As Byte\r\n        For i As Integer = 32 To 47\r\n            bytIV(i - 32) = bytResult(i)\r\n        Next\r\n        Return bytIV 'return the IV\r\n    End Function\r\n\r\n#End Region\r\n\r\n\r\n#Region \"4. Encrypt \/ Decrypt File \"\r\n\r\n    '****************************\r\n    '** Encrypt\/Decrypt File\r\n    '****************************\r\n\r\n    Private Enum CryptoAction\r\n        ActionEncrypt = 1\r\n        ActionDecrypt = 2\r\n    End Enum\r\n\r\n    Private Sub EncryptOrDecryptFile(ByVal strInputFile As String, _\r\n                                     ByVal strOutputFile As String, _\r\n                                     ByVal bytKey() As Byte, _\r\n                                     ByVal bytIV() As Byte, _\r\n                                     ByVal Direction As CryptoAction)\r\n        Try\r\n            fsInput = New System.IO.FileStream(strInputFile, FileMode.Open, _\r\n                                               FileAccess.Read)\r\n            fsOutput = New System.IO.FileStream(strOutputFile, FileMode.OpenOrCreate, _\r\n                                                FileAccess.Write)\r\n            fsOutput.SetLength(0) 'make sure fsOutput is empty\r\n            Dim bytBuffer(4096) As Byte 'holds a block of bytes for processing\r\n            Dim lngBytesProcessed As Long = 0 'running count of bytes processed\r\n            Dim lngFileLength As Long = fsInput.Length 'the input file's length\r\n            Dim intBytesInCurrentBlock As Integer 'current bytes being processed\r\n            Dim csCryptoStream As CryptoStream\r\n            'Declare your CryptoServiceProvider.\r\n            Dim cspRijndael As New System.Security.Cryptography.RijndaelManaged\r\n            pbStatus.Value = 0\r\n            pbStatus.Maximum = 100\r\n\r\n            Select Case Direction\r\n                Case CryptoAction.ActionEncrypt\r\n                    csCryptoStream = New CryptoStream(fsOutput, _\r\n                    cspRijndael.CreateEncryptor(bytKey, bytIV), _\r\n                    CryptoStreamMode.Write)\r\n\r\n                Case CryptoAction.ActionDecrypt\r\n                    csCryptoStream = New CryptoStream(fsOutput, _\r\n                    cspRijndael.CreateDecryptor(bytKey, bytIV), _\r\n                    CryptoStreamMode.Write)\r\n            End Select\r\n\r\n            While lngBytesProcessed &lt; lngFileLength\r\n                'Read file with the input filestream.\r\n                intBytesInCurrentBlock = fsInput.Read(bytBuffer, 0, 4096)\r\n                'Write output file with the cryptostream.\r\n                csCryptoStream.Write(bytBuffer, 0, intBytesInCurrentBlock)\r\n                'Update lngBytesProcessed\r\n                lngBytesProcessed = lngBytesProcessed + CLng(intBytesInCurrentBlock)\r\n                'Update Progress Bar\r\n                pbStatus.Value = CInt((lngBytesProcessed \/ lngFileLength) * 100)\r\n            End While\r\n\r\n            csCryptoStream.Close()\r\n            fsInput.Close()\r\n            fsOutput.Close()\r\n\r\n            If Direction = CryptoAction.ActionEncrypt Then\r\n                Dim fileOriginal As New FileInfo(strFileToEncrypt)\r\n                fileOriginal.Delete()\r\n            End If\r\n\r\n            If Direction = CryptoAction.ActionDecrypt Then\r\n                Dim fileEncrypted As New FileInfo(strFileToDecrypt)\r\n                fileEncrypted.Delete()\r\n            End If\r\n\r\n            Dim Wrap As String = Chr(13) + Chr(10)\r\n            If Direction = CryptoAction.ActionEncrypt Then\r\n                MsgBox(\"Encryption Complete\" + Wrap + Wrap + _\r\n                        \"Total bytes processed = \" + _\r\n                        lngBytesProcessed.ToString, _\r\n                        MsgBoxStyle.Information, \"Done\")\r\n                pbStatus.Value = 0\r\n            Else\r\n                pbStatus.Value = 0\r\n            End If\r\n\r\n\r\n            'Catch file not found error.\r\n        Catch When Err.Number = 53 'if file not found\r\n            MsgBox(\"Please check to make sure the path and filename\" + _\r\n                    \"are correct and if the file exists.\", _\r\n                     MsgBoxStyle.Exclamation, \"Invalid Path or Filename\")\r\n\r\n        Catch\r\n            fsInput.Close()\r\n            fsOutput.Close()\r\n\r\n        End Try\r\n    End Sub\r\n\r\n#End Region\r\nEnd Class<\/pre>\n<h2><span class=\"ez-toc-section\" id=\"Video\"><\/span>V\u00eddeo<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>https:\/\/youtu.be\/6NksaI0SAA8<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Enlaces\"><\/span>Enlaces<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<ul>\n<li id=\"ctl00_ArticleTitle\"><a href=\"https:\/\/www.codeproject.com\/Articles\/12092\/Encrypt-Decrypt-Files-in-VB-NET-Using-Rijndael\" target=\"_blank\" rel=\"noopener\">Encrypt\/Decrypt Files in VB.NET (Using Rijndael)<\/a><\/li>\n<li><a href=\"https:\/\/es.wikipedia.org\/wiki\/Advanced_Encryption_Standard\" target=\"_blank\" rel=\"noopener\">Advanced Encryption Standard<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Intro Aqu&iacute; teneis un sencillo encriptador\/desencriptador multi-archivo implementando el algoritmo de encriptaci&oacute;n Rijndael de 256 bits. El encriptador est&aacute; basado en el c&oacute;digo de&nbsp;Thad Van den Bosch. Simplemente abre un nuevo proyecto e introduce 3 botones, un ListView, una caja de texto y una barra de progreso. Atenci&oacute;n: Si no se utiliza la misma clave al desencriptar, el proceso de desencriptado se completa pero el archivo resultante ser&aacute; ilegible. C&oacute;digo Imports System Imports System.IO Imports System.Security Imports System.Security.Cryptography Public Class&#8230;<\/p>\n<p class=\"read-more\"><a class=\"btn btn-default\" href=\"https:\/\/garikoitz.info\/blog\/2018\/01\/encriptador-desencriptador-net\/\"> Leer m\u00e1s<span class=\"screen-reader-text\">  Leer m\u00e1s<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":372,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","wpupg_custom_link":[],"wpupg_custom_link_behaviour":[],"wpupg_custom_link_nofollow":[],"wpupg_custom_image":[],"wpupg_custom_image_id":[],"footnotes":""},"categories":[37],"tags":[40,44,43,42,41,38,39],"class_list":["post-368","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-net","tag-net","tag-aes","tag-crc32","tag-desencriptar","tag-encriptar","tag-rijndael","tag-visual-basic"],"_links":{"self":[{"href":"https:\/\/garikoitz.info\/blog\/wp-json\/wp\/v2\/posts\/368","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/garikoitz.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/garikoitz.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/garikoitz.info\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/garikoitz.info\/blog\/wp-json\/wp\/v2\/comments?post=368"}],"version-history":[{"count":7,"href":"https:\/\/garikoitz.info\/blog\/wp-json\/wp\/v2\/posts\/368\/revisions"}],"predecessor-version":[{"id":379,"href":"https:\/\/garikoitz.info\/blog\/wp-json\/wp\/v2\/posts\/368\/revisions\/379"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/garikoitz.info\/blog\/wp-json\/wp\/v2\/media\/372"}],"wp:attachment":[{"href":"https:\/\/garikoitz.info\/blog\/wp-json\/wp\/v2\/media?parent=368"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/garikoitz.info\/blog\/wp-json\/wp\/v2\/categories?post=368"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/garikoitz.info\/blog\/wp-json\/wp\/v2\/tags?post=368"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}