Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Part 2: SharePoint : Think before You Pass Your Parameters in Query String Format
WhatsApp
Ketak Bhalsing
10y
3.7
k
0
0
25
Blog
We have discussed about the problem and how to deal with it in
Part 1: SharePoint : Think before You Pass Your Parameters in Query String Format
).
Here I will brief you about how to handle it on destination Side. As we saw we have done an encryption using a key ; now we need to use the same key to decrypt the information from Encrypted text.For this firstly we need to fetch the information from Query String and then decode this using UrlDecode of HttpUtility class.
Please find below is the helper method to encrypt parameters:
using
System.Security.Cryptography;
private
string
Decrypt(
string
cipherText)
{
string
EncryptionKey =
"MAKV2SPBNI99212"
;
cipherText = cipherText.Replace(
" "
,
"+"
);
byte
[] cipherBytes = Convert.FromBase64String(cipherText);
using
(Aes encryptor = Aes.Create())
{
Rfc2898DeriveBytes pdb =
new
Rfc2898DeriveBytes(EncryptionKey,
new
byte
[] { 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76 });
encryptor.Key = pdb.GetBytes(32);
encryptor.IV = pdb.GetBytes(16);
using
(MemoryStream ms =
new
MemoryStream())
{
using
(CryptoStream cs =
new
CryptoStream(ms, encryptor.CreateDecryptor(), CryptoStreamMode.Write))
{
cs.Write(cipherBytes, 0, cipherBytes.Length);
cs.Close();
}
cipherText = Encoding.Unicode.GetString(ms.ToArray());
}
}
return
cipherText;
}
Here is how we need to call this method:
string
Location =
"SharepointUserLocation"
;
string
LoggedInUser =
"SharepointUser"
;
string
EncryptedLocation = Encrypt(HttpUtility.UrlEncode(Location .Trim()));
string
EncryptedLoggedInUser = Encrypt(HttpUtility.UrlEncode(LoggedInUser.Trim()));
string
Encrypted =
string
.Format(
"~/page.aspx?Location={0}&LoggedInUser={1}"
, EncryptedLocation , EncryptedLoggedInUser);
string
decryptedLocation = Decrypt(HttpUtility.UrlDecode(EncryptedLocation));
string
decryptedLoggedInUser = Decrypt(HttpUtility.UrlDecode(EncryptedLoggedInUser));
string
decrypted =
string
.Format(
"~/page.aspx?Location={0}&LoggedInUser={1}"
, decryptedLocation, decryptedLoggedInUser);
Happy SharePointing !!!
Up Next
Selecting Value of Field Based on Query String URL Using JQuery in SharePoint 2013
Ebook Download
View all
SharePoint Framework (SPFx) A Developers Guide
Read by 11.1k people
Download Now!
Learn
View all
Membership not found