文書番号: 280391 - 最終更新日: 2007年10月25日 - リビジョン: 4.5

署名されたメッセージ CDOSYS/CDOEX によるデジタルに送信する方法

目次

すべて展開する | すべて折りたたむ

概要

マイクロソフト コラボレーション データ オブジェクトを Windows 2000 (CDOSYS) とマイクロソフト コラボレーション データ オブジェクトの Exchange 2000 (CDOEX) はいない直接手段を提供をデジタル署名またはメッセージを暗号化します。 アプリケーション プログラミング インターフェイス (API) は、有効な署名を生成する機能を公開されません。 ただし、CDOSYS または CDOEX と組み合わせて、暗号化 API を使用してデジタル署名やメッセージを暗号化できます。

詳細

使用して COM バージョン、暗号化 API (CAPICOM) の簡単に署名または CDOSYS または CDOEX メッセージを暗号化します。 CAPICOM DLL、次のマイクロソフトから入手できます"プラットフォーム SDK Redistributable: CAPICOM 1.0A"Web サイト。
http://www.microsoft.com/downloads/details.aspx?FamilyID=860ee43a-a843-462f-abb5-ff88ea5896f6&DisplayLang=en (http://www.microsoft.com/downloads/details.aspx?FamilyID=860ee43a-a843-462f-abb5-ff88ea5896f6&DisplayLang=en)

メッセージにデジタル署名

  1. CDOSYS または CDOEX IMessage オブジェクトを始めます。 送信者、受信者、件名、本文、添付ファイル、および他の必要なアイテムには、このメッセージを構成します。
  2. 新しい IMessage オブジェクトを作成します。 手順 1 からこの新しいメッセージの IDatasource::OpenObject メソッドを使用して既存メッセージを開きます。
  3. 新しい IMessage オブジェクトの IBodyPart ルートを取得し、[次プロパティを設定:
    oBodyPart.ContentMediaType = "application/pkcs7-mime;smime-type=signed-data;name=""smime.p7m"""
    oBodyPart.ContentTransferEncoding = "base64"
    oBodyPart.Fields("urn:schemas:mailheader:content-disposition") = "attachment;FileName=""smime.p7m"""
    oBodyPart.Fields.Update
    					
  4. CAPICOM の署名者オブジェクトと送信者の証明書を使用して、新しい IMessage オブジェクトのコンテンツの署名にします。
  5. 新しいメッセージを送受信し、元のメッセージを破棄します。

メッセージの暗号化

  1. CDOSYS または CDOEX IMessage オブジェクトを始めます。 送信者、受信者、件名、本文、添付ファイル、および他の必要なアイテムには、このメッセージを構成します。
  2. 新しい IMessage オブジェクトを作成します。 手順 1 からこの新しいメッセージの IDatasource::OpenObject メソッドを使用して既存メッセージを開きます。
  3. 新しい IMessage オブジェクトの IBodyPart ルートを取得し、[次プロパティを設定:
    oBodyPart.ContentMediaType = "application/pkcs7-mime;smime-type=enveloped-data;name=smime.p7m;"
    oBodyPart.ContentTransferEncoding = "base64"
    oBodyPart.Fields("urn:schemas:mailheader:content-disposition") = "attachment;FileName=""smime.p7m"""
    oBodyPart.Fields.Update
    					
  4. CAPICOM EnvelopedData オブジェクトと受信者の証明書を使用して、新しい IMessage オブジェクトの内容を暗号化します。
  5. 新しいメッセージを送信し、元の破棄します。

デジタル署名とメッセージの暗号化

手順は、同じが、順序が重要です。 まず、メッセージを署名し、メッセージを暗号化してください。

サンプル コード

サンプル コードについてのメモ

  • サンプルは GetCertForSignature GetCertForEnvelope nothing の関数が 2 つを呼び出します。 プログラマは適切なの証明書を取得する必要があります。
  • サンプル コードは、CAPICOM 1. 0 タイプ ライブラリ、Microsoft ActiveX データ オブジェクトの 2. 5 ライブラリ、および適切な CDO ライブラリへの参照が必要です。
'******************************************************************
'
' SignMessage
'
' Takes oMsg as input (non-secure message) and returns a new
' message that is digitally signed.
'
'******************************************************************
Public Function SignMessage(oMsg As CDO.Message) As CDO.Message
    Dim oSecMsg As New CDO.Message
    Dim oBodyPart As CDO.IBodyPart
    Dim oSignedData As New CAPICOM.SignedData
    Dim strData As String
    Dim strContent As String
    Dim oStream As ADODB.Stream
    Dim oSigner As New CAPICOM.Signer
    Dim oCert As CAPICOM.Certificate
    Dim oAttr As New CAPICOM.Attribute
    Dim byteData() As Byte
    
    On Error GoTo handle_error
    
    ' Copy input into output message
    oSecMsg.DataSource.OpenObject oMsg, cdoIMessage
    
    ' Set up main bodypart
    Set oBodyPart = oSecMsg.BodyPart
    oBodyPart.ContentMediaType = "application/pkcs7-mime;smime-type=signed-data;name=""smime.p7m"""
    oBodyPart.ContentTransferEncoding = "base64"
    oBodyPart.Fields("urn:schemas:mailheader:content-disposition") = "attachment;FileName=""smime.p7m"""
    oBodyPart.Fields.Update
            
    ' Get certificate
    Set oCert = GetCertForSignature(oSecMsg.From)
    
    ' If no cert, throw an error and exit
    If oCert Is Nothing Then
        MsgBox "No valid certificate found for sender.", , "Error"
        Set SignMessage = Nothing
    End If
    
    ' Add cert to signer object
    oSigner.Certificate = oCert
    
    ' Add signing time attribute to signer object
    oAttr.Name = CAPICOM_AUTHENTICATED_ATTRIBUTE_SIGNING_TIME
    oAttr.Value = Now
    oSigner.AuthenticatedAttributes.Add oAttr

    ' Sign the content (root bodypart)
    strContent = oMsg.BodyPart.GetStream.ReadText
    oSignedData.Content = StrConv(strContent, vbFromUnicode)

    strData = oSignedData.Sign(oSigner, False, CAPICOM_ENCODE_BINARY)

    ' Write the cms blob into the main bodypart
    ' let CDO do the base64 encoding
    Set oStream = oSecMsg.BodyPart.GetDecodedContentStream
    
    oStream.Type = adTypeBinary

    ' Get the string data as a byte array
    byteData = strData
    
    ' Write the data to the stream and flush it
    oStream.Write byteData
    oStream.Flush
    
    GoTo cleanup
    
    ' Report error
handle_error:
    MsgBox Err.Number & ": " & Err.Description, , "Error:"
    Set oSecMsg = Nothing
    
    ' Clean up memory
cleanup:
    Set oBodyPart = Nothing
    Set oSignedData = Nothing
    Set oStream = Nothing
    Set oSigner = Nothing
    Set oCert = Nothing
    Set oAttr = Nothing
    
    ' Return new message
    Set SignMessage = oSecMsg
End Function

'******************************************************************
'
' EnvelopeMessage
'
' Takes oMsg as input (non-secure message) and returns a new
' message that is enveloped.
'
'******************************************************************
Public Function EnvelopeMessage(oMsg As CDO.Message, iCertStore As Integer, Optional strQuery As String) As CDO.Message
    Dim oSecMsg As New CDO.Message
    Dim oBodyPart As CDO.IBodyPart
    Dim oEnvelopedData As New CAPICOM.EnvelopedData
    Dim oCert As CAPICOM.Certificate
    Dim oStream As ADODB.Stream
    Dim strData As String
    Dim strContent As String
    Dim byteData() As Byte
    
    ' Copy input into output message
    oSecMsg.DataSource.OpenObject oMsg, cdoIMessage
    
    ' Set up main bodypart
    Set oBodyPart = oSecMsg.BodyPart
    oBodyPart.ContentMediaType = "application/pkcs7-mime;smime-type=enveloped-data;name=smime.p7m;"

    oBodyPart.ContentTransferEncoding = "base64"
    oBodyPart.Fields("urn:schemas:mailheader:content-disposition") = "attachment;FileName=""smime.p7m"""
    oBodyPart.Fields.Update
    
    ' Get recipient's cert
    If strQuery = "" Then
        Set oCert = GetCertForEnvelope(oSecMsg.To, iCertStore)
    Else
        Set oCert = GetCertForEnvelope(oSecMsg.To, iCertStore, strQuery)
    End If
    
    oEnvelopedData.Recipients.Add oCert
    
    ' Encrypt content
    strContent = oMsg.BodyPart.GetStream.ReadText
    oEnvelopedData.Content = StrConv(strContent, vbFromUnicode)
    strData = oEnvelopedData.Encrypt(CAPICOM_ENCODE_BINARY)
    
    ' Write the CMS blob into the main bodypart
    ' let CDO do the base64 encoding
    Set oStream = oSecMsg.BodyPart.GetDecodedContentStream
    
    oStream.Type = adTypeBinary
    
    ' Get the string data as a byte array
    byteData = strData
    
    ' Write the data to the stream and flush it
    oStream.Write byteData
    oStream.Flush
    
    GoTo cleanup
    
handle_error:
    MsgBox Err.Number & ": " & Err.Description, , "Error:"
    Set oSecMsg = Nothing
    
    ' Clean up memory
cleanup:
    Set oBodyPart = Nothing
    Set oEnvelopedData = Nothing
    Set oStream = Nothing
    Set oCert = Nothing
    
    ' Return new message
    Set EnvelopeMessage = oSecMsg
End Function
				

この資料は以下の製品について記述したものです。
  • Microsoft Exchange Server 2003 Enterprise Edition
  • Microsoft Exchange Server 2003 Standard Edition
  • Microsoft Exchange 2000 Server Standard Edition
  • Microsoft Windows Server 2003, Enterprise Edition (32-bit x86)
  • Microsoft Windows Server 2003, Standard Edition (32-bit x86)
  • Microsoft Windows 2000 Advanced Server
  • Microsoft Windows 2000 Server
  • Microsoft Windows 2000 Professional
  • Microsoft Windows XP Professional
  • Microsoft Windows XP Home Edition
  • Collaboration Data Objects for Exchange 2000
  • Microsoft Collaboration Data Objects 2.0
キーワード:?
kbmt kbenv kbhowto kbmsg KB280391 KbMtja
機械翻訳機械翻訳
重要: このサポート技術情報 (以下「KB」) は、翻訳者による翻訳の代わりに、マイクロソフト機械翻訳システムによって翻訳されたものです。マイクロソフトは、お客様に、マイクロソフトが提供している全ての KB を日本語でご利用いただけるように、翻訳者による翻訳 KB に加え機械翻訳 KB も提供しています。しかしながら、機械翻訳の品質は翻訳者による翻訳ほど十分ではありません。誤訳や、文法、言葉使い、その他、たとえば日本語を母国語としない方が日本語を話すときに間違えるようなミスを含んでいる可能性があります。マイクロソフトは、機械翻訳の品質、及び KB の内容の誤訳やお客様が KB を利用されたことによって生じた直接または間接的な問題や損害については、いかなる責任も負わないものとします。マイクロソフトは、機械翻訳システムの改善を継続的に行っています。
英語版 KB:280391? (http://support.microsoft.com/kb/280391/en-us/ )
"Microsoft Knowledge Baseに含まれている情報は、いかなる保証もない現状ベースで提供されるものです。Microsoft Corporation及びその関連会社は、市場性および特定の目的への適合性を含めて、明示的にも黙示的にも、一切の保証をいたしません。さらに、Microsoft Corporation及びその関連会社は、本文書に含まれている情報の使用及び使用結果につき、正確性、真実性等、いかなる表明・保証も行ないません。Microsoft Corporation、その関連会社及びこれらの権限ある代理人による口頭または書面による一切の情報提供またはアドバイスは、保証を意味するものではなく、かつ上記免責条項の範囲を狭めるものではありません。Microsoft Corporation、その関連会社 及びこれらの者の供給者は、直接的、間接的、偶発的、結果的損害、逸失利益、懲罰的損害、または特別損害を含む全ての損害に対して、状況のいかんを問わず一切責任を負いません。(Microsoft Corporation、その関連会社 またはこれらの者の供給者がかかる損害の発生可能性を了知している場合を含みます。) 結果的損害または偶発的損害に対する責任の免除または制限を認めていない地域においては、上記制限が適用されない場合があります。なお、本文書においては、文書の体裁上の都合により製品名の表記において商標登録表示、その他の商標表示を省略している場合がありますので、予めご了解ください。"
 

サポート技術情報の翻訳