Every time I try new encryption algorithm to get encrypted string and use it in QUeryString I face a problem of generating not clean string (string that doesn't contain (+) sign and (/) ).
I want to use it in ASP.NET MVC.
Isn't there a way to encrypt a string avoiding these signs ?.
I'm encrypting a string (either if it is a valid query string or not it shouldn't matter) then I append this string to a URL I have
EDIT 1: Here's the encrypting code:
public string Encrypt(string inputText, string key = "", string salt = "")
{
key = !string.IsNullOrEmpty(key) ? key : EncryptionKey;
salt = !string.IsNullOrEmpty(salt) ? salt : EncryptionSalt;
byte[] plainText = Encoding.UTF8.GetBytes(inputText);
using (RijndaelManaged rijndaelCipher = new RijndaelManaged())
{
PasswordDeriveBytes secretKey = new PasswordDeriveBytes(Encoding.ASCII.GetBytes(key), Encoding.ASCII.GetBytes(salt));
using (ICryptoTransform encryptor = rijndaelCipher.CreateEncryptor(secretKey.GetBytes(32), secretKey.GetBytes(16)))
{
using (MemoryStream memoryStream = new MemoryStream())
{
using (CryptoStream cryptoStream = new CryptoStream(memoryStream, encryptor, CryptoStreamMode.Write))
{
cryptoStream.Write(plainText, 0, plainText.Length);
cryptoStream.FlushFinalBlock();
string base64 = Convert.ToBase64String(memoryStream.ToArray());
// Generate a string that won't get screwed up when passed as a query string.
string urlEncoded = HttpUtility.UrlEncode(base64);
return urlEncoded;
}
}
}
}
}
EDIT 2:
Example of the encoded string:
1|6
Just like that, And I want to receive it by a string argument in ASP.NET MVC action.