---
sourceDocument: Yokohama 플랫폼 보안
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/ko-KR/yokohama/platform-security

 Release :

    - yokohama

ft:locale :

    - ko-KR

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 클래스는 세 가지 입력 매개변수에서 다이제스트 토큰을 만드는 방법을 보여줍니다.  
* strEncryptionMethod -- 해시 계산 방법(SHA1, SHA256 또는 MD5)을 나열합니다.
* 메시지 -- 다이제스트 토큰으로 변환할 값을 나열합니다.
* sharedKey -- 비밀 키를 나열합니다.
{#c_SampleC__ul_uwx_jyg_y4}  
주:  
다이제스트 토큰 생성을 위해 SHA256과 같은 더 강력한 보안 해시 알고리즘을 사용합니다.  
이 샘플에서는 다음을 가정합니다.

* 웹 서버는 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 ;
     
             }


