Class CadesSignatureCompression
Class with methods for compressing and decompressing CAdES signatures storing objects likely to be repeated across different signatures such as certificates and CRLs on an external store, avoiding redundant storage of such objects.
Inherited Members
Namespace: Lacuna.Pki.Cades
Assembly: Lacuna.Pki.dll
Syntax
public static class CadesSignatureCompression
Remarks
A CAdES signature may contain, somewhere in its encoding, several certificates, CRLs and other objects that may account to as much as 99% of the length of the signature. Such objects tend to repeat themselves across different signatures performed close together in time. Therefore, if one stores several CAdES signatures, it will be needlessly storing such objects redundantly.
The methods of this class use an external store (an implementation of the ISimpleStore for instance a database, filesystem or cloud service) to implement a strategy that takes into account collectively all signatures stored by a system, instead of treating them as separate files. Given a signature and a store, the Compress(Byte[], ISimpleStore) method will locate the objects likely to be repeated on other signatures, store the ones that are not already in the store, and return a proprietary data object that can be used to do the inverse process (decompress the signature, see Decompress(Byte[], ISimpleStore)).
For more information see article Signature Compression.
Examples
In the following example, we take a signature previously performed (maybe with the CadesSigner class, maybe imported from a 3rd party system, it doesn't really matter) and compress it using as store the FileSystemSimpleStore.
var signature = File.ReadAllBytes("existing-signature.p7s");
var store = new FileSystemSimpleStore(@"C:\Temp");
var compressedSignature = CadesSignatureCompression.Compress(signature, store);
var decompressedSignature = CadesSignatureCompression.Decompress(compressedSignature, store);
if (decompressedSignature.SequenceEqual(signature)) {
Console.WriteLine("OK!");
} else {
Console.WriteLine("NOT OK!");
}
Methods
Compress(Byte[], ISimpleStore)
Compresses a CAdES signature storing objects likely to be repeated across different signatures such as certificates and CRLs in an external store.
Declaration
public static byte[] Compress(byte[] cadesSignature, ISimpleStore store)
Parameters
Type | Name | Description |
---|---|---|
Byte[] | cadesSignature | The CAdES signature to be compressed. |
ISimpleStore | store | The external store on which to store the repeatable objects. |
Returns
Type | Description |
---|---|
Byte[] | The compressed signature in a proprietary format that can be decompressed with the Decompress(Byte[], ISimpleStore, Byte[]) method. |
Remarks
The given signature need not have been generated by the
If the given signature has an encapsulated content (attached signature), this method does not remove it. If you want to separate the encapsulated content from the signature during the compression, use the method Compress(Byte[], ISimpleStore, out Byte[]) instead.
Compress(Byte[], ISimpleStore, out Byte[])
Compresses a CAdES signature storing objects likely to be repeated across different signatures such as certificates and CRLs in an external store, separating the encapsulated content within the signature (attached signature) if present.
Declaration
public static byte[] Compress(byte[] cadesSignature, ISimpleStore store, out byte[] encapsulatedContent)
Parameters
Type | Name | Description |
---|---|---|
Byte[] | cadesSignature | The CAdES signature to be compressed. |
ISimpleStore | store | The external store on which to store the repeatable objects. |
Byte[] | encapsulatedContent | When this method returns, contains the encapsulated content within the signature, if any. |
Returns
Type | Description |
---|---|
Byte[] | The compressed signature in a proprietary format that can be decompressed with the Decompress(Byte[], ISimpleStore, Byte[]) method. |
Remarks
The given signature need not have been generated by the
If you wish to store the signature with the encapsulated content inside, or if you don´t care about the encapsulated content (for instance if all your signatures are detached), use the method Compress(Byte[], ISimpleStore) instead.
Decompress(Byte[], ISimpleStore)
Decompresses a CAdES signature previously compressed with the compression methods from this class.
Declaration
public static byte[] Decompress(byte[] compressedSignature, ISimpleStore store)
Parameters
Type | Name | Description |
---|---|---|
Byte[] | compressedSignature | The compressed signature in proprietary format. |
ISimpleStore | store | The external store where the repeatable objects were stored during the compression. |
Returns
Type | Description |
---|---|
Byte[] |
Decompress(Byte[], ISimpleStore, Byte[])
Decompresses a CAdES signature previously compressed with the compression methods from this class.
Declaration
public static byte[] Decompress(byte[] compressedSignature, ISimpleStore store, byte[] encapsulatedContent)
Parameters
Type | Name | Description |
---|---|---|
Byte[] | compressedSignature | The compressed signature in proprietary format. |
ISimpleStore | store | The external store where the repeatable objects were stored during the compression. |
Byte[] | encapsulatedContent | The encapsulated content separated during the compression, if any. |
Returns
Type | Description |
---|---|
Byte[] | The original signature. |
Remarks
If the original signature had an encapsulated content and the method Compress(Byte[], ISimpleStore, out Byte[])
was used to compress the signature, you