Creating a simple class to encrypt strings


This code will help you to create class to encrypt strings

A simple namespace is created below for all your encryption requirements in the application


Imports System.Security.Cryptography
Imports System.Text
Imports System.Text.RegularExpressions

Namespace ASPNET.Handheld
Public Class Security

'*********************************************************************
'
' Security.Encrypt() Method
'
' The Encrypt method encryts a clean string into a hashed string
'
'*********************************************************************

Public Shared Function Encrypt(ByVal cleanString As String) As String
Dim clearBytes As [char]()
clearBytes = New UnicodeEncoding().GetBytes(cleanString)
Dim hashedBytes As [Byte]() = CType(CryptoConfig.CreateFromName("MD5"), HashAlgorithm).ComputeHash(clearBytes)
Dim hashedText As String = BitConverter.ToString(hashedBytes)
Return hashedText
End Function
End Class
End Namespace


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: