Export (0) Print
Expand All

RSAPKCS1SignatureFormatter.CreateSignature Method (Byte[])

Creates the RSA PKCS #1 signature for the specified data.

Namespace: System.Security.Cryptography
Assembly: mscorlib (in mscorlib.dll)

'Declaration
Public Overrides Function CreateSignature ( _
	rgbHash As Byte() _
) As Byte()
'Usage
Dim instance As RSAPKCS1SignatureFormatter
Dim rgbHash As Byte()
Dim returnValue As Byte()

returnValue = instance.CreateSignature(rgbHash)
public byte[] CreateSignature (
	byte[] rgbHash
)
public override function CreateSignature (
	rgbHash : byte[]
) : byte[]
Not applicable.

Parameters

rgbHash

The data to be signed.

Return Value

The digital signature for rgbHash.

Exception typeCondition

CryptographicUnexpectedOperationException

The key is a null reference (Nothing in Visual Basic).

-or-

The hash algorithm is a null reference (Nothing in Visual Basic).

ArgumentNullException

The rgbHash parameter is a null reference (Nothing in Visual Basic).

You must specify a key and a hash algorithm before calling this method.

Imports System
Imports System.Security.Cryptography

 _

Class RSASample


    Shared Sub Main()
        Try
            'Create a new instance of RSACryptoServiceProvider.
            Dim RSA As New RSACryptoServiceProvider()

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

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

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

            'Create a signature for HashValue and return it.
            Dim SignedHash As Byte() = RSAFormatter.CreateSignature(Hash)


        Catch e As CryptographicException
            Console.WriteLine(e.Message)
        End Try
    End Sub
End Class

import System.*;
import System.Security.Cryptography.*;

class RSASample
{
    public static void main(String[] args)
    {
        try {
            // Create a new instance of RSACryptoServiceProvider.
            RSACryptoServiceProvider rsa =  new RSACryptoServiceProvider();
            
            //The hash to sign.
            ubyte hash[] =  {59, 4, 248, 102, 77, 97, 142, 201, 210, 12, 
                224, 93, 25, 41, 100, 197, 213, 134, 130, 135};
            
            // Create an RSAOPKCS1SignatureFormatter object and pass it the 
            // RSACryptoServiceProvider to transfer the key information.
            RSAPKCS1SignatureFormatter rsaFormatter =  
                new RSAPKCS1SignatureFormatter(rsa);
            
            // Set the hash algorithm to SHA1.
            rsaFormatter.SetHashAlgorithm("SHA1");
            
            // Create a signature for HashValue and return it.
            ubyte signedHash[] = rsaFormatter.CreateSignature(hash);
        } 
        catch (CryptographicException e) {
            Console.WriteLine(e.get_Message());
        }
    } //main
} //RSASample

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2014 Microsoft