SoftCircuits.QueryArgumentEncryptor
3.0.0
Prefix Reserved
dotnet add package SoftCircuits.QueryArgumentEncryptor --version 3.0.0
NuGet\Install-Package SoftCircuits.QueryArgumentEncryptor -Version 3.0.0
<PackageReference Include="SoftCircuits.QueryArgumentEncryptor" Version="3.0.0" />
<PackageVersion Include="SoftCircuits.QueryArgumentEncryptor" Version="3.0.0" />
<PackageReference Include="SoftCircuits.QueryArgumentEncryptor" />
paket add SoftCircuits.QueryArgumentEncryptor --version 3.0.0
#r "nuget: SoftCircuits.QueryArgumentEncryptor, 3.0.0"
#:package SoftCircuits.QueryArgumentEncryptor@3.0.0
#addin nuget:?package=SoftCircuits.QueryArgumentEncryptor&version=3.0.0
#tool nuget:?package=SoftCircuits.QueryArgumentEncryptor&version=3.0.0
QueryArgumentEncryptor
Install-Package SoftCircuits.QueryArgumentEncryptor
QueryArgumentEncryptor makes it easy to pass private data as a URL query argument.
When passing data as a query argument in a URL, sometimes that data contains sensitive information that you do not want to expose to the user. In addition, sometimes it is important to ensure that data is not tampered with. For example, if a query argument contained an ID associated with the current user, someone could edit the ID and potentially expose information for another user.
QueryArgumentEncryptor solves both issues by converting any number of key/value pairs into a single, encrypted string. The data is encrypted using AES-256-GCM, which provides both confidentiality and built-in tamper detection — if the encrypted string is modified in any way, or decrypted with the wrong password, decryption fails.
Using the Class
QueryArgumentEncryptor derives from Dictionary<string, string>. So you can add data to it using the Dictionary class' methods and properties.
ArgumentEncryptor args = new ArgumentEncryptor("Password123");
args.Add("Key1", "Value1");
args.Add("Key2", "Value2");
Next, use the EncryptData() method to encrypt everything into a single string. By default, the encrypted string will be URL encoded. You can set the urlEncode argument to override this.
string url = string.Format("http://www.mydomain.com?data={0}", encryptor.EncryptData());
The page receiving this URL request can then reconstitute the original data from the query argument. (Obviously, the password must match the one used to create the argument.)
string arg = /* Value of query argument */
// Note: An exception is thrown if the password or data is invalid.
ArgumentEncryptor args = new ArgumentEncryptor("Password123", arg);
// Get some data
string s = args["Key1"];
If you'd rather not have an exception thrown for invalid data, use TryDecryptData() instead:
ArgumentEncryptor args = new ArgumentEncryptor("Password123");
if (args.TryDecryptData(arg))
{
// Data was valid
string s = args["Key1"];
}
Version Compatibility
Starting with version 3.0, this library uses a new, stronger encryption format (AES-256-GCM in place of the previous algorithm). Encrypted strings produced by version 2.x cannot be decrypted by version 3.0 or later, and vice versa.
If your application has previously issued long-lived URLs containing encrypted query arguments (for example, links emailed to users or saved for later use), those links will stop working once you upgrade to version 3.0. Consider this before upgrading if such links may still be in use, and plan to regenerate or expire them as needed.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- No dependencies.
-
net10.0
- No dependencies.
-
net6.0
- No dependencies.
-
net7.0
- No dependencies.
-
net8.0
- No dependencies.
-
net9.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version 3.0: Now uses AES-256-GCM encryption in place of the previous algorithm, providing stronger security and built-in tamper detection. Now targets .NET Standard 2.1 and .NET 6.0 through .NET 10.0 (previously .NET Standard 2.0 and .NET 5.0).
BREAKING CHANGE: Encrypted strings produced by version 2.x cannot be decrypted by this version, and vice versa. If your application has issued long-lived URLs containing encrypted query arguments, they will stop working after this upgrade.