Click here to Skip to main content
15,889,860 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How I can encrypt a text in vb.net?
For example I want to encrypt the text of d.txt.
How I can do it?
Posted

encrypting-a-text-in-vbnet[^]

Hope it will help...
 
Share this answer
 
For this you can read the Data from file in a string var,
after this you can Encrypt this

public string EncryptData(string ClearText)
{
byte[] keyArray;
byte[] EncryptString= UTF8Encoding.UTF8.GetBytes(ClearText);

System.Configuration.AppSettingsReader settingsReader = new AppSettingsReader();

string key ="Securekey";
'Above secure key is a key that can be in config file, You can specify any key of your wish

MD5CryptoServiceProvider hashmd5 = new MD5CryptoServiceProvider();
keyArray = hashmd5.ComputeHash(UTF8Encoding.UTF8.GetBytes(key));
hashmd5.Clear();

TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider();
tdes.Key = keyArray;
tdes.Mode = CipherMode.ECB;
tdes.Padding = PaddingMode.PKCS7;

ICryptoTransform cTransform = tdes.CreateEncryptor();
byte[] resultArray = cTransform.TransformFinalBlock(EncryptString, 0, EncryptString.Length);
tdes.Clear();
return Convert.ToBase64String(resultArray, 0, resultArray.Length);
}

With this above method you can encrypt data.
I hope its clear for you to implement this
 
Share this answer
 
v3

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900