다음을 통해 공유


서명 생성

업데이트: 2007년 11월

디지털 서명은 대개 보다 큰 데이터를 나타내는 해시 값에 적용됩니다. 다음 예제에서는 해시 값에 디지털 서명을 적용합니다. 먼저 RSACryptoServiceProvider 클래스의 새 인스턴스가 만들어져 공개/개인 키 쌍을 생성합니다. 다음에는 RSACryptoServiceProviderRSAPKCS1SignatureFormatter 클래스의 새 인스턴스에 전달됩니다. 이 클래스는 실제로 디지털 서명을 수행하는 RSAPKCS1SignatureFormatter에 개인 키를 전송합니다. 해시 코드에 서명하려면 먼저 사용할 해시 알고리즘을 지정해야 합니다. 이 예제에서는 SHA1 알고리즘을 사용합니다. 마지막으로, RSAPKCS1SignatureFormatter.CreateSignature 메서드가 호출되어 서명을 수행합니다.

Imports System
Imports System.Security.Cryptography

Module Module1
    Sub Main()
        'The hash value to sign.
        Dim HashValue As Byte() = {59, 4, 248, 102, 77, 97, 142, 201, 210, 12, 224, 93, 25, 41, 100, 197, 213, 134, 130, 135}

        'The value to hold the signed value.
        Dim SignedHashValue() As Byte

        'Generate a public/private key pair.
        Dim RSA As New RSACryptoServiceProvider()

        'Create an RSAPKCS1SignatureFormatter object and pass it 
        'the RSACryptoServiceProvider to transfer the private key.
        Dim RSAFormatter As New RSAPKCS1SignatureFormatter(RSA)

        'Set the hash algorithm to SHA1.
        RSAFormatter.SetHashAlgorithm("SHA1")

        'Create a signature for HashValue and assign it to 
        'SignedHashValue.
        SignedHashValue = RSAFormatter.CreateSignature(HashValue)
    End Sub
End Module

using System;
using System.Security.Cryptography;
class Class1
{
   static void Main()
   {
      //The hash value to sign.
      byte[] HashValue = {59,4,248,102,77,97,142,201,210,12,224,93,25,41,100,197,213,134,130,135};

      //The value to hold the signed value.
      byte[] SignedHashValue;

      //Generate a public/private key pair.
      RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();

      //Create an RSAPKCS1SignatureFormatter object and pass it the 
      //RSACryptoServiceProvider to transfer the private key.
      RSAPKCS1SignatureFormatter RSAFormatter = new RSAPKCS1SignatureFormatter(RSA);

      //Set the hash algorithm to SHA1.
      RSAFormatter.SetHashAlgorithm("SHA1");

      //Create a signature for HashValue and assign it to 
      //SignedHashValue.
      SignedHashValue = RSAFormatter.CreateSignature(HashValue);
   }
}

XML 파일 서명

.NET Framework에서는 XML에 서명하는 데 사용할 수 있는 System.Security.Cryptography.XML 네임스페이스를 제공합니다. XML이 특정 소스에서 온 것임을 확인하려면 XML에 서명해야 합니다. 예를 들어, XML을 사용하는 주식 시세 서비스를 사용하는 경우 XML에 서명이 있으면 해당 XML의 소스를 확인할 수 있습니다.

이 네임스페이스의 클래스는 www.w3.org에 설명된 World Wide Web 컨소시엄의 "XML-서명 구문 및 처리" 권장 사항에 따릅니다.

참고 항목

개념

서명 확인

암호화 서명

기타 리소스

암호화 작업

암호화 서비스