Opc.Ua.CertificateIdentifier.ParseBlob C# (CSharp) Method

ParseBlob() public static method

Parses a blob with a list of DER encoded certificates.
Any supporting certificates found in the buffer are processed as well.
public static ParseBlob ( byte encodedData ) : X509Certificate2Collection
encodedData byte The encoded data.
return System.Security.Cryptography.X509Certificates.X509Certificate2Collection
        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;
        }