コード例 #1
0
ファイル: Program.cs プロジェクト: krwq/PfxDataPrinter
        private static void ProcessAttribute(
            TextWriter writer,
            AsnEncodedData attr,
            string scopeId,
            IDictionary <string, List <string> > keyMatches)
        {
            string oidValue = attr.Oid.Value;
            bool   handled  = false;

            writer.WriteLine($"Type: {attr.GetType().Name} ({oidValue})");

            if (attr is Pkcs9LocalKeyId keyId)
            {
                string localKeyId = keyId.KeyId.ToHex();
                writer.WriteLine($"Value: {localKeyId}");
                handled = true;

                if (!keyMatches.TryGetValue(localKeyId, out List <string> scopes))
                {
                    keyMatches[localKeyId] = new List <string> {
                        scopeId
                    };
                }
                else
                {
                    scopes.Add(scopeId);
                }
            }
            else if (oidValue == "1.3.6.1.4.1.311.17.2")
            {
                writer.WriteLine("Value: Machine Keyset Indicated");
                handled = true;
            }
            else if (oidValue == "1.2.840.113549.1.9.20")
            {
                if (TryReadBmpString(attr.RawData, out string friendlyName))
                {
                    writer.WriteLine($"Friendly Name: {friendlyName}");
                    handled = true;
                }
            }
            else if (oidValue == "1.3.6.1.4.1.311.17.1")
            {
                if (TryReadBmpString(attr.RawData, out string keyProvider))
                {
                    writer.WriteLine($"Key Provider: {keyProvider}");
                    handled = true;
                }
            }

            if (!handled)
            {
                byte[] rawData = attr.RawData;
                writer.WriteLine($"Value Length: {rawData.Length}");

                if (rawData.Length > 12)
                {
                    writer.WriteLine($"Value: {rawData.AsSpan(0, 10).ToHex()}...");
                }
                else
                {
                    writer.WriteLine($"Value: {rawData.ToHex()}");
                }
            }
        }