Despues de casi 6 meses que habia dejado de escribir en mi blog, ahora vuelvo con un articulo que me parecio bastante interesante…
Lo que hace este pequeño codigo es encriptar el querystring de una URL,bueno espero que les sea util este articulo.

Imports System
Imports System.IO
Imports System.Xml
Imports System.Text
Imports System.Security.Cryptography

Public Class Encryption64
Private key() As Byte = {}
Private IV() As Byte = {&H12&H34&H56&H78&H90&HAB&HCD&HEF}

 Public Function Decrypt(ByVal stringToDecrypt As String_
      ByVal sEncryptionKey As StringAs String
      Dim inputByteArray(stringToDecrypt.LengthAs Byte
       Try
      key = System.Text.Encoding.UTF8.GetBytes(Left(sEncryptionKey8))
       Dim des As New DESCryptoServiceProvider()
       inputByteArray = Convert.FromBase64String(stringToDecrypt)
       Dim ms As New MemoryStream()
       Dim cs As New CryptoStream(msdes.CreateDecryptor(keyIV), _
         CryptoStreamMode.Write)
          cs.Write(inputByteArray0inputByteArray.Length)
          cs.FlushFinalBlock()
      Dim encoding As System.Text.Encoding = System.Text.Encoding.UTF8
          Return encoding.GetString(ms.ToArray())
      Catch e As Exception
          Return e.Message
      End Try
   End Function

   Public Function Encrypt(ByVal stringToEncrypt As String_
       ByVal SEncryptionKey As StringAs String
       Try
      key = System.Text.Encoding.UTF8.GetBytes(Left(SEncryptionKey8))
          Dim des As New DESCryptoServiceProvider()
          Dim inputByteArray() As Byte = Encoding.UTF8.GetBytes_
              stringToEncrypt)
          Dim ms As New MemoryStream()
        Dim cs As New CryptoStream(msdes.CreateEncryptor(keyIV), _
              CryptoStreamMode.Write)
          cs.Write(inputByteArray0inputByteArray.Length)
          cs.FlushFinalBlock()
          Return Convert.ToBase64String(ms.ToArray())
      Catch e As Exception
          Return e.Message
      End Try
   End Function

End Class

comentarios
  1. B dice:

    interesante post sobre seguridad. si tienes más temitas sueltos sobre encriptación y seguridad en logueos también te agradecería si publicas algunos articulos sobre eso. bytes

  2. Andres dice:

    Sabes que con algunos valores da error y no se por que ? me dice que
    [System.FormatException] = {«Longitud no válida para una matriz de caracteres Base-64.»}

    los valores que encripto son 2 , 5 , 8 no eh probado mas pero con esos se cae

  3. razzieel dice:

    Hola funciona bien solo la cadena key tiene q ser de mas d 8 caracteres (sEncryptionKey)… por ej «123456789»

    Pero me queda la duda si al encryptar no manda un «&» en la cadena ya q esto tronaria el querystring.. lo han considerado?

  4. Juan dice:

    Muchas gracias por el script…

  5. Leo54 dice:

    Muy buen post, muchas gracias por la rutina, estuve investigando algunas maneras para encriptar el querystring, inclusive descargue algunas dlls, pero en su mayoria eran muy inestables, necesitabas muchas validaciones y mucho recurso en el server… esta clase es muy sencilla de implementar y usar … de nuevo gracias…

    Saludos

  6. Carlos dice:

    Oigan que buena rutina la verdad, gracias por la ayuda a quien publico esto

  7. Excelente post acerca de la seguridad !

  8. Israel Jovel dice:

    me parece muy bien el post pero yo soy nuevo en esto y quisiera que me explicaran mas sobre como implementarlo.. gracias

  9. mavrodi dice:

    I feel this is one of the most significant information for me.
    And i am happy reading your article. But want to commentary on some basic things, The site style is perfect,
    the articles is truly excellent : D. Good task, cheers

  10. malaysia mmm dice:

    naturally like your web-site but you have to test the spelling on quite a few of your posts.

    A number of them are rife with spelling problems and I in finding it very bothersome
    to tell the reality on the other hand I will definitely come again again.

  11. Edgar dice:

    buen artículo, pero por favor un ejemplo de invocar a url y cómo recuperar sus valores desde la otra página. Gracias

Deja un comentario