Class CpX509Certificate2Collection
Inherited Members
Namespace: CryptoPro.Security.Cryptography.X509Certificates
Assembly: CryptoPro.Security.Cryptography.dll
Syntax
public class CpX509Certificate2Collection : CpX509CertificateCollection, IList, ICollection, IEnumerable<CpX509Certificate2>, IEnumerable
Constructors
CpX509Certificate2Collection()
Declaration
public CpX509Certificate2Collection()
CpX509Certificate2Collection(CpX509Certificate2)
Declaration
public CpX509Certificate2Collection(CpX509Certificate2 certificate)
Parameters
Type | Name | Description |
---|---|---|
CpX509Certificate2 | certificate |
CpX509Certificate2Collection(CpX509Certificate2Collection)
Declaration
public CpX509Certificate2Collection(CpX509Certificate2Collection certificates)
Parameters
Type | Name | Description |
---|---|---|
CpX509Certificate2Collection | certificates |
CpX509Certificate2Collection(CpX509Certificate2[])
Declaration
public CpX509Certificate2Collection(CpX509Certificate2[] certificates)
Parameters
Type | Name | Description |
---|---|---|
CpX509Certificate2[] | certificates |
Properties
this[int]
Declaration
public CpX509Certificate2 this[int index] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
int | index |
Property Value
Type | Description |
---|---|
CpX509Certificate2 |
Methods
Add(CpX509Certificate2)
Declaration
public int Add(CpX509Certificate2 certificate)
Parameters
Type | Name | Description |
---|---|---|
CpX509Certificate2 | certificate |
Returns
Type | Description |
---|---|
int |
AddRange(CpX509Certificate2Collection)
Declaration
public void AddRange(CpX509Certificate2Collection certificates)
Parameters
Type | Name | Description |
---|---|---|
CpX509Certificate2Collection | certificates |
AddRange(CpX509Certificate2[])
Declaration
public void AddRange(CpX509Certificate2[] certificates)
Parameters
Type | Name | Description |
---|---|---|
CpX509Certificate2[] | certificates |
Contains(CpX509Certificate2)
Declaration
public bool Contains(CpX509Certificate2 certificate)
Parameters
Type | Name | Description |
---|---|---|
CpX509Certificate2 | certificate |
Returns
Type | Description |
---|---|
bool |
Export(X509ContentType)
Declaration
public byte[]? Export(X509ContentType contentType)
Parameters
Type | Name | Description |
---|---|---|
X509ContentType | contentType |
Returns
Type | Description |
---|---|
byte[] |
Export(X509ContentType, string?)
Declaration
public byte[]? Export(X509ContentType contentType, string? password)
Parameters
Type | Name | Description |
---|---|---|
X509ContentType | contentType | |
string | password |
Returns
Type | Description |
---|---|
byte[] |
ExportCertificatePems()
Exports the public X.509 certificates, encoded as PEM.
Declaration
public string ExportCertificatePems()
Returns
Type | Description |
---|---|
string | The PEM encoding of the certificates. |
Remarks
A PEM-encoded X.509 certificate collection will contain certificates
where each certificate begins with -----BEGIN CERTIFICATE-----
and ends with -----END CERTIFICATE-----
, with the base64 encoded DER
contents of the certificate between the PEM boundaries. Each certificate is
separated by a single line-feed character.
Certificates are encoded according to the IETF RFC 7468 "strict" encoding rules.
Exceptions
Type | Condition |
---|---|
CryptographicException | A certificate is corrupt, in an invalid state, or could not be exported to PEM. |
OverflowException | The combined size of encoding all certificates exceeds MaxValue. |
ExportPkcs7Pem()
Exports the X.509 public certificates as a PKCS7 certificate collection, encoded as PEM.
Declaration
public string ExportPkcs7Pem()
Returns
Type | Description |
---|---|
string | The PEM encoded PKCS7 collection. |
Exceptions
Type | Condition |
---|---|
CryptographicException | A certificate is corrupt, in an invalid state, or could not be exported to PEM. |
Find(X509FindType, object, bool)
Declaration
public CpX509Certificate2Collection Find(X509FindType findType, object findValue, bool validOnly)
Parameters
Type | Name | Description |
---|---|---|
X509FindType | findType | |
object | findValue | |
bool | validOnly |
Returns
Type | Description |
---|---|
CpX509Certificate2Collection |
GetEnumerator()
Declaration
public CpX509Certificate2Enumerator GetEnumerator()
Returns
Type | Description |
---|---|
CpX509Certificate2Enumerator |
Import(byte[])
Declaration
public void Import(byte[] rawData)
Parameters
Type | Name | Description |
---|---|---|
byte[] | rawData |
Import(byte[], string?, X509KeyStorageFlags)
Declaration
public void Import(byte[] rawData, string? password, X509KeyStorageFlags keyStorageFlags = X509KeyStorageFlags.DefaultKeySet)
Parameters
Type | Name | Description |
---|---|---|
byte[] | rawData | |
string | password | |
X509KeyStorageFlags | keyStorageFlags |
Import(ReadOnlySpan<byte>)
Imports the certificates from the provided data into this collection.
Declaration
public void Import(ReadOnlySpan<byte> rawData)
Parameters
Type | Name | Description |
---|---|---|
ReadOnlySpan<byte> | rawData | The certificate data to read. |
Import(ReadOnlySpan<byte>, ReadOnlySpan<char>, X509KeyStorageFlags)
Imports the certificates from the provided data into this collection.
Declaration
public void Import(ReadOnlySpan<byte> rawData, ReadOnlySpan<char> password, X509KeyStorageFlags keyStorageFlags = X509KeyStorageFlags.DefaultKeySet)
Parameters
Type | Name | Description |
---|---|---|
ReadOnlySpan<byte> | rawData | The certificate data to read. |
ReadOnlySpan<char> | password | The password required to access the certificate data. |
X509KeyStorageFlags | keyStorageFlags | A bitwise combination of the enumeration values that control where and how to import the certificate. |
Import(ReadOnlySpan<byte>, string?, X509KeyStorageFlags)
Imports the certificates from the provided data into this collection.
Declaration
public void Import(ReadOnlySpan<byte> rawData, string? password, X509KeyStorageFlags keyStorageFlags = X509KeyStorageFlags.DefaultKeySet)
Parameters
Type | Name | Description |
---|---|---|
ReadOnlySpan<byte> | rawData | The certificate data to read. |
string | password | The password required to access the certificate data. |
X509KeyStorageFlags | keyStorageFlags | A bitwise combination of the enumeration values that control where and how to import the certificate. |
Import(string)
Declaration
public void Import(string fileName)
Parameters
Type | Name | Description |
---|---|---|
string | fileName |
Import(string, ReadOnlySpan<char>, X509KeyStorageFlags)
Imports the certificates from the specified file a into this collection.
Declaration
public void Import(string fileName, ReadOnlySpan<char> password, X509KeyStorageFlags keyStorageFlags = X509KeyStorageFlags.DefaultKeySet)
Parameters
Type | Name | Description |
---|---|---|
string | fileName | The name of the file containing the certificate information. |
ReadOnlySpan<char> | password | The password required to access the certificate data. |
X509KeyStorageFlags | keyStorageFlags | A bitwise combination of the enumeration values that control where and how to import the certificate. |
Import(string, string?, X509KeyStorageFlags)
Declaration
public void Import(string fileName, string? password, X509KeyStorageFlags keyStorageFlags = X509KeyStorageFlags.DefaultKeySet)
Parameters
Type | Name | Description |
---|---|---|
string | fileName | |
string | password | |
X509KeyStorageFlags | keyStorageFlags |
ImportFromPem(ReadOnlySpan<char>)
Imports a collection of RFC 7468 PEM-encoded certificates.
Declaration
public void ImportFromPem(ReadOnlySpan<char> certPem)
Parameters
Type | Name | Description |
---|---|---|
ReadOnlySpan<char> | certPem | The text of the PEM-encoded X509 certificate collection. |
Remarks
PEM-encoded items with a CERTIFICATE PEM label will be imported. PEM items with other labels will be ignored.
More advanced scenarios for loading certificates and can leverage PemEncoding to enumerate PEM-encoded values and apply any custom loading behavior.
Exceptions
Type | Condition |
---|---|
CryptographicException | The decoded contents of a PEM are invalid or corrupt and could not be imported. |
ImportFromPemFile(string)
Imports a collection of RFC 7468 PEM-encoded certificates.
Declaration
public void ImportFromPemFile(string certPemFilePath)
Parameters
Type | Name | Description |
---|---|---|
string | certPemFilePath | The path for the PEM-encoded X509 certificate collection. |
Remarks
See ReadAllText(string) for additional documentation about exceptions that can be thrown.
PEM-encoded items with a CERTIFICATE PEM label will be imported. PEM items with other labels will be ignored.
More advanced scenarios for loading certificates and can leverage PemEncoding to enumerate PEM-encoded values and apply any custom loading behavior.
Exceptions
Type | Condition |
---|---|
CryptographicException | The decoded contents of a PEM are invalid or corrupt and could not be imported. |
ArgumentNullException |
|
Insert(int, CpX509Certificate2)
Declaration
public void Insert(int index, CpX509Certificate2 certificate)
Parameters
Type | Name | Description |
---|---|---|
int | index | |
CpX509Certificate2 | certificate |
Remove(CpX509Certificate2)
Declaration
public void Remove(CpX509Certificate2 certificate)
Parameters
Type | Name | Description |
---|---|---|
CpX509Certificate2 | certificate |
RemoveRange(CpX509Certificate2Collection)
Declaration
public void RemoveRange(CpX509Certificate2Collection certificates)
Parameters
Type | Name | Description |
---|---|---|
CpX509Certificate2Collection | certificates |
RemoveRange(CpX509Certificate2[])
Declaration
public void RemoveRange(CpX509Certificate2[] certificates)
Parameters
Type | Name | Description |
---|---|---|
CpX509Certificate2[] | certificates |
TryExportCertificatePems(Span<char>, out int)
Attempts to export the public X.509 certificates, encoded as PEM.
Declaration
public bool TryExportCertificatePems(Span<char> destination, out int charsWritten)
Parameters
Type | Name | Description |
---|---|---|
Span<char> | destination | The buffer to receive the PEM encoded certificates. |
int | charsWritten | When this method returns, the total number of characters written to |
Returns
Type | Description |
---|---|
bool | true if |
Remarks
A PEM-encoded X.509 certificate collection will contain certificates
where each certificate begins with -----BEGIN CERTIFICATE-----
and ends with -----END CERTIFICATE-----
, with the base64 encoded DER
contents of the certificate between the PEM boundaries. Each certificate is
separated by a single line-feed character.
Certificates are encoded according to the IETF RFC 7468 "strict" encoding rules.
Exceptions
Type | Condition |
---|---|
CryptographicException | A certificate is corrupt, in an invalid state, or could not be exported to PEM. |
TryExportPkcs7Pem(Span<char>, out int)
Attempts to export the X.509 public certificates as a PKCS7 certificate collection, encoded as PEM.
Declaration
public bool TryExportPkcs7Pem(Span<char> destination, out int charsWritten)
Parameters
Type | Name | Description |
---|---|---|
Span<char> | destination | The buffer to receive the PEM encoded PKCS7 collection. |
int | charsWritten | When this method returns, the total number of characters written to |
Returns
Type | Description |
---|---|
bool | true if |
Exceptions
Type | Condition |
---|---|
CryptographicException | A certificate is corrupt, in an invalid state, or could not be exported to PEM. |