DSAKeyValue コンストラクタとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > DSAKeyValue コンストラクタの意味・解説 

DSAKeyValue コンストラクタ (DSA)

指定した DSA 公開キー使用して、DSAKeyValue クラス新しインスタンス初期化します。

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

使用例使用例

XML 暗号化における DSAKeyValue クラス使用方法次のコード例示します

' Sign an XML file and save the signature in a new file.
Public Shared Sub SignDetachedResource(URIString
 As String, XmlSigFileName As
 String, DSAKey As DSA)
   ' Create a SignedXml object.
   Dim signedXml As New
 SignedXml()
   
   ' Assign the DSA key to the SignedXml object.
   signedXml.SigningKey = DSAKey
   
   ' Create a reference to be signed.
   Dim reference As New
 Reference()
   
   ' Add the passed URI to the reference object.
   reference.Uri = URIString
   
   ' Add the reference to the SignedXml object.
   signedXml.AddReference(reference)
   
   ' Add a DSAKeyValue to the KeyInfo (optional; helps recipient find
 key to validate).
   Dim keyInfo As New KeyInfo()
   keyInfo.AddClause(New DSAKeyValue(CType(DSAKey, DSA)))
   signedXml.KeyInfo = keyInfo
   
   ' Compute the signature.
   signedXml.ComputeSignature()
   
   ' Get the XML representation of the signature and save
   ' it to an XmlElement object.
   Dim xmlDigitalSignature As XmlElement =
 signedXml.GetXml()
   
   ' Save the signed XML document to a file specified
   ' using the passed string.
   Dim xmltw As New XmlTextWriter(XmlSigFileName,
 New UTF8Encoding(False))
   xmlDigitalSignature.WriteTo(xmltw)
   xmltw.Close()
End Sub 

// Sign an XML file and save the signature in a new file.
public static void SignDetachedResource(string
 URIString, string XmlSigFileName, DSA DSAKey)
{
    // Create a SignedXml object.
    SignedXml signedXml = new SignedXml();

    // Assign the DSA key to the SignedXml object.
    signedXml.SigningKey = DSAKey;

    // Create a reference to be signed.
    Reference reference = new Reference();

    // Add the passed URI to the reference object.
    reference.Uri = URIString;
    
    // Add the reference to the SignedXml object.
    signedXml.AddReference(reference);

    // Add a DSAKeyValue to the KeyInfo (optional; helps recipient find
 key to validate).
    KeyInfo keyInfo = new KeyInfo();
    keyInfo.AddClause(new DSAKeyValue((DSA)DSAKey));    
    signedXml.KeyInfo = keyInfo;

    // Compute the signature.
    signedXml.ComputeSignature();

    // Get the XML representation of the signature and save
    // it to an XmlElement object.
    XmlElement xmlDigitalSignature = signedXml.GetXml();

    // Save the signed XML document to a file specified
    // using the passed string.
    XmlTextWriter xmltw = new XmlTextWriter(XmlSigFileName, new
 UTF8Encoding(false));
    xmlDigitalSignature.WriteTo(xmltw);
    xmltw.Close();
}
// Sign an XML file and save the signature in a new file.
void SignDetachedResource( String^ URIString, String^ XmlSigFileName,
 DSA^ DSAKey )
{
   
   // Create a SignedXml Object*.
   SignedXml^ signedXml = gcnew SignedXml;
   
   // Assign the DSA key to the SignedXml object.
   signedXml->SigningKey = DSAKey;
   
   // Create a reference to be signed.
   Reference^ reference = gcnew Reference;
   
   // Add the passed URI to the reference object.
   reference->Uri = URIString;
   
   // Add the reference to the SignedXml object.
   signedXml->AddReference( reference );
   
   // Add a DSAKeyValue to the KeyInfo (optional; helps recipient find
 key to validate).
   KeyInfo^ keyInfo = gcnew KeyInfo;
   keyInfo->AddClause( gcnew DSAKeyValue( safe_cast<DSA^>(DSAKey) ) );
   signedXml->KeyInfo = keyInfo;
   
   // Compute the signature.
   signedXml->ComputeSignature();
   
   // Get the XML representation of the signature and save
   // it to an XmlElement object.
   XmlElement^ xmlDigitalSignature = signedXml->GetXml();
   
   // Save the signed XML document to a file specified
   // using the passed string.
   XmlTextWriter^ xmltw = gcnew XmlTextWriter( XmlSigFileName,gcnew UTF8Encoding(
 false ) );
   xmlDigitalSignature->WriteTo( xmltw );
   xmltw->Close();
}


