Rainbow.CSharp.SDK.Cryptography
1.5.0
.NET 8.0
This package targets .NET 8.0. The package is compatible with this framework or higher.
.NET Standard 2.0
This package targets .NET Standard 2.0. The package is compatible with this framework or higher.
dotnet add package Rainbow.CSharp.SDK.Cryptography --version 1.5.0
NuGet\Install-Package Rainbow.CSharp.SDK.Cryptography -Version 1.5.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Rainbow.CSharp.SDK.Cryptography" Version="1.5.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Rainbow.CSharp.SDK.Cryptography" Version="1.5.0" />
<PackageReference Include="Rainbow.CSharp.SDK.Cryptography" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Rainbow.CSharp.SDK.Cryptography --version 1.5.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Rainbow.CSharp.SDK.Cryptography, 1.5.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Rainbow.CSharp.SDK.Cryptography@1.5.0
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Rainbow.CSharp.SDK.Cryptography&version=1.5.0
#tool nuget:?package=Rainbow.CSharp.SDK.Cryptography&version=1.5.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Provides ability to create objects implementing SASLMechanism.
These objects handle the SCRAM mechanism of SASL.
No strings are allocated during challenge. Only client-side mechanisms are provided.
Based on https://github.com/stazz/FluentCryptography and https://github.com/stazz/UtilPack
Code has been reworked:
- to only support SCRAM-SHA-1, SCRAM-SHA-256 and SCRAM-SHA-512
- to support .Net standard 2.0, 2.1, .Net 6.0 and .Net 8.0
Unnecessary code has been removed.
Example of use:
var credentials = new SASLCredentialsSCRAMForClient(
userName,
password // password may be clear-text password as string, or result of PBKDF2 iteration as byte array.
);
String type = "SCRAM-SHA-512"; // To define which encryption must be used
switch (type)
{
case "SCRAM-SHA-1":
var sha1 = new Rainbow.Cryptography.Digest.SHA128();
client = sha1.CreateSASLClientSCRAM();
break;
case "SCRAM-SHA-256":
var sha256 = new Rainbow.Cryptography.Digest.SHA256();
client = sha256.CreateSASLClientSCRAM();
break;
case "SCRAM-SHA-512":
var sha512 = new Rainbow.Cryptography.Digest.SHA512();
client = sha512.CreateSASLClientSCRAM();
break;
}
var encoding = new UTF8Encoding(false, false).CreateDefaultEncodingInfo();
var writeArray = new ResizableArray<Byte>();
var firstMessageToServer = Convert.ToBase64String( ComputeInitialResponse());
// => Need to send the first message to the server and read it's answer
var firstMessageFromServer = "..."; // <= Here it's the content of the server reponse
byte[] data = Convert.FromBase64String(firstMessageFromServer);
var secondMessageToServer = Convert.ToBase64String( ComputeFinalResponse(data));
// => Need to send the second message to the server and read it's answer
var secondMessageFromServer = "..."; // <= Here it's the content of the server reponse
data = Convert.FromBase64String(secondMessageFromServer);
VerifyServerSignature(data); // => If no exception, the authentication process is a success
private byte[] ComputeInitialResponse()
{
var challengeArguments = credentials.CreateChallengeArguments(
null, // Initial phase does not read anything
-1,
-1,
writeArray,
0,
encoding
);
try
{
var task = client.ChallengeOrThrowOnErrorAsync(challengeArguments);
(var bytesWritten, var challengeResult) = task.Result;
if (bytesWritten > 0)
{
byte[] result = new byte[bytesWritten];
Array.Copy(writeArray.Array, result, bytesWritten);
return result;
}
}
catch
{
}
return new byte[0];
}
private byte[] ComputeFinalResponse(byte[] challenge)
{
var challengeArguments = credentials.CreateChallengeArguments(
challenge,
0,
challenge.Length,
writeArray,
0,
encoding
);
try
{
var task = client.ChallengeOrThrowOnErrorAsync(challengeArguments);
(var bytesWritten, var challengeResult) = task.Result;
if (bytesWritten > 0)
{
byte[] result = new byte[bytesWritten];
Array.Copy(writeArray.Array, result, bytesWritten);
return result;
}
}
catch
{
}
return new byte[0];
}
private byte[] VerifyServerSignature(byte[] challenge)
{
var challengeArguments = credentials.CreateChallengeArguments(
challenge,
0,
challenge.Length,
writeArray,
0,
encoding
);
var task = client.ChallengeOrThrowOnErrorAsync(challengeArguments);
(var bytesWritten, var challengeResult) = task.Result;
if(challengeResult == SASLChallengeResult.Completed)
return new byte[0];
throw new Exception("Server signature has not been verified with success");
}
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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 was computed. 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 was computed. 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 | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- System.Threading.Tasks.Extensions (>= 4.5.4)
-
.NETStandard 2.1
- No dependencies.
-
net10.0
- No dependencies.
-
net8.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.