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.
private string EnryptString(string strEncrypted)
byte b = System.Text.ASCIIEncoding.ASCII.GetBytes(strEncrypted);
string encryptedConnectionString = Convert.ToBase64String(b);
private string DecryptString(string encrString)
byte b = Convert.FromBase64String(encrString);
string decryptedConnectionString = System.Text.ASCIIEncoding.ASCII.GetString(b);
Private Function EnryptString(ByVal strEncrypted As String) As String
Dim b As Byte() = System.Text.ASCIIEncoding.ASCII.GetBytes(strEncrypted)
Dim encryptedConnectionString As String = Convert.ToBase64String(b)
Private Function DecryptString(ByVal encrString As String) As String
Dim b As Byte() = Convert.FromBase64String(encrString)
Dim decryptedConnectionString As String = System.Text.ASCIIEncoding.ASCII.GetString(b)
Hi friend, i have error while using your Decryption function...
Hi D.Jeya kumar,
I don't know what idea you have about encryption and decryption. But the codes that you have posted are not at all encryption/decryption leave alone simple.
What is posted here is simply text conversions like what you have done here is converted to Base64 format, similarly there are UTF32,UTF7,UTF8, and many more.
Encryption/decryption always comes with the terms "passwords"/"keys". That means you have a data(it can be file, simple text,etc ) and you encrypt/decrypt that data with a password or key.
Encryption is a technique and we can use any technique to encrypt or decrypt the given text. It is not specific that you need to have a key to encrypt and decrypt the string. If you want to you can use your own method to encrypt or decrypt.
Read the topic again. It is a simple encryption or decryption technique.
Hi D.Jeya kumar,
I do not want to upset you.
But the definition that you have written is not complete,
If you are talking about encryption "key" has to be mentioned.
I will show you examples too.
check this link in wikipedia: http://en.wikipedia.org/wiki/Encryption
Where itself in first line its mentioned that without a special knowledge otherwise refered as key you wont be able to encrypt or decrypt a plain text.
check this link also: http://www.howstuffworks.com/encryption.htm
where the exact defination mentioned is " encryption, the process of encoding information in such a way that only the person with the key can decode it."
All the definition or references of encryption/decryption contains the term "key" which is very important part of the encryption/decryption process, if the concept of key is removed its not encryption/decryption.
It will only be "text conversion" with out key or password.
You should correct this out.
string decryptedConnectionString = System.Text.UnicodeEncoding.Unicode.GetString(b);