// Sign an XML file and save the signature in a new file.
public static void SignDetachedResource(String
 uriString, 
    String xmlSigFileName, DSA dsaKey) 
{
    // Create a SignedXml object.
    SignedXml signedXml =  new SignedXml();
    
    // Assign the DSA key to the SignedXml object.
    signedXml.set_SigningKey ( dsaKey);
    
    // Create a reference to be signed.
    Reference reference =  new Reference();
    
    // Add the passed URI to the reference object.
    reference.set_Uri ( uriString);
    
    // Add a transformation if the URI is an XML file.
    if (uriString.EndsWith("xml")) {
        reference.AddTransform(new XmlDsigC14NTransform());
    }
    
    // Add the reference to the SignedXml object.
    signedXml.AddReference(reference);
    
    // Add a DSAKeyValue to the KeyInfo (optional; 
    // helps recipient find key to validate).
    KeyInfo keyInfo =  new KeyInfo();
    keyInfo.AddClause(new DSAKeyValue(((DSA)(dsaKey))));
    signedXml.set_KeyInfo ( keyInfo);
    
    // Compute the signature.
    signedXml.ComputeSignature();
    
    // Get the XML representation of the signature and save
    // it to an XmlElement object.
    XmlElement xmlDigitalSignature = signedXml.GetXml();
    
    // Save the signed XML document to a file specified
    // using the passed string.
    XmlTextWriter xmlTW =  
        new XmlTextWriter(xmlSigFileName, new
 UTF8Encoding(false));
    xmlDigitalSignature.WriteTo(xmlTW);
    xmlTW.Close();
} //SignDetachedResource   
' Sign an XML file and save the signature in a new file.
Public Shared Sub SignXmlFile(FileName
 As String, SignedFileName As
 String, DSAKey As DSA)
   ' Create a new XML document.
   Dim doc As New XmlDocument()
   
   ' Format the document to ignore white spaces.
   doc.PreserveWhitespace = False
   
   ' Load the passed XML file using it's name.
   doc.Load(New XmlTextReader(FileName))
   
   ' Create a SignedXml object.
   Dim signedXml As New
 SignedXml(doc)
   
   ' Add the DSA key to the SignedXml document. 
   signedXml.SigningKey = DSAKey
   
   ' Create a reference to be signed.
   Dim reference As New
 Reference()
   reference.Uri = ""
   
   ' Add a transformation to the reference.
   Dim trns = New XmlDsigC14NTransform()
   reference.AddTransform(trns)
   
   ' Add an enveloped transformation to the reference.
   Dim env As New XmlDsigEnvelopedSignatureTransform()
   reference.AddTransform(env)
   
   ' Add the reference to the SignedXml object.
   signedXml.AddReference(reference)
   
   
   ' Add a DSAKeyValue to the KeyInfo (optional; helps recipient find
 key to validate).
   Dim keyInfo As New KeyInfo()
   keyInfo.AddClause(New DSAKeyValue(CType(DSAKey, DSA)))
   signedXml.KeyInfo = keyInfo
   
   ' Compute the signature.
   signedXml.ComputeSignature()
   
   ' Get the XML representation of the signature and save
   ' it to an XmlElement object.
   Dim xmlDigitalSignature As XmlElement =
 signedXml.GetXml()
   
   ' Append the element to the XML document.
   doc.DocumentElement.AppendChild(doc.ImportNode(xmlDigitalSignature, True))
   
   
   If TypeOf doc.FirstChild Is
 XmlDeclaration Then
      doc.RemoveChild(doc.FirstChild)
   End If
   
   ' Save the signed XML document to a file specified
   ' using the passed string.
   Dim xmltw As New XmlTextWriter(SignedFileName,
 New UTF8Encoding(False))
   doc.WriteTo(xmltw)
   xmltw.Close()
End Sub 

