carlst99.Rc4Sharp
3.0.0
I was very uncertain of where to leave the design of the library. I've already modified it far too many times to align with my personal project goals. Hence, I've decided to unlist this package. You can find a simplified implementation here, should it be of use: https://gist.github.com/carlst99/c4ddec1963b3189acbe8d3127860b241
dotnet add package carlst99.Rc4Sharp --version 3.0.0
NuGet\Install-Package carlst99.Rc4Sharp -Version 3.0.0
<PackageReference Include="carlst99.Rc4Sharp" Version="3.0.0" />
paket add carlst99.Rc4Sharp --version 3.0.0
#r "nuget: carlst99.Rc4Sharp, 3.0.0"
// Install carlst99.Rc4Sharp as a Cake Addin #addin nuget:?package=carlst99.Rc4Sharp&version=3.0.0 // Install carlst99.Rc4Sharp as a Cake Tool #tool nuget:?package=carlst99.Rc4Sharp&version=3.0.0
Rc4Sharp
A managed .NET Standard 2.1 implementation of the RC4 stream cipher. Verified against the test vectors on the RC4 Wikipedia page.
Usage
Installation
You can install Rc4Sharp from NuGet.
# .NET CLI
dotnet add package carlst99.Rc4Sharp
# Visual Studio Package Manager
Install-Package carlst99.Rc4Sharp
Transforming Buffers
The Rc4Cipher
class can be used to apply the RC4 cipher to byte buffers. It acts as the default implementation of the IRc4Cipher
interface.
To use it, you must first initialize it with an array of bytes containing your key data. Note that this key buffer must be at least one byte in length.
using Rc4Sharp;
// Don't actually use this as a key
const string key = "Secret!";
byte[] keyData = Encoding.ASCII.GetBytes(key);
byte[] toEncrypt = Encoding.ASCII.GetBytes("plaintext");
// The output buffer must always be at
// least as long as the input buffer
byte[] encryptedData = new byte[toEncrypt.Length];
using Rc4Cipher encrypter = new(keyData);
encrypter.Transform(toEncrypt, encryptedData);
Transforming Streams
The Rc4Stream
can be used to apply the RC4 cipher to a stream of data. It uses the Rc4Cipher
class under the hood, although a constructor overload is provided where you can pass in any object that implements the IRc4Cipher
interface.
using Rc4Sharp;
Stream dataStream = new MemoryStream();
using Rc4Stream encrypter = new(dataStream, keyData);
// Reads data from the underlying stream and
// applys the cipher to the output buffer
encrypter.Read(...);
// Applys the cipher to a copy of the input buffer
// then writes it to the underlying stream
encrypter.Write(...);
Note that the Rc4Stream
will dispose of its underlying stream when Dispose
is called. If you'd like to change this, set the disposeUnderlying
constructor parameter to false
.
using Rc4Stream encrypter = new Rc4Stream(stream, keyData, disposeUnderlying: false);
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 was computed. 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. |
.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.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|
Target .NET Standard 2.1