---
sourceDocument: Yokohama プラットフォームセキュリティ
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/ja-JP/yokohama/platform-security

 Release :

    - yokohama

ft:locale :

    - ja-JP

ft:publication_title :

    - Yokohama プラットフォームセキュリティ

ft:clusterId :

    - psec

bundleId :

    - psec

workflow :

    - Platform


---

# サンプル C

# サンプル C {#ariaid-title1}

* リリースバージョン: Yokohama
* 
* 更新日 2025年01月30日
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 所要時間：2分

この C クラスは、3 つの入力パラメーターからダイジェストトークンを作成する方法を示しています。  
* strEncryptionMethod -- ハッシュ計算方法 (SHA1、SHA256、または MD5) をリスト
* message -- ダイジェストトークンに変換する値をリスト
* sharedKey -- 秘密キーをリスト
{#c_SampleC__ul_uwx_jyg_y4}  
注:  
ダイジェストトークンの生成には、SHA256 などのより強力で安全なハッシュアルゴリズムを使用します。  
この例では、以下を前提としています。

* Web サーバーは C をサポート
* 他のコードがこのクラスを呼び出し、予想されるパラメーターを渡す
{#c_SampleC__ul_fth_4yg_y4}

## サンプルコード

      private stringdigestData(string strEncryptionMethod , string message , string sharedKey ) {
                UnicodeEncoding myUnicodeEncoding  = new UnicodeEncoding ( ) ;
     
                byte [ ] messageBytes  = System. Text. Encoding. ASCII. GetBytes (message ) ;
                byte [ ] sharedKeyBytes  = System. Text. Encoding. ASCII. GetBytes (sharedKey ) ;
                byte [ ] hashedMessage ;
     
                string b64SHA1Message ;
     
                 if (this. DEBUG ) {
                    TextBoxMessage. Text = message ;
                    TextBoxSecret. Text = sharedKey ; }
     
                 switch ( (strEncryptionMethod ) )
     
                 { case "SHA1" :
     
                        HMACSHA1 hmacsha1  = new HMACSHA1 ( ) ;
                        hmacsha1. Key = sharedKeyBytes ;
                        hashedMessage  = hmacsha1. ComputeHash (messageBytes ) ;
                        b64SHA1Message  = Convert. ToBase64String (hashedMessage ) ; if (this. DEBUG ) TextBoxDigest. Text = Convert. ToString (hashedMessage ) ; break ;
     
                     case "MD5" :
     
                        HMACMD5 hmacmd5  = new HMACMD5 (sharedKeyBytes ) ;
                        hashedMessage  = hmacmd5. ComputeHash (messageBytes ) ;
                        b64SHA1Message  = Convert. ToBase64String (hashedMessage ) ; if (this. DEBUG ) TextBoxDigest. Text = Convert. ToString (hashedMessage ) ; break ;
     
                     default :
     
                        b64SHA1Message  = "Unknown Encryption Method" ; break ;
     
                 }
     
     
                TextBoxBase64. Text = b64SHA1Message ; return b64SHA1Message ;
     
             }


