demo_encriptación_datos

11

Click here to load reader

Upload: dirk-rose

Post on 28-Jan-2018

128 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: DEMO_Encriptación_datos

Encriptación de datos

Asegurando nuestra información

Page 2: DEMO_Encriptación_datos

Introducción

Las aplicaciones Web muy a menudo necesitan almacenar datos sensibles, como las conexiones a las bases de datos o las credenciales de una cuenta de usuario en archivos de configuración. Por razones de seguridad, este tipo de información nunca debe ser almacenada en texto plano y siempre debe ser cifrada antes de su almacenamiento.

Page 3: DEMO_Encriptación_datos

Objetivos

En este módulo aprenderemos a: • Utilizar la clase librería que encapsula las

llamadas a la Data Protection API (DPAPI) contenida en “Crypt32.dll” para cifrar y descifrar datos.

• Cifrar las cadenas de conexión y almacenarlas en el Web.config

• Crear una aplicación Web para cifrar y descifrar datos.

Page 4: DEMO_Encriptación_datos

Requerimientos

• Imports System.Text

• Imports Dataprotection

Las referencias a emplear son:

Page 5: DEMO_Encriptación_datos

Referencia y uso de Crypt32.dll para DPAPI

Creación del proyecto Dataprotection que emplea la librería DPAPIWin32® Data Protection API (DPAPI).

Una de las caracteristicas de DPAPI es que maneja las llavesde cifrado por nosotros.

Page 6: DEMO_Encriptación_datos

Pantalla de pruebas

Page 7: DEMO_Encriptación_datos

Cifrando cadenasPrivate Sub btnEncrypt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEncrypt.Click Dim dp As New DataProtector(DataProtector.Store.USE_MACHINE_STORE) Try Dim dataToEncrypt() As Byte = Encoding.ASCII.GetBytes(txtDataToEncrypt.Text) txtEncryptedData.Text = Convert.ToBase64String(dp.Encrypt(dataToEncrypt, Nothing)) Catch ex As Exception lblError.ForeColor = Color.Red lblError.Text = "Exception.<br>" + ex.Message Return End Try lblError.Text = "" End Sub

Page 8: DEMO_Encriptación_datos

Descifrando cadenas

Private Sub btnDecrypt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDecrypt.Click Dim dp As New DataProtector(DataProtector.Store.USE_MACHINE_STORE) Try Dim dataToDecrypt() As Byte = Convert.FromBase64String(txtEncryptedData.Text) txtDecryptedData.Text = Encoding.ASCII.GetString(dp.Decrypt(dataToDecrypt, Nothing)) Catch ex As Exception lblError.ForeColor = Color.Red lblError.Text = "Exception.<br>" + ex.Message Return End Try lblError.Text = "" End Sub

Page 9: DEMO_Encriptación_datos

Descifrando valores establecidos en Config.Web

<appSettings>

<add key="connectionString" value="AQAAANCMnd8BFdERjHoAwE/Cl+sBAAAAn5RQ1aAJME2AMmEpBWkVlgQAAAACAAAAAAADZgAAqAAAABAAAACwMLkvl305PsddA94tM4E8AAAAAASAAACgAAAAEAAAAN+WvQ7eCbS3W3aZ1X8SEytIAAAAUwjfzcZvNVs4Bp439waR13/T5tWYSdh/4nvuC1NO/0JWFrmW1ve19U6GPjxzxJo6QhUWdW8g0267d/GuUpZXnYDWjuOl9gEnFAAAAA1H2b97Jaz4+YXpYthxSlDZXQLY" />

</appSettings>

En el archivo Web.Config

Page 10: DEMO_Encriptación_datos

Descifrando valores establecidos en Config.Web

Private Sub btnDecryptConfig_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDecryptConfig.Click Dim dp As New DataProtector(DataProtector.Store.USE_MACHINE_STORE) Try Dim appSettingValue As String = ConfigurationSettings.AppSettings("connectionString") Dim dataToDecrypt() As Byte = Convert.FromBase64String(appSettingValue) txtDecryptedData.Text = Encoding.ASCII.GetString(dp.Decrypt(dataToDecrypt, Nothing)) Catch ex As Exception lblError.ForeColor = Color.Red lblError.Text = "Exception.<br>" + ex.Message Return End Try lblError.Text = "" End Sub

Page 11: DEMO_Encriptación_datos

DEMO

http://localhost/DPAPIClientWeb/WebForm1.aspx