EncryptedTypeとは? わかりやすく解説

EncryptedType クラス

メモ : このクラスは、.NET Framework version 2.0新しく追加されたものです。

EncryptedData クラスと EncryptedKey クラス派生元となる抽象基本クラス表します

名前空間: System.Security.Cryptography.Xml
アセンブリ: System.Security (system.security.dll 内)
構文構文

Public MustInherit Class
 EncryptedType
Dim instance As EncryptedType
public abstract class EncryptedType
public ref class EncryptedType abstract
public abstract class EncryptedType
解説解説

EncryptedType クラスは、EncryptedData クラスEncryptedKey クラス派生元となる抽象基本クラス表します。これらの 2 つクラスは、XML 暗号化暗号化された実際のデータまたはキー情報格納しますXML 暗号化標準準拠するには、これらの 2 つ派生クラス使用する必要があります

XML 暗号化標準詳細については、http://www.w3.org/TR/xmlenc-core/ を参照してください

使用例使用例

EncryptedType クラスから派生した EncryptedData クラス使用してXML 要素暗号化および復号化する方法次のコード例示します

Imports System
Imports System.Xml
Imports System.Security.Cryptography
Imports System.Security.Cryptography.Xml



Module Program

    Sub Main(ByVal args() As
 String)

        ' Create an XmlDocument object.
        Dim xmlDoc As New
 XmlDocument()

        ' Load an XML file into the XmlDocument object.
        Try
            xmlDoc.PreserveWhitespace = True
            xmlDoc.Load("test.xml")
        Catch e As Exception
            Console.WriteLine(e.Message)
        End Try

        ' Create a new TripleDES key. 
        Dim tDESkey As New
 TripleDESCryptoServiceProvider()


        Try
            ' Encrypt the "creditcard" element.
            Encrypt(xmlDoc, "creditcard", tDESkey)

            ' Display the encrypted XML to the console.
            Console.WriteLine("Encrypted XML:")
            Console.WriteLine()
            Console.WriteLine(xmlDoc.OuterXml)

            ' Decrypt the "creditcard" element.
            Decrypt(xmlDoc, tDESkey)

            ' Display the encrypted XML to the console.
            Console.WriteLine()
            Console.WriteLine("Decrypted XML:")
            Console.WriteLine()
            Console.WriteLine(xmlDoc.OuterXml)
        Catch e As Exception
            Console.WriteLine(e.Message)
        Finally
            ' Clear the TripleDES key.
            tDESkey.Clear()
        End Try

    End Sub


    Sub Encrypt(ByVal Doc As
 XmlDocument, ByVal ElementToEncryptString As
 String, ByVal Alg As TripleDESCryptoServiceProvider)

        ''''''''''''''''''''''''''''''''''''''''''''''''''
        ' Find the specified element in the XmlDocument
        ' object and create a new XmlElemnt object.
        ''''''''''''''''''''''''''''''''''''''''''''''''''

        Dim elementToEncrypt As XmlElement
 = Doc.GetElementsByTagName(ElementToEncryptString)(0)


        ' Throw an XmlException if the element was not found.
        If elementToEncrypt Is Nothing
 Then
            Throw New XmlException("The
 specified element was not found")
        End If

        ''''''''''''''''''''''''''''''''''''''''''''''''''
        ' Create a new instance of the EncryptedXml class 
        ' and use it to encrypt the XmlElement with the 
        ' symmetric key.
        ''''''''''''''''''''''''''''''''''''''''''''''''''

        Dim eXml As New
 EncryptedXml()

        Dim encryptedElement As Byte()
 = eXml.EncryptData(elementToEncrypt, Alg, False)

        ''''''''''''''''''''''''''''''''''''''''''''''''''
        ' Construct an EncryptedData object and populate
        ' it with the desired encryption information.
        ''''''''''''''''''''''''''''''''''''''''''''''''''

        Dim edElement As New
 EncryptedData()

        edElement.Type = EncryptedXml.XmlEncElementUrl


        ' Create an EncryptionMethod element so that the 
        ' receiver knows which algorithm to use for decryption.
        ' Determine what kind of algorithm is being used and
        ' supply the appropriate URL to the EncryptionMethod element.
        edElement.EncryptionMethod = New EncryptionMethod(EncryptedXml.XmlEncTripleDESUrl)

        ' Add the encrypted element data to the 
        ' EncryptedData object.
        edElement.CipherData.CipherValue = encryptedElement

        ''''''''''''''''''''''''''''''''''''''''''''''''''
        ' Replace the element from the original XmlDocument
        ' object with the EncryptedData element.
        ''''''''''''''''''''''''''''''''''''''''''''''''''
        EncryptedXml.ReplaceElement(elementToEncrypt, edElement, False)

    End Sub


    Sub Decrypt(ByVal Doc As
 XmlDocument, ByVal Alg As SymmetricAlgorithm)

        ' Find the EncryptedData element in the XmlDocument.
        Dim encryptedElement As XmlElement
 = Doc.GetElementsByTagName("EncryptedData")(0) 
   

        ' If the EncryptedData element was not found, throw an exception.
        If encryptedElement Is Nothing
 Then
            Throw New XmlException("The
 EncryptedData element was not found.")
        End If

        ' Create an EncryptedData object and populate it.
        Dim edElement As New
 EncryptedData()
        edElement.LoadXml(encryptedElement)

        ' Create a new EncryptedXml object.
        Dim exml As New
 EncryptedXml()

        ' Decrypt the element using the symmetric key.
        Dim rgbOutput As Byte()
 = exml.DecryptData(edElement, Alg)

        ' Replace the encryptedData element with the plaintext XML element.
        exml.ReplaceData(encryptedElement, rgbOutput)

    End Sub
End Module

using System;
using System.Xml;
using System.Security.Cryptography;
using System.Security.Cryptography.Xml;

class Program
{
    static void Main(string[]
 args)
    {

        // Create an XmlDocument object.
        XmlDocument xmlDoc = new XmlDocument();

        // Load an XML file into the XmlDocument object.
        try
        {
            xmlDoc.PreserveWhitespace = true;
            xmlDoc.Load("test.xml");
        }
        catch (Exception e)
        {
            Console.WriteLine(e.Message);
        }

        // Create a new TripleDES key. 
        TripleDESCryptoServiceProvider tDESkey = new TripleDESCryptoServiceProvider();


        try
        {
            // Encrypt the "creditcard" element.
            Encrypt(xmlDoc, "creditcard", tDESkey);

            // Display the encrypted XML to the console.
            Console.WriteLine("Encrypted XML:");
            Console.WriteLine();
            Console.WriteLine(xmlDoc.OuterXml);

            // Decrypt the "creditcard" element.
            Decrypt(xmlDoc, tDESkey);

            // Display the encrypted XML to the console.
            Console.WriteLine();
            Console.WriteLine("Decrypted XML:");
            Console.WriteLine();
            Console.WriteLine(xmlDoc.OuterXml);
        }
        catch (Exception e)
        {
            Console.WriteLine(e.Message);
        }
        finally
        {
            // Clear the TripleDES key.
            tDESkey.Clear();
        }

    }

    public static void Encrypt(XmlDocument
 Doc, string ElementToEncrypt, TripleDESCryptoServiceProvider
 Alg)
    {

        ////////////////////////////////////////////////
        // Find the specified element in the XmlDocument
        // object and create a new XmlElemnt object.
        ////////////////////////////////////////////////

        XmlElement elementToEncrypt = Doc.GetElementsByTagName(ElementToEncrypt)[0]
 as XmlElement;

        // Throw an XmlException if the element was not found.
        if (elementToEncrypt == null)
        {
            throw new XmlException("The specified element
 was not found");

        }

        //////////////////////////////////////////////////
        // Create a new instance of the EncryptedXml class 
        // and use it to encrypt the XmlElement with the 
        // symmetric key.
        //////////////////////////////////////////////////

        EncryptedXml eXml = new EncryptedXml();

        byte[] encryptedElement = eXml.EncryptData(elementToEncrypt, Alg, false);

        ////////////////////////////////////////////////
        // Construct an EncryptedData object and populate
        // it with the desired encryption information.
        ////////////////////////////////////////////////


        EncryptedData edElement = new EncryptedData();
        
        edElement.Type = EncryptedXml.XmlEncElementUrl;

  
        // Create an EncryptionMethod element so that the 
        // receiver knows which algorithm to use for decryption.
        // Determine what kind of algorithm is being used and
        // supply the appropriate URL to the EncryptionMethod element.

        edElement.EncryptionMethod = new EncryptionMethod(EncryptedXml.XmlEncTripleDESUrl);

        // Add the encrypted element data to the 
        // EncryptedData object.
        edElement.CipherData.CipherValue = encryptedElement;

        ////////////////////////////////////////////////////
        // Replace the element from the original XmlDocument
        // object with the EncryptedData element.
        ////////////////////////////////////////////////////

        EncryptedXml.ReplaceElement(elementToEncrypt, edElement, false);

    }

    public static void Decrypt(XmlDocument
 Doc, SymmetricAlgorithm Alg)
    {

        // Find the EncryptedData element in the XmlDocument.
        XmlElement encryptedElement = Doc.GetElementsByTagName("EncryptedData")[0]
 as XmlElement;

        // If the EncryptedData element was not found, throw an exception.
        if (encryptedElement == null)
        {
            throw new XmlException("The EncryptedData element
 was not found.");
        }

        // Create an EncryptedData object and populate it.
        EncryptedData edElement = new EncryptedData();
        edElement.LoadXml(encryptedElement);

        // Create a new EncryptedXml object.
        EncryptedXml exml = new EncryptedXml();

        // Decrypt the element using the symmetric key.
        byte[] rgbOutput = exml.DecryptData(edElement, Alg);

        // Replace the encryptedData element with the plaintext XML
 element.
        exml.ReplaceData(encryptedElement, rgbOutput);

    }


}
継承階層継承階層
System.Object
  System.Security.Cryptography.Xml.EncryptedType
     System.Security.Cryptography.Xml.EncryptedData
     System.Security.Cryptography.Xml.EncryptedKey
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
EncryptedType メンバ
System.Security.Cryptography.Xml 名前空間

EncryptedType コンストラクタ

メモ : このコンストラクタは、.NET Framework version 2.0新しく追加されたものです。

EncryptedType クラス新しインスタンス初期化します。

名前空間: System.Security.Cryptography.Xml
アセンブリ: System.Security (system.security.dll 内)
構文構文

protected EncryptedType ()
protected:
EncryptedType ()
protected EncryptedType ()
解説解説

このコンストラクタは、EncryptedType クラス新しインスタンス作成します。このクラスは、EncryptedData クラスと EncryptedKey クラス派生元となる抽象基本クラス表しますXML 暗号化標準準拠するには、これらの 2 つ派生クラス使用する必要がありますXML 暗号化標準詳細については、http://www.w3.org/TR/xmlenc-core/ を参照してください

使用例使用例

EncryptedType クラスから派生した EncryptedData クラス使用してXML 要素暗号化および復号化する方法次のコード例示します

Imports System
Imports System.Xml
Imports System.Security.Cryptography
Imports System.Security.Cryptography.Xml



Module Program

    Sub Main(ByVal args() As
 String)

        ' Create an XmlDocument object.
        Dim xmlDoc As New
 XmlDocument()

        ' Load an XML file into the XmlDocument object.
        Try
            xmlDoc.PreserveWhitespace = True
            xmlDoc.Load("test.xml")
        Catch e As Exception
            Console.WriteLine(e.Message)
        End Try

        ' Create a new TripleDES key. 
        Dim tDESkey As New
 TripleDESCryptoServiceProvider()


        Try
            ' Encrypt the "creditcard" element.
            Encrypt(xmlDoc, "creditcard", tDESkey)

            ' Display the encrypted XML to the console.
            Console.WriteLine("Encrypted XML:")
            Console.WriteLine()
            Console.WriteLine(xmlDoc.OuterXml)

            ' Decrypt the "creditcard" element.
            Decrypt(xmlDoc, tDESkey)

            ' Display the encrypted XML to the console.
            Console.WriteLine()
            Console.WriteLine("Decrypted XML:")
            Console.WriteLine()
            Console.WriteLine(xmlDoc.OuterXml)
        Catch e As Exception
            Console.WriteLine(e.Message)
        Finally
            ' Clear the TripleDES key.
            tDESkey.Clear()
        End Try

    End Sub


    Sub Encrypt(ByVal Doc As
 XmlDocument, ByVal ElementToEncryptString As
 String, ByVal Alg As TripleDESCryptoServiceProvider)

        ''''''''''''''''''''''''''''''''''''''''''''''''''
        ' Find the specified element in the XmlDocument
        ' object and create a new XmlElemnt object.
        ''''''''''''''''''''''''''''''''''''''''''''''''''

        Dim elementToEncrypt As XmlElement
 = Doc.GetElementsByTagName(ElementToEncryptString)(0)


        ' Throw an XmlException if the element was not found.
        If elementToEncrypt Is Nothing
 Then
            Throw New XmlException("The
 specified element was not found")
        End If

        ''''''''''''''''''''''''''''''''''''''''''''''''''
        ' Create a new instance of the EncryptedXml class 
        ' and use it to encrypt the XmlElement with the 
        ' symmetric key.
        ''''''''''''''''''''''''''''''''''''''''''''''''''

        Dim eXml As New
 EncryptedXml()

        Dim encryptedElement As Byte()
 = eXml.EncryptData(elementToEncrypt, Alg, False)

        ''''''''''''''''''''''''''''''''''''''''''''''''''
        ' Construct an EncryptedData object and populate
        ' it with the desired encryption information.
        ''''''''''''''''''''''''''''''''''''''''''''''''''

        Dim edElement As New
 EncryptedData()

        edElement.Type = EncryptedXml.XmlEncElementUrl


        ' Create an EncryptionMethod element so that the 
        ' receiver knows which algorithm to use for decryption.
        ' Determine what kind of algorithm is being used and
        ' supply the appropriate URL to the EncryptionMethod element.
        edElement.EncryptionMethod = New EncryptionMethod(EncryptedXml.XmlEncTripleDESUrl)

        ' Add the encrypted element data to the 
        ' EncryptedData object.
        edElement.CipherData.CipherValue = encryptedElement

        ''''''''''''''''''''''''''''''''''''''''''''''''''
        ' Replace the element from the original XmlDocument
        ' object with the EncryptedData element.
        ''''''''''''''''''''''''''''''''''''''''''''''''''
        EncryptedXml.ReplaceElement(elementToEncrypt, edElement, False)

    End Sub


    Sub Decrypt(ByVal Doc As
 XmlDocument, ByVal Alg As SymmetricAlgorithm)

        ' Find the EncryptedData element in the XmlDocument.
        Dim encryptedElement As XmlElement
 = Doc.GetElementsByTagName("EncryptedData")(0) 
   

        ' If the EncryptedData element was not found, throw an exception.
        If encryptedElement Is Nothing
 Then
            Throw New XmlException("The
 EncryptedData element was not found.")
        End If

        ' Create an EncryptedData object and populate it.
        Dim edElement As New
 EncryptedData()
        edElement.LoadXml(encryptedElement)

        ' Create a new EncryptedXml object.
        Dim exml As New
 EncryptedXml()

        ' Decrypt the element using the symmetric key.
        Dim rgbOutput As Byte()
 = exml.DecryptData(edElement, Alg)

        ' Replace the encryptedData element with the plaintext XML element.
        exml.ReplaceData(encryptedElement, rgbOutput)

    End Sub
End Module

using System;
using System.Xml;
using System.Security.Cryptography;
using System.Security.Cryptography.Xml;

class Program
{
    static void Main(string[]
 args)
    {

        // Create an XmlDocument object.
        XmlDocument xmlDoc = new XmlDocument();

        // Load an XML file into the XmlDocument object.
        try
        {
            xmlDoc.PreserveWhitespace = true;
            xmlDoc.Load("test.xml");
        }
        catch (Exception e)
        {
            Console.WriteLine(e.Message);
        }

        // Create a new TripleDES key. 
        TripleDESCryptoServiceProvider tDESkey = new TripleDESCryptoServiceProvider();


        try
        {
            // Encrypt the "creditcard" element.
            Encrypt(xmlDoc, "creditcard", tDESkey);

            // Display the encrypted XML to the console.
            Console.WriteLine("Encrypted XML:");
            Console.WriteLine();
            Console.WriteLine(xmlDoc.OuterXml);

            // Decrypt the "creditcard" element.
            Decrypt(xmlDoc, tDESkey);

            // Display the encrypted XML to the console.
            Console.WriteLine();
            Console.WriteLine("Decrypted XML:");
            Console.WriteLine();
            Console.WriteLine(xmlDoc.OuterXml);
        }
        catch (Exception e)
        {
            Console.WriteLine(e.Message);
        }
        finally
        {
            // Clear the TripleDES key.
            tDESkey.Clear();
        }

    }

    public static void Encrypt(XmlDocument
 Doc, string ElementToEncrypt, TripleDESCryptoServiceProvider
 Alg)
    {

        ////////////////////////////////////////////////
        // Find the specified element in the XmlDocument
        // object and create a new XmlElemnt object.
        ////////////////////////////////////////////////

        XmlElement elementToEncrypt = Doc.GetElementsByTagName(ElementToEncrypt)[0]
 as XmlElement;

        // Throw an XmlException if the element was not found.
        if (elementToEncrypt == null)
        {
            throw new XmlException("The specified element
 was not found");

        }

        //////////////////////////////////////////////////
        // Create a new instance of the EncryptedXml class 
        // and use it to encrypt the XmlElement with the 
        // symmetric key.
        //////////////////////////////////////////////////

        EncryptedXml eXml = new EncryptedXml();

        byte[] encryptedElement = eXml.EncryptData(elementToEncrypt, Alg, false);

        ////////////////////////////////////////////////
        // Construct an EncryptedData object and populate
        // it with the desired encryption information.
        ////////////////////////////////////////////////


        EncryptedData edElement = new EncryptedData();
        
        edElement.Type = EncryptedXml.XmlEncElementUrl;

  
        // Create an EncryptionMethod element so that the 
        // receiver knows which algorithm to use for decryption.
        // Determine what kind of algorithm is being used and
        // supply the appropriate URL to the EncryptionMethod element.

        edElement.EncryptionMethod = new EncryptionMethod(EncryptedXml.XmlEncTripleDESUrl);

        // Add the encrypted element data to the 
        // EncryptedData object.
        edElement.CipherData.CipherValue = encryptedElement;

        ////////////////////////////////////////////////////
        // Replace the element from the original XmlDocument
        // object with the EncryptedData element.
        ////////////////////////////////////////////////////

        EncryptedXml.ReplaceElement(elementToEncrypt, edElement, false);

    }

    public static void Decrypt(XmlDocument
 Doc, SymmetricAlgorithm Alg)
    {

        // Find the EncryptedData element in the XmlDocument.
        XmlElement encryptedElement = Doc.GetElementsByTagName("EncryptedData")[0]
 as XmlElement;

        // If the EncryptedData element was not found, throw an exception.
        if (encryptedElement == null)
        {
            throw new XmlException("The EncryptedData element
 was not found.");
        }

        // Create an EncryptedData object and populate it.
        EncryptedData edElement = new EncryptedData();
        edElement.LoadXml(encryptedElement);

        // Create a new EncryptedXml object.
        EncryptedXml exml = new EncryptedXml();

        // Decrypt the element using the symmetric key.
        byte[] rgbOutput = exml.DecryptData(edElement, Alg);

        // Replace the encryptedData element with the plaintext XML
 element.
        exml.ReplaceData(encryptedElement, rgbOutput);

    }


}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
EncryptedType クラス
EncryptedType メンバ
System.Security.Cryptography.Xml 名前空間

EncryptedType プロパティ


パブリック プロパティパブリック プロパティ

  名前 説明
パブリック プロパティ CipherData EncryptedType クラスインスタンスの CipherData 値を取得または設定します
パブリック プロパティ Encoding XML 暗号化EncryptedType インスタンスEncoding 属性取得または設定します
パブリック プロパティ EncryptionMethod XML 暗号化<EncryptionMethod> 要素取得または設定します
パブリック プロパティ EncryptionProperties XML 暗号化<EncryptionProperties> 要素取得または設定します
パブリック プロパティ Id XML 暗号化EncryptedType インスタンスId 属性取得または設定します
パブリック プロパティ KeyInfo XML 暗号化<KeyInfo> 要素取得または設定します
パブリック プロパティ MimeType XML 暗号化EncryptedType インスタンスMimeType 属性取得または設定します
パブリック プロパティ Type XML 暗号化EncryptedType インスタンスType 属性取得または設定します
参照参照

関連項目

EncryptedType クラス
System.Security.Cryptography.Xml 名前空間

EncryptedType メソッド


パブリック メソッドパブリック メソッド

プロテクト メソッドプロテクト メソッド
参照参照

関連項目

EncryptedType クラス
System.Security.Cryptography.Xml 名前空間

EncryptedType メンバ

EncryptedData クラスと EncryptedKey クラス派生元となる抽象基本クラス表します

EncryptedType データ型公開されるメンバを以下の表に示します


プロテクト コンストラクタプロテクト コンストラクタ
  名前 説明
プロテクト メソッド EncryptedType EncryptedType クラス新しインスタンス初期化します。
パブリック プロパティパブリック プロパティ
  名前 説明
パブリック プロパティ CipherData EncryptedType クラスインスタンスの CipherData 値を取得または設定します
パブリック プロパティ Encoding XML 暗号化EncryptedType インスタンスEncoding 属性取得または設定します
パブリック プロパティ EncryptionMethod XML 暗号化<EncryptionMethod> 要素取得または設定します
パブリック プロパティ EncryptionProperties XML 暗号化<EncryptionProperties> 要素取得または設定します
パブリック プロパティ Id XML 暗号化EncryptedType インスタンスId 属性取得または設定します
パブリック プロパティ KeyInfo XML 暗号化<KeyInfo> 要素取得または設定します
パブリック プロパティ MimeType XML 暗号化EncryptedType インスタンスMimeType 属性取得または設定します
パブリック プロパティ Type XML 暗号化EncryptedType インスタンスType 属性取得または設定します
パブリック メソッドパブリック メソッド
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

EncryptedType クラス
System.Security.Cryptography.Xml 名前空間


このページでは「.NET Framework クラス ライブラリ リファレンス」からEncryptedTypeを検索した結果を表示しています。
Weblioに収録されているすべての辞書からEncryptedTypeを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からEncryptedType を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「EncryptedType」の関連用語

EncryptedTypeのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



EncryptedTypeのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS