C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » Encryption »

Simple String Encryption and Decryption in .net(C# and VB.NET)


Posted Date: 25 Jun 2009    Resource Type: Code Snippets    Category: Encryption
Author: D.Jeya kumar(JK)Member Level: Diamond    
Rating: 1 out of 5Points: 15



Hi All,


Some times we need to encrypt a string or password for some reason.For that we can use the below encryption and decryption technique. it can be used for simple and less secured strings.


C#
private string EnryptString(string strEncrypted)
{
try
{
byte[] b = System.Text.ASCIIEncoding.ASCII.GetBytes(strEncrypted);
string encryptedConnectionString = Convert.ToBase64String(b);
return encryptedConnectionString;
}
catch
{
throw;
}
}

private string DecryptString(string encrString)
{
try
{
byte[] b = Convert.FromBase64String(encrString);
string decryptedConnectionString = System.Text.ASCIIEncoding.ASCII.GetString(b);
return decryptedConnectionString;
}
catch
{
throw;
}
}

VB.NET



Private Function EnryptString(ByVal strEncrypted As String) As String
Try
Dim b As Byte() = System.Text.ASCIIEncoding.ASCII.GetBytes(strEncrypted)
Dim encryptedConnectionString As String = Convert.ToBase64String(b)
Return encryptedConnectionString
Catch
Throw
End Try
End Function

Private Function DecryptString(ByVal encrString As String) As String
Try
Dim b As Byte() = Convert.FromBase64String(encrString)
Dim decryptedConnectionString As String = System.Text.ASCIIEncoding.ASCII.GetString(b)
Return decryptedConnectionString
Catch
Throw
End Try
End Function




Regards
JK



Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Simple Technique to Encrypt and Decrypt in .net  .  Encryption and Decryption in .net  .  Convert a string to FromBase64String  .  Convert a FromBase64String string to ASCII  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Encrypting and Decripting values using Security Key
Previous Resource: Encryption and Decryption of Password using VB.NET
Return to Discussion Resource Index
Post New Resource
Category: Encryption


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use