public static X509Certificate2Collection ParseBlob(byte[] encodedData)
{
if (!IsValidCertificateBlob(encodedData))
{
throw new CryptographicException("Primary certificate in blob is not valid.");
}
X509Certificate2Collection collection = new X509Certificate2Collection();
X509Certificate2 certificate = CertificateFactory.Create(encodedData, true);
collection.Add(certificate);
byte[] rawData = encodedData;
byte[] data = certificate.RawData;
int processedBytes = data.Length;
if (encodedData.Length < processedBytes)
{
byte[] buffer = new byte[encodedData.Length-processedBytes];
do
{
Array.Copy(encodedData, processedBytes, buffer, 0, encodedData.Length-processedBytes);
if (!IsValidCertificateBlob(buffer))
{
throw new CryptographicException("Supporting certificate in blob is not valid.");
}
X509Certificate2 issuerCertificate = CertificateFactory.Create(buffer, true);
collection.Add(issuerCertificate);
data = issuerCertificate.RawData;
processedBytes += data.Length;
}
while (processedBytes < encodedData.Length);
}
return collection;
}