ICryptographyService Interface
Provides functions to encrypt and decrypt data, as well as signing data and verifying signatures.
public interface ICryptographyServiceFields
Section titled “Fields”ICryptographyService.DEFAULT_CERTIFICATE_NAME Field
Section titled “ICryptographyService.DEFAULT_CERTIFICATE_NAME Field”The default certificate name used when no specific certificate name is provided.
const string DEFAULT_CERTIFICATE_NAME = "Default";Field Value
Section titled “Field Value”Methods
Section titled “Methods”ICryptographyService.Decrypt(byte[], string, CancellationToken) Method
Section titled “ICryptographyService.Decrypt(byte[], string, CancellationToken) Method”Tries to load a certificate with the given certificateName then decrypts the given data with the private key from found certificate.
System.Threading.Tasks.Task<byte[]> Decrypt(byte[] data, string certificateName="Default", System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));Parameters
Section titled “Parameters”data System.Byte[]
The encrypted data, which will be decrypted.
certificateName System.String
The name of the certificate containing the private key, which will be used for the decryption.
cancellationToken System.Threading.CancellationToken
A System.Threading.CancellationToken used to interrupt the async method.
Returns
Section titled “Returns”System.Threading.Tasks.Task<System.Byte[]>
A System.Threading.Tasks.Task containing the decrypted System.Byte array.
ICryptographyService.Decrypt(byte[], X509Certificate2) Method
Section titled “ICryptographyService.Decrypt(byte[], X509Certificate2) Method”Decrypts the encrypted data with the private key from the given certificate.
byte[] Decrypt(byte[] data, System.Security.Cryptography.X509Certificates.X509Certificate2 certificate);Parameters
Section titled “Parameters”data System.Byte[]
The encrypted data, which will be decrypted.
certificate System.Security.Cryptography.X509Certificates.X509Certificate2
The certificate containing the private key, which will be used for the decryption.
Returns
Section titled “Returns”System.Byte[]
The decrypted data.
ICryptographyService.DecryptBase64(string, string, CancellationToken) Method
Section titled “ICryptographyService.DecryptBase64(string, string, CancellationToken) Method”Tries to load a certificate with the given certificateName then decrypts the given base64String with the private key from found certificate.
System.Threading.Tasks.Task<byte[]> DecryptBase64(string base64String, string certificateName="Default", System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));Parameters
Section titled “Parameters”base64String System.String
The encrypted base64 encoded string.
certificateName System.String
The name of the certificate containing the private key, which will be used for the decryption.
cancellationToken System.Threading.CancellationToken
A System.Threading.CancellationToken used to interrupt the async method.
Returns
Section titled “Returns”System.Threading.Tasks.Task<System.Byte[]>
A System.Threading.Tasks.Task containing the decrypted System.Byte array.
ICryptographyService.Encrypt(byte[], string, CancellationToken) Method
Section titled “ICryptographyService.Encrypt(byte[], string, CancellationToken) Method”Tries to load a certificate with the given certificateName then encrypts the given data with the public key from found certificate.
System.Threading.Tasks.Task<byte[]> Encrypt(byte[] data, string certificateName="Default", System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));Parameters
Section titled “Parameters”data System.Byte[]
The data, which will be encrypted.
certificateName System.String
The name of the certificate containing the public key, which will be used for the encryption.
cancellationToken System.Threading.CancellationToken
A System.Threading.CancellationToken used to interrupt the async method.
Returns
Section titled “Returns”System.Threading.Tasks.Task<System.Byte[]>
A System.Threading.Tasks.Task containing the encrypted System.Byte array.
ICryptographyService.Encrypt(byte[], X509Certificate2) Method
Section titled “ICryptographyService.Encrypt(byte[], X509Certificate2) Method”Encrypts the given data with the public key from the given certificate.
byte[] Encrypt(byte[] data, System.Security.Cryptography.X509Certificates.X509Certificate2 certificate);Parameters
Section titled “Parameters”data System.Byte[]
The data, which will be encrypted.
certificate System.Security.Cryptography.X509Certificates.X509Certificate2
The certificate containing the public key, which will be used for the encryption.
Returns
Section titled “Returns”System.Byte[]
A System.Byte array, which represents the encrypted data.
ICryptographyService.EncryptBase64(byte[], string, CancellationToken) Method
Section titled “ICryptographyService.EncryptBase64(byte[], string, CancellationToken) Method”Tries to load a certificate with the given certificateName then encrypts the given data with the public key from found certificate.
System.Threading.Tasks.Task<string> EncryptBase64(byte[] data, string certificateName="Default", System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));Parameters
Section titled “Parameters”data System.Byte[]
The data, which will be encrypted.
certificateName System.String
The name of the certificate containing the public key, which will be used for the encryption.
cancellationToken System.Threading.CancellationToken
A System.Threading.CancellationToken used to interrupt the async method.
Returns
Section titled “Returns”System.Threading.Tasks.Task<System.String>
A System.Threading.Tasks.Task containing the base64 encoded representation of the encrypted byte array.
ICryptographyService.Sign(byte[], string, CancellationToken) Method
Section titled “ICryptographyService.Sign(byte[], string, CancellationToken) Method”Tries to load a certificate with the given certificateName then signs the given data with the private key from found certificate.
System.Threading.Tasks.Task<byte[]> Sign(byte[] data, string certificateName="Default", System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));Parameters
Section titled “Parameters”data System.Byte[]
The data, which will be signed.
certificateName System.String
The name of the certificate containing the private key, which will be used for the signature.
cancellationToken System.Threading.CancellationToken
A System.Threading.CancellationToken used to interrupt the async method.
Returns
Section titled “Returns”System.Threading.Tasks.Task<System.Byte[]>
A System.Threading.Tasks.Task containing the signature for the specified data.
ICryptographyService.Sign(byte[], X509Certificate2) Method
Section titled “ICryptographyService.Sign(byte[], X509Certificate2) Method”Signs the data with the private key from the given certificate.
byte[] Sign(byte[] data, System.Security.Cryptography.X509Certificates.X509Certificate2 certificate);Parameters
Section titled “Parameters”data System.Byte[]
The data, which will be signed.
certificate System.Security.Cryptography.X509Certificates.X509Certificate2
The certificate containing the private key, which will be used for the signature.
Returns
Section titled “Returns”System.Byte[]
The RSA signature for the specified data.
ICryptographyService.Verify(byte[], byte[], string, CancellationToken) Method
Section titled “ICryptographyService.Verify(byte[], byte[], string, CancellationToken) Method”Tries to load a certificate with the given certificateName then verifies that the given data was signed with the private key corresponding to the public key from the found certificate.
System.Threading.Tasks.Task<bool> Verify(byte[] data, byte[] signature, string certificateName="Default", System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));Parameters
Section titled “Parameters”data System.Byte[]
The signed data.
signature System.Byte[]
The signature, which will be tested.
certificateName System.String
The name of the certificate containing the private key, which will be used for the signature verification.
cancellationToken System.Threading.CancellationToken
A System.Threading.CancellationToken used to interrupt the async method.
Returns
Section titled “Returns”System.Threading.Tasks.Task<System.Boolean>
A System.Threading.Tasks.Task containing the verification result: true,
if the data was signed by the entity with the public key from the found certificate.
ICryptographyService.Verify(byte[], byte[], X509Certificate2) Method
Section titled “ICryptographyService.Verify(byte[], byte[], X509Certificate2) Method”Verifies that the given data was signed with the private key corresponding to the public key from the given certificate.
bool Verify(byte[] data, byte[] signature, System.Security.Cryptography.X509Certificates.X509Certificate2 certificate);Parameters
Section titled “Parameters”data System.Byte[]
The signed data.
signature System.Byte[]
The signature, which will be tested.
certificate System.Security.Cryptography.X509Certificates.X509Certificate2
The certificate containing the public key, which will be used for the signature verification.
Returns
Section titled “Returns”System.Boolean
True, if the data was signed by the entity with the public key from the given certificate.