Asymmetric Crypter class. This class implements RSA public key encryption. Public key means that a message encrypted with a recipient's public key cannot be decrypted by anyone except the recipient possessing the corresponding private key. To make such encryption, AsymmetricCrypter implements RSA algorithm. Since this algorithm is relatively computationally costly in comparison with many symmetric key algorithms of equivalent security, AsymmetricCrypter implements an hybrid asymmetric/symmetric cryptosystem for reasons of efficiency; in such a cryptosystem, a shared secret key ("session key") is generated by one party and this much briefer session key is then encrypted by each recipient's public key. Each recipient uses the corresponding private key to decrypt the session key. The message is then encrypted with a symmetric algorithm ciphered with the session key. This is why the constructor of AsymmetricCrypter takes in input a SupportedStreamAlgorithms object, to determine the symmetric algorithm that will be used to encrypt the message. Instead, the random generated key is ciphered with RSA algorithm. This class also offers some utility methods to acquire public and private keys from certificates or external files in several formats, such as: CER, PEM or XML.

Namespace: LLCryptoLib.Crypto
Assembly: LLCryptoLib (in LLCryptoLib.dll) Version: 2.0.1024.0 (2.0.1024)

Syntax

C#
public class AsymmetricCrypter
Visual Basic
Public Class AsymmetricCrypter
Visual C++
public ref class AsymmetricCrypter

Examples

Encryption code:
CopyC#
AsymmetricCrypter ac = new AsymmetricCrypter(SupportedStreamAlgorithms.BLOWFISH256);
RSA pubKey = AsymmetricCrypter.LoadKeyFromXmlFile(PUBLIC_KEY);
// or RSA pubKey = AsymmetricCrypter.LoadPublicKeyFromCER(PUBLIC_KEY_CER);
ac.Encrypt(new FileInfo(INPUT_FILE), new FileInfo(ENCRYPTED_FILE), pubKey);

Examples

Decryption code:
CopyC#
string storeName = "MyCA";
string certificateName = "Alice";
RSA privateKey = AsymmetricCrypter.LoadPrivateKey(StoreLocation.CurrentUser, storeName, certificateName);  
AsymmetricCrypter ac = new AsymmetricCrypter(SupportedStreamAlgorithms.BLOWFISH256);
ac.Decrypt(new FileInfo(ENCRYPTED_FILE), new FileInfo(DECRYPTED_FILE), privateKey);

Inheritance Hierarchy

System..::..Object
  LLCryptoLib.Crypto..::..AsymmetricCrypter

See Also