Find Code:
All Words
Any of the Words
Exact Phrase
Home
:
Code
:
Forums
:
Submit
:
Mailing List
:
About
:
Contact
Code
All
VB.NET
ASP.NET
C#
VB Classic
ASP Classic
Snippets
Popular
Resources
Submit Code
Forums
Articles
Tips
Links
Books
Contest
Link to us
A class for all your encryption needs
Author:
Nikhil
E-mail:
Click to e-mail author
Submitted:
10/4/2004
Version:
VB.NET
Compatibility:
VB.NET
Category:
Security
Views:
31568
This is a class for all your secutity needs ! This contains methods to encrypt and decrypt any given string. So if you wanna pass something like an employee id or a password in the query string, feed it to this class once, get it encryted and then have no fear !!
Declarations:
'none
Code:
Imports System.Text Imports System.Collections.Specialized Imports System.Security.Cryptography Public Class Security Private lbtVector() As Byte = {240, 3, 45, 29, 0, 76, 173, 59} Private lscryptoKey As String = "ChangeThis!" Public Function psDecrypt(ByVal sQueryString As String) As String Dim buffer() As Byte Dim loCryptoClass As New TripleDESCryptoServiceProvider Dim loCryptoProvider As New MD5CryptoServiceProvider Try buffer = Convert.FromBase64String(sQueryString) loCryptoClass.Key = loCryptoProvider.ComputeHash(ASCIIEncoding.ASCII.GetBytes(lscryptoKey)) loCryptoClass.IV = lbtVector Return Encoding.ASCII.GetString(loCryptoClass.CreateDecryptor().TransformFinalBlock(buffer, 0, buffer.Length())) Catch ex As Exception Throw ex Finally loCryptoClass.Clear() loCryptoProvider.Clear() loCryptoClass = Nothing loCryptoProvider = Nothing End Try End Function 'Author : Nikhil Gupta 'Description : This function encrypts a given string 'Parameters : String 'Return Values: Encrypted String 'Called From : Business Layer Public Function psEncrypt(ByVal sInputVal As String) As String Dim loCryptoClass As New TripleDESCryptoServiceProvider Dim loCryptoProvider As New MD5CryptoServiceProvider Dim lbtBuffer() As Byte Try lbtBuffer = System.Text.Encoding.ASCII.GetBytes(sInputVal) loCryptoClass.Key = loCryptoProvider.ComputeHash(ASCIIEncoding.ASCII.GetBytes(lscryptoKey)) loCryptoClass.IV = lbtVector sInputVal = Convert.ToBase64String(loCryptoClass.CreateEncryptor().TransformFinalBlock(lbtBuffer, 0, lbtBuffer.Length())) psEncrypt = sInputVal Catch ex As CryptographicException Throw ex Catch ex As FormatException Throw ex Catch ex As Exception Throw ex Finally loCryptoClass.Clear() loCryptoProvider.Clear() loCryptoClass = Nothing loCryptoProvider = Nothing End Try End Function End Class
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2024 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement