rskibbe.Encryption – An infrastructure for encoding / decoding things

rskibbe.Encryption - A common base infrastructure package for things that depend on encryption
rskibbe.Encryption – A common base infrastructure package for things that depend on encryption

What is rskibbe.Encryption?

In software development you most likely want to create a clean and easy maintainable code base. With „rskibbe.Encryption“ you create that common base infrastructure for things that depend on encryption processes like encoding / decoding. Just imagine this package being installed and telling your (for example) viewmodels or services: „Hey, you depend on something, which is able to encode / encrypt data / both“ or „Hey, you will get something, which is able to decode data“.

Write your custom implementation for that (or install the available ones) and boom – no need to have 10 different types in your projects, which all actually should refer to a common base. For sure, there will be more sub-packages later!

Quick example

A quick example for rskibbe.Encryption based encryption
A quick example for rskibbe.Encryption based encryption

Step 1 – Install the package

Open the NuGet Package Manager and execute the following commands (or install it by GUI). This command will install the package to enable you using its code.

Install-Package rskibbe.Encryption

Step 2 – Install existing or create manual implementations

Remember: „rskibbe.Encryption“ is only a base package, that is used, to create a common infrastructure between apps. There will be more sub-packages coming – but feel (of course) free to create your own implementations.

Existing implementations

If you just want to get it going with like Base64, take a look at for example „rskibbe.Encryption.Base64“ for the Base64 „IEncryptor“ interface implementation.

Custom implementation

After installing the base package, you can now start implementing the things required for the interfaces. Please make sure, to check out the detailed explanation to understand the things behind this package. There could be different approaches, like if you only want something, which is able to decode something, just implement the „IDecoder“ interface. If – on the other hand – you need something which is able to encode and decode, then implement the „IEncryptor“ interface. You could then use typical DI to inject your dependencies into the target models, services, etc.

Step 3 – Use the implementation

After you either downloaded an existing implementation like the „rskibbe.Encryption.Base64“ or implemented your own one. Create an instance and call the corresponding „Encode“, „Decode“ methods on the object.

Detailed explanation

Infrastructure Diagram for classes and interfaces – rskibbe.Encryption
Infrastructure Diagram for classes and interfaces – rskibbe.Encryption

If you take a look at the diagram / image, you can see some things explaining the library in more detail. I mean, it’s not that big anyways, but… As this is only an infrastructure, you won’t see any implementation / model classes. Only the exception classes are (more or less provided) to be directly used – the exception, hah.

Common conception:

The idea behind this package is to structure the (soon) following things when talking about encryption. Keep in mind, that the term „encryption“ isn’t to be mixed with the term „hashing“! Back to the encryption side of things, there are:

  • „things“ being able to encode data
  • „things“ being able to decode data
  • and „things“ being able to do both tasks combined


The most common task when talking about „encryption“ would be the encoding / encryption of provided data. So I called the thing which is able to „encode“ data – Encoder. Therefore, the „IEncoder“ interface came to life having only this one method „Encode“.


In terms of encryption (again – not hashing!) you wouldn’t have pretty much out of it, when you can encode things but never getting them back to the original. This is where the term „Decoder“ and the corresponding interface „IDecoder“ are coming into play. As the name suggests, a decoder has only one job – decoding things! Therefore the interface „IDecoder“ came to life.


In the end, there will be „things“ that can do both works – encoding and also decoding. I called them „Encryptors“ in my little world here. I was racking my brain to find a better term for it, but couldn’t. I though about something like „Cypher“, „XyManager“ but these sucked even more, so…


For sure, there can be and will be things going wrong. Some may lead to a fatal exit of your app, some aren’t that bad. I’ve added two base classes for Exception handling, signaling: „Hey, there went something wrong encoding / decoding your provided data“. You can therefore throw an „EncodingException“ when something went wrong while encoding and a „DecodingException“ for decoding problems.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert