Common encryption and decryption logic required by various KS FIKS clients on the dotnet platform. All code is released under a MIT license
All crypto is performed using a portable C# version of the BouncyCastle library
- This library targets .Net Core 3.1 as well as .Net Standard 2.1
- A PEM file containing the BASE64 encoded public certificate to be used for encryption
- A PEM file containing the BASE64 encoded private key to be used for decryption
var encryptionService = EncryptionService.Create(/* public certificate */);
using (var encryptedOutStream = /* create out stream */)
using (var dataStream = /* the stream containing the unencrypted data */)
{
encryptionService.Encrypt(dataStream, encryptedOutStream);
}
var decryptionService = DecryptionService.Create(/* private key */);
using (var encryptedDataInStream = /* stream containing the encrypted data */)
using (var decryptedOutStream = /* a stream to write the unencrypted data to */)
using (var decryptBufferStream = decryptionService.Decrypt(encryptedDataInStream))
{
decryptBufferStream.CopyTo(decryptedOutStream);
}