Hi Keyrun
plz copy and paste algo written below and call it. will work fine
any problem contact on
REMOVED@gmail.com
regards,
satan singh
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Text;
using System.Security.Cryptography;
namespace MSIS.SPH.Common
{
public class EncryptionDecryption
{
private static string Encrypt(string plainText, string passPhrase, string saltValue, string hashAlgorithm, int passwordIterations, string initVector, int keySize)
{
byte[] initVectorBytes = null;
initVectorBytes = Encoding.ASCII.GetBytes(initVector);
byte[] saltValueBytes = null;
saltValueBytes = Encoding.ASCII.GetBytes(saltValue);
byte[] plainTextBytes = null;
plainTextBytes = Encoding.UTF8.GetBytes(plainText);
PasswordDeriveBytes password = default(PasswordDeriveBytes);
password = new PasswordDeriveBytes(passPhrase, saltValueBytes, hashAlgorithm, passwordIterations);
byte[] keyBytes = null;
keyBytes = password.GetBytes(keySize / 8);
RijndaelManaged symmetricKey = default(RijndaelManaged);
symmetricKey = new RijndaelManaged();
symmetricKey.Mode = CipherMode.CBC;
ICryptoTransform encryptor = default(ICryptoTransform);
encryptor = symmetricKey.CreateEncryptor(keyBytes, initVectorBytes);
MemoryStream memoryStream = default(MemoryStream);
memoryStream = new MemoryStream();
CryptoStream cryptoStream = default(CryptoStream);
cryptoStream = new CryptoStream(memoryStream, encryptor, CryptoStreamMode.Write);
cryptoStream.Write(plainTextBytes, 0, plainTextBytes.Length);
cryptoStream.FlushFinalBlock();
byte[] cipherTextBytes = null;
cipherTextBytes = memoryStream.ToArray();
memoryStream.Close();
cryptoStream.Close();
string cipherText = null;
cipherText = Convert.ToBase64String(cipherTextBytes);
return cipherText;
}
private static string Decrypt(string cipherText, string passPhrase, string saltValue, string hashAlgorithm, int passwordIterations, string initVector, int keySize)
{
byte[] initVectorBytes = null;
initVectorBytes = Encoding.ASCII.GetBytes(initVector);
byte[] saltValueBytes = null;
saltValueBytes = Encoding.ASCII.GetBytes(saltValue);
byte[] cipherTextBytes = null;
cipherTextBytes = Convert.FromBase64String(cipherText);
PasswordDeriveBytes password = default(PasswordDeriveBytes);
password = new PasswordDeriveBytes(passPhrase, saltValueBytes, hashAlgorithm, passwordIterations);
byte[] keyBytes = null;
keyBytes = password.GetBytes(keySize / 8);
RijndaelManaged symmetricKey = default(RijndaelManaged);
symmetricKey = new RijndaelManaged();
symmetricKey.Mode = CipherMode.CBC;
ICryptoTransform decryptor = default(ICryptoTransform);
decryptor = symmetricKey.CreateDecryptor(keyBytes, initVectorBytes);
MemoryStream memoryStream = default(MemoryStream);
memoryStream = new MemoryStream(cipherTextBytes);
CryptoStream cryptoStream = default(CryptoStream);
cryptoStream = new CryptoStream(memoryStream, decryptor, CryptoStreamMode.Read);
byte[] plainTextBytes = new byte[cipherTextBytes.Length];
int decryptedByteCount = 0;
decryptedByteCount = cryptoStream.Read(plainTextBytes, 0, plainTextBytes.Length);
memoryStream.Close();
cryptoStream.Close();
string plainText = null;
plainText = Encoding.UTF8.GetString(plainTextBytes, 0, decryptedByteCount);
return plainText;
}
public static string EncryptValue(string strString)
{
if (string.IsNullOrEmpty(strString.Trim())) return "";
string strplainText = null;
string strcipherText = null;
string strpassPhrase = null;
string strsaltValue = null;
string strhashAlgorithm = null;
int intpasswordIterations = 0;
string strinitVector = null;
int intkeySize = 0;
strplainText = strString;
strpassPhrase = "Pas5pr@se";
strsaltValue = "s@1tValue";
strhashAlgorithm = "SHA1";
intpasswordIterations = 2;
strinitVector = "@1B2c3D4e5F6g7H8";
intkeySize = 256;
strcipherText = Encrypt(strplainText, strpassPhrase, strsaltValue, strhashAlgorithm, intpasswordIterations, strinitVector, intkeySize);
return strcipherText;
}
public static string DecryptValue(string strString)
{
if (string.IsNullOrEmpty(strString.Trim())) return "";
string strplainText = null;
string strcipherText = null;
string strpassPhrase = null;
string strsaltValue = null;
string strhashAlgorithm = null;
int intpasswordIterations = 0;
string strinitVector = null;
int intkeySize = 0;
strplainText = strString;
strpassPhrase = "Pas5pr@se";
strsaltValue = "s@1tValue";
strhashAlgorithm = "SHA1";
intpasswordIterations = 2;
strinitVector = "@1B2c3D4e5F6g7H8";
intkeySize = 256;
strcipherText = Decrypt(strplainText, strpassPhrase, strsaltValue, strhashAlgorithm, intpasswordIterations, strinitVector, intkeySize);
return strcipherText;
}
}
}</br></br></br></br>