英語で読む

次の方法で共有


AsnEncodedData クラス

定義

ASN.1 (Abstract Syntax Notation One) でエンコードされたデータを表します。

C#
public class AsnEncodedData
継承
AsnEncodedData
派生

AsnEncodedData クラスを使用するコード例を次に示します。

C#
using System;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;

class AsnEncodedDataSample
{
    static void Main()
    {		
        //The following example demonstrates the usage the AsnEncodedData classes.
        // Asn encoded data is read from the extensions of an X509 certificate.
        try
        {
            // Open the certificate store.
            X509Store store = new X509Store("MY", StoreLocation.CurrentUser);
            store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
            X509Certificate2Collection collection = (X509Certificate2Collection)store.Certificates;
            X509Certificate2Collection fcollection = (X509Certificate2Collection)collection.Find(X509FindType.FindByTimeValid, DateTime.Now, false);
            // Select one or more certificates to display extensions information.
            X509Certificate2Collection scollection = X509Certificate2UI.SelectFromCollection(fcollection, "Certificate Select", "Select certificates from the following list to get extension information on that certificate", X509SelectionFlag.MultiSelection);

            // Create a new AsnEncodedDataCollection object.
            AsnEncodedDataCollection asncoll = new AsnEncodedDataCollection();
            for (int i = 0; i < scollection.Count; i++)
            {
                // Display certificate information.
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Certificate name: {0}", scollection[i].GetName());
                Console.ResetColor();
                // Display extensions information.
                foreach (X509Extension extension in scollection[i].Extensions)
                {
                    // Create an AsnEncodedData object using the extensions information.
                    AsnEncodedData asndata = new AsnEncodedData(extension.Oid, extension.RawData);
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine("Extension type: {0}", extension.Oid.FriendlyName);
                    Console.WriteLine("Oid value: {0}",asndata.Oid.Value);
                    Console.WriteLine("Raw data length: {0} {1}", asndata.RawData.Length, Environment.NewLine);
                    Console.ResetColor();
                    Console.WriteLine(asndata.Format(true));
                    Console.WriteLine(Environment.NewLine);
                    // Add the AsnEncodedData object to the AsnEncodedDataCollection object.
                    asncoll.Add(asndata);
                }
                Console.WriteLine(Environment.NewLine);
            }
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("Number of AsnEncodedData items in the collection: {0} {1}", asncoll.Count, Environment.NewLine);
            Console.ResetColor();

            store.Close();
            //Create an enumerator for moving through the collection.
            AsnEncodedDataEnumerator asne = asncoll.GetEnumerator();
            //You must execute a MoveNext() to get to the first item in the collection.
            asne.MoveNext();
            // Write out AsnEncodedData in the collection.
            Console.ForegroundColor = ConsoleColor.Blue;
            Console.WriteLine("First AsnEncodedData in the collection: {0}", asne.Current.Format(true));
            Console.ResetColor();

            asne.MoveNext();
            Console.ForegroundColor = ConsoleColor.DarkBlue;
            Console.WriteLine("Second AsnEncodedData in the collection: {0}", asne.Current.Format(true));
            Console.ResetColor();
            //Return index in the collection to the beginning.
            asne.Reset();
        }
        catch (CryptographicException)
        {
            Console.WriteLine("Information could not be written out for this certificate.");
        }
    }
}

注釈

CCITT Recommendation X.208 で定義されている抽象構文表記 1 (ASN.1) は、シリアル送信される抽象オブジェクトを指定する方法です。 1 と 0 の文字列などのオブジェクトを表す ASN.1 規則のセットは、識別エンコード規則 (DER) と呼ばれ、CCITT Recommendation X.509 セクション 8.7 で定義されています。 これらのエンコード方法は、現在、.NET Framework の暗号化名前空間で使用されています。

このクラスのインスタンスへのアクセス中に不明なデータ型が検出された場合、データは 16 進数の文字列として返されることに注意してください。

コンストラクター

AsnEncodedData()

AsnEncodedData クラスの新しいインスタンスを初期化します。

AsnEncodedData(AsnEncodedData)

AsnEncodedData クラスの新しいインスタンスを、AsnEncodedData クラスのインスタンスを使用して初期化します。

AsnEncodedData(Byte[])

バイト配列を使用して、AsnEncodedData クラスの新しいインスタンスを初期化します。

AsnEncodedData(Oid, Byte[])

AsnEncodedData オブジェクトとバイト配列を使用して、Oid クラスの新しいインスタンスを初期化します。

AsnEncodedData(Oid, ReadOnlySpan<Byte>)

オブジェクト識別子 (OID) と既存のエンコードされたデータを使用して、AsnEncodedData クラスの新しいインスタンスを初期化します。

AsnEncodedData(ReadOnlySpan<Byte>)

既存のエンコードされたデータを使用して、AsnEncodedData クラスの新しいインスタンスを初期化します。

AsnEncodedData(String, Byte[])

バイト配列を使用して、AsnEncodedData クラスの新しいインスタンスを初期化します。

AsnEncodedData(String, ReadOnlySpan<Byte>)

オブジェクト識別子 (OID) と既存のエンコードされたデータを使用して、AsnEncodedData クラスの新しいインスタンスを初期化します。

プロパティ

Oid

Oid オブジェクトの AsnEncodedData 値を取得または設定します。

RawData

ASN.1 (Abstract Syntax Notation One) でエンコードされたデータをバイト配列表現で取得または設定します。

メソッド

CopyFrom(AsnEncodedData)

AsnEncodedData オブジェクトの情報をコピーします。

Equals(Object)

指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判断します。

(継承元 Object)
Format(Boolean)

ASN.1 (Abstract Syntax Notation One) でエンコードされたデータを、文字列として書式設定して返します。

GetHashCode()

既定のハッシュ関数として機能します。

(継承元 Object)
GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
MemberwiseClone()

現在の Object の簡易コピーを作成します。

(継承元 Object)
ToString()

現在のオブジェクトを表す文字列を返します。

(継承元 Object)

適用対象

製品 バージョン
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.3, 1.4, 1.6, 2.0, 2.1