-
Notifications
You must be signed in to change notification settings - Fork 0
api crypto
The cryptography interface is defined in the MKW.Cryptography library.
To begin using the cryptography API, please reference the following assemblies:
MKW.CommonMKW.CryptographyMKW.Cryptography.Loader
Please reference to the MKW.Cryptography.Loader library, which will
help loading the cryptography provider based on the platform and user
configuration.
Use one of the following code snippets to load a cryptography provider:
// Loads default cryptography provider (recommended).
var crypto = CryptographyLoader.GetProvider();
// Loads MKW.Cryptography.BouncyCastle cryptography provider.
var cryptoBouncyCastle = CryptographyLoader.GetProvider(BouncyCastleLoader.Name);
// Loads MKW.Cryptography.System cryptography provider.
// Note: won't work in .NET Framework projects.
var cryptoSystem = CryptographyLoader.GetProvider(SystemCryptographyLoader.Name);Through the ICryptographyProvider interface, you can access the following
cryptographic operations:
- Symmetric operations
- Key generation
- Encryption
- Decryption
- Asymmetric operations (public key cryptography)
- Encryption
- Decryption
- Signature generation
- Signature verification
- Secret key derivation from text password
- Random bytes generation
Follow the ICryptographyProvider.cs file more.
Please name the project as MKW.Cryptography.<CryptoLibrary>.
Reference the following assemblies:
-
MKW.Common(optional) -
MKW.Cryptography(the interfaces) -
MKW.Cryptography.Loader(TODO: to register loader)
Create a class that implements the MKW.Cryptography.ICryptographyProvider
interface. This is like the host of the provider.
Then add separate classes for each functionality, implementing the following interfaces:
ISymmetricTransformer-
IAsymmetricPrivateTransformer+IAsymmetricPublicTransformer IUserCredentialsIRandomGenerator
For each class, make them hidden for external assemblies by changing class
modifier to internal, hide the constructor by changing its visibility to
private or protected and create static methods Create and Open
taking all the information needed to initialize the object. The
ICryptographyProvider implementation should refer to these methods.
This is not yet implemented in the loader, so currently the only option is to
manually modify the MKW.Cryptography.Loader library, and introducing
supporting the module.
The MKW.Cryptography.Tests project contains a bunch of test cases. It
also checks compatibility between different modules to ensure the client will
work the same way no matter which crypto provider is currently in use.
Just modify the test matrix of the test fixtures, by adding yours.