Click here to Skip to main content
15,892,537 members
Articles / Programming Languages / Visual Basic

Encrypting a dataset using AES, including compression

Rate me:
Please Sign up or sign in to vote.
4.98/5 (49 votes)
21 Aug 2015CPOL7 min read 127K   4.8K   127  
Article describes how to encrypt a dataset using AES. Optionally the dataset is compressed before the encryption.
''' <summary>
''' This class calculates a linear gradient brush to represent the password strength
''' </summary>
Public Class ForegroundConverter
   Implements System.Windows.Data.IValueConverter
   ''' <summary>
   ''' Converts a value. 
   ''' </summary>
   ''' <param name="value">The password strength (0 to 100)</param>
   ''' <param name="targetType">The type of the binding target property.</param>
   ''' <param name="parameter">The converter parameter to use.</param>
   ''' <param name="culture">The culture to use in the converter.</param>
   ''' <returns>A brush that paints an area with a linear gradient. </returns>
   Public Function Convert(value As Object, targetType As System.Type, parameter As Object, culture As System.Globalization.CultureInfo) _
      As Object _
      Implements System.Windows.Data.IValueConverter.Convert

      Dim strength As Double = value
      Dim brush As System.Windows.Media.LinearGradientBrush = New System.Windows.Media.LinearGradientBrush()

      brush.StartPoint = New System.Windows.Point(0, 0.5)
      brush.EndPoint = New System.Windows.Point(1, 0.5)

      If (strength <= 33) Then
         brush.GradientStops.Add(New System.Windows.Media.GradientStop(System.Windows.Media.Colors.Red, 0))
      ElseIf (strength <= 66) Then
         brush.GradientStops.Add(New System.Windows.Media.GradientStop(System.Windows.Media.Colors.Red, 0))
         brush.GradientStops.Add(New System.Windows.Media.GradientStop(System.Windows.Media.Colors.Yellow, (1 / strength) * 33))
      Else
         brush.GradientStops.Add(New System.Windows.Media.GradientStop(System.Windows.Media.Colors.Red, 0))
         brush.GradientStops.Add(New System.Windows.Media.GradientStop(System.Windows.Media.Colors.Yellow, (1 / strength) * 33))
         brush.GradientStops.Add(New System.Windows.Media.GradientStop(System.Windows.Media.Colors.Green, ((1 / strength) * 33) * 2))
      End If

      Return brush
   End Function

   ''' <summary>
   ''' Converts a value. 
   ''' </summary>
   ''' <param name="value">The value that is produced by the binding target.</param>
   ''' <param name="targetType">The type to convert to.</param>
   ''' <param name="parameter">The converter parameter to use.</param>
   ''' <param name="culture">The culture to use in the converter.</param>
   ''' <returns>Never returns a value</returns>
   ''' <exception cref="System.NotImplementedException">Thrown always</exception>
   Public Function ConvertBack(value As Object, targetType As Type, parameter As Object, culture As System.Globalization.CultureInfo) _
      As Object _
      Implements System.Windows.Data.IValueConverter.ConvertBack

      Throw New System.NotImplementedException()
   End Function
End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
Europe Europe
Biography provided

Comments and Discussions