Class AsymmetricEncryption
Inheritance
Namespace: Sensus.Encryption
Assembly: SensusAndroid.dll
Syntax
public class AsymmetricEncryption : Object, IEncryptor, IEnvelopeEncryptor
Constructors
AsymmetricEncryption(String)
Initializes a new instance of the AsymmetricEncryption class.
Declaration
public AsymmetricEncryption(string publicKeyString)
Parameters
Type | Name | Description |
---|---|---|
System.String | publicKeyString | Public key string. Can be generated following the generation of the private key (see below) using the following command: openssl rsa -in private.pem -outform PEM -pubout -out public.pem |
AsymmetricEncryption(String, String)
Initializes a new instance of the AsymmetricEncryption class.
Declaration
public AsymmetricEncryption(string publicKeyString, string privateKeyString)
Parameters
Type | Name | Description |
---|---|---|
System.String | publicKeyString | Public key string. Can be generated following the generation of the private key (see below) using the following command: openssl rsa -in private.pem -outform PEM -pubout -out public.pem |
System.String | privateKeyString | Private key string. Only necessary if you want to be able to decrypt using this object. Can be generated with the following commands: openssl genrsa -des3 -out private.pem 2048 openssl pkcs8 -topk8 -nocrypt -in private.pem |
Methods
DecryptToBytes(Byte[])
Declaration
public byte[] DecryptToBytes(byte[] encryptedBytes)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | encryptedBytes |
Returns
Type | Description |
---|---|
System.Byte[] |
DecryptToString(Byte[], Encoding)
Declaration
public string DecryptToString(byte[] encryptedBytes, Encoding encoding)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | encryptedBytes | |
System.Text.Encoding | encoding |
Returns
Type | Description |
---|---|
System.String |
Encrypt(Byte[])
Declaration
public byte[] Encrypt(byte[] unencryptedBytes)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | unencryptedBytes |
Returns
Type | Description |
---|---|
System.Byte[] |
Encrypt(String, Encoding)
Declaration
public byte[] Encrypt(string unencryptedValue, Encoding encoding)
Parameters
Type | Name | Description |
---|---|---|
System.String | unencryptedValue | |
System.Text.Encoding | encoding |
Returns
Type | Description |
---|---|
System.Byte[] |
EnvelopeAsync(Byte[], Int32, Int32, Stream, CancellationToken)
Encrypts bytes asymmetrically via symmetric encryption. Since asymmetric encryption does not support large data sizes, the approach is to generate a symmetric encryption key that is designed for large data sizes, encrypt the data with the symmetric key, encrypt the symmetric key with the asymmetric key, and send everything to output.
Declaration
public Task EnvelopeAsync(byte[] unencryptedBytes, int symmetricKeySizeBits, int symmetricInitializationVectorSizeBits, Stream encryptedOutputStream, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | unencryptedBytes | Unencrypted bytes. |
System.Int32 | symmetricKeySizeBits | Symmetric key size in bits. |
System.Int32 | symmetricInitializationVectorSizeBits | Symmetric initialization vector size in bits. |
System.IO.Stream | encryptedOutputStream | Encrypted output stream. |
System.Threading.CancellationToken | cancellationToken | Cancellation token. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task |