// Sign an XML file and save the signature in a new file.
public static void SignXmlFile(string
 FileName, string SignedFileName, DSA DSAKey)
{
    // Create a new XML document.
    XmlDocument doc = new XmlDocument();

    // Format the document to ignore white spaces.
    doc.PreserveWhitespace = false;

    // Load the passed XML file using it's name.
    doc.Load(new XmlTextReader(FileName));

    // Create a SignedXml object.
    SignedXml signedXml = new SignedXml(doc);

    // Add the DSA key to the SignedXml document. 
    signedXml.SigningKey = DSAKey;

    // Create a reference to be signed.
    Reference reference = new Reference();
    reference.Uri = "";

    // Add a transformation to the reference.
    Transform trns = new XmlDsigC14NTransform();
    reference.AddTransform(trns);

    // Add an enveloped transformation to the reference.
    XmlDsigEnvelopedSignatureTransform env = new XmlDsigEnvelopedSignatureTransform();
    reference.AddTransform(env);

    // Add the reference to the SignedXml object.
    signedXml.AddReference(reference);

    
    // Add a DSAKeyValue to the KeyInfo (optional; helps recipient find
 key to validate).
    KeyInfo keyInfo = new KeyInfo();
    keyInfo.AddClause(new DSAKeyValue((DSA)DSAKey));
    signedXml.KeyInfo = keyInfo;

    // Compute the signature.
    signedXml.ComputeSignature();

    // Get the XML representation of the signature and save
    // it to an XmlElement object.
    XmlElement xmlDigitalSignature = signedXml.GetXml();

    // Append the element to the XML document.
    doc.DocumentElement.AppendChild(doc.ImportNode(xmlDigitalSignature, true));
    
    
    if (doc.FirstChild is XmlDeclaration)  
    {
        doc.RemoveChild(doc.FirstChild);
    }

    // Save the signed XML document to a file specified
    // using the passed string.
    XmlTextWriter xmltw = new XmlTextWriter(SignedFileName, new
 UTF8Encoding(false));
    doc.WriteTo(xmltw);
    xmltw.Close();
}
// Sign an XML file and save the signature in a new file.
void SignXmlFile( String^ FileName, String^ SignedFileName, DSA^
 DSAKey )
{
   
   // Create a new XML document.
   XmlDocument^ doc = gcnew XmlDocument;
   
   // Format the document to ignore white spaces.
   doc->PreserveWhitespace = false;
   
   // Load the passed XML file using its name.
   doc->Load( gcnew XmlTextReader( FileName ) );
   
   // Create a SignedXml object.
   SignedXml^ signedXml = gcnew SignedXml( doc );
   
   // Add the DSA key to the SignedXml document. 
   signedXml->SigningKey = DSAKey;
   
   // Create a reference to be signed.
   Reference^ reference = gcnew Reference;
   reference->Uri = "";
   
   // Add a transformation to the reference.
   Transform^ trns = gcnew XmlDsigC14NTransform;
   reference->AddTransform( trns );
   
   // Add an enveloped transformation to the reference.
   XmlDsigEnvelopedSignatureTransform^ env = gcnew XmlDsigEnvelopedSignatureTransform;
   reference->AddTransform( env );
   
   // Add the reference to the SignedXml object.
   signedXml->AddReference( reference );
   
   // Add a DSAKeyValue to the KeyInfo (optional; helps recipient find
 key to validate).
   KeyInfo^ keyInfo = gcnew KeyInfo;
   keyInfo->AddClause( gcnew DSAKeyValue( safe_cast<DSA^>(DSAKey) ) );
   signedXml->KeyInfo = keyInfo;
   
   // Compute the signature.
   signedXml->ComputeSignature();
   
   // Get the XML representation of the signature and save
   // it to an XmlElement object.
   XmlElement^ xmlDigitalSignature = signedXml->GetXml();
   
   // Append the element to the XML document.
   doc->DocumentElement->AppendChild( doc->ImportNode( xmlDigitalSignature,
 true ) );
   if ( (doc->FirstChild)->GetType() == XmlDeclaration::typeid
 )
   {
      doc->RemoveChild( doc->FirstChild );
   }

   
   // Save the signed XML document to a file specified
   // using the passed string.
   XmlTextWriter^ xmltw = gcnew XmlTextWriter( SignedFileName,gcnew UTF8Encoding(
 false ) );
   doc->WriteTo( xmltw );
   xmltw->Close();
}


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

DSAKeyValue コンストラクタ


DSAKeyValue コンストラクタ ()




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

辞書ショートカット

すべての辞書の索引

「DSAKeyValue コンストラクタ」の関連用語

DSAKeyValue コンストラクタのお隣キーワード
検索ランキング

   

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



DSAKeyValue コンストラクタのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2024 GRAS Group, Inc.RSS