AWS SDK Version 3 for .NET
API Reference

AWS services or capabilities described in AWS Documentation may vary by region/location. Click Getting Started with Amazon AWS to see specific differences applicable to the China (Beijing) Region.

Creates a digital signature for a message or message digest by using the private key in an asymmetric signing KMS key. To verify the signature, use the Verify operation, or use the public key in the same asymmetric KMS key outside of KMS. For information about asymmetric KMS keys, see Asymmetric KMS keys in the Key Management Service Developer Guide.

Digital signatures are generated and verified by using asymmetric key pair, such as an RSA or ECC pair that is represented by an asymmetric KMS key. The key owner (or an authorized user) uses their private key to sign a message. Anyone with the public key can verify that the message was signed with that particular private key and that the message hasn't changed since it was signed.

To use the Sign operation, provide the following information:

When signing a message, be sure to record the KMS key and the signing algorithm. This information is required to verify the signature.

Best practices recommend that you limit the time during which any signature is effective. This deters an attack where the actor uses a signed message to establish validity repeatedly or long after the message is superseded. Signatures do not include a timestamp, but you can include a timestamp in the signed message to help you detect when its time to refresh the signature.

To verify the signature that this operation generates, use the Verify operation. Or use the GetPublicKey operation to download the public key and then use the public key to verify the signature outside of KMS.

The KMS key that you use for this operation must be in a compatible key state. For details, see Key states of KMS keys in the Key Management Service Developer Guide.

Cross-account use: Yes. To perform this operation with a KMS key in a different Amazon Web Services account, specify the key ARN or alias ARN in the value of the KeyId parameter.

Required permissions: kms:Sign (key policy)

Related operations: Verify

Eventual consistency: The KMS API follows an eventual consistency model. For more information, see KMS eventual consistency.

Note:

For .NET Core this operation is only available in asynchronous form. Please refer to SignAsync.

Namespace: Amazon.KeyManagementService
Assembly: AWSSDK.KeyManagementService.dll
Version: 3.x.y.z

Syntax

C#
public virtual SignResponse Sign(
         SignRequest request
)

Parameters

request
Type: Amazon.KeyManagementService.Model.SignRequest

Container for the necessary parameters to execute the Sign service method.

Return Value


The response from the Sign service method, as returned by KeyManagementService.

Exceptions

ExceptionCondition
DependencyTimeoutException The system timed out while trying to fulfill the request. You can retry the request.
DisabledException The request was rejected because the specified KMS key is not enabled.
DryRunOperationException The request was rejected because the DryRun parameter was specified.
InvalidGrantTokenException The request was rejected because the specified grant token is not valid.
InvalidKeyUsageException The request was rejected for one of the following reasons: The KeyUsage value of the KMS key is incompatible with the API operation. The encryption algorithm or signing algorithm specified for the operation is incompatible with the type of key material in the KMS key (KeySpec). For encrypting, decrypting, re-encrypting, and generating data keys, the KeyUsage must be ENCRYPT_DECRYPT. For signing and verifying messages, the KeyUsage must be SIGN_VERIFY. For generating and verifying message authentication codes (MACs), the KeyUsage must be GENERATE_VERIFY_MAC. For deriving key agreement secrets, the KeyUsage must be KEY_AGREEMENT. To find the KeyUsage of a KMS key, use the DescribeKey operation. To find the encryption or signing algorithms supported for a particular KMS key, use the DescribeKey operation.
KeyUnavailableException The request was rejected because the specified KMS key was not available. You can retry the request.
KMSInternalException The request was rejected because an internal exception occurred. The request can be retried.
KMSInvalidStateException The request was rejected because the state of the specified resource is not valid for this request. This exceptions means one of the following: The key state of the KMS key is not compatible with the operation. To find the key state, use the DescribeKey operation. For more information about which key states are compatible with each KMS operation, see Key states of KMS keys in the Key Management Service Developer Guide. For cryptographic operations on KMS keys in custom key stores, this exception represents a general failure with many possible causes. To identify the cause, see the error message that accompanies the exception.
NotFoundException The request was rejected because the specified entity or resource could not be found.

Examples

This operation uses the private key in an asymmetric elliptic curve (ECC) KMS key to generate a digital signature for a given message.

To digitally sign a message with an asymmetric KMS key.


var client = new AmazonKeyManagementServiceClient();
var response = client.Sign(new SignRequest 
{
    KeyId = "alias/ECC_signing_key", // The asymmetric KMS key to be used to generate the digital signature. This example uses an alias of the KMS key.
    Message = new MemoryStream(<message to be signed>), // Message to be signed. Use Base-64 for the CLI.
    MessageType = "RAW", // Indicates whether the message is RAW or a DIGEST.
    SigningAlgorithm = "ECDSA_SHA_384" // The requested signing algorithm. This must be an algorithm that the KMS key supports.
});

string keyId = response.KeyId; // The key ARN of the asymmetric KMS key that was used to sign the message.
MemoryStream signature = response.Signature; // The digital signature of the message.
string signingAlgorithm = response.SigningAlgorithm; // The actual signing algorithm that was used to generate the signature.

            

This operation uses the private key in an asymmetric RSA signing KMS key to generate a digital signature for a message digest. In this example, a large message was hashed and the resulting digest is provided in the Message parameter. To tell KMS not to hash the message again, the MessageType field is set to DIGEST

To digitally sign a message digest with an asymmetric KMS key.


var client = new AmazonKeyManagementServiceClient();
var response = client.Sign(new SignRequest 
{
    KeyId = "alias/RSA_signing_key", // The asymmetric KMS key to be used to generate the digital signature. This example uses an alias of the KMS key.
    Message = new MemoryStream(<message digest to be signed>), // Message to be signed. Use Base-64 for the CLI.
    MessageType = "DIGEST", // Indicates whether the message is RAW or a DIGEST. When it is RAW, KMS hashes the message before signing. When it is DIGEST, KMS skips the hashing step and signs the Message value.
    SigningAlgorithm = "RSASSA_PKCS1_V1_5_SHA_256" // The requested signing algorithm. This must be an algorithm that the KMS key supports.
});

string keyId = response.KeyId; // The key ARN of the asymmetric KMS key that was used to sign the message.
MemoryStream signature = response.Signature; // The digital signature of the message.
string signingAlgorithm = response.SigningAlgorithm; // The actual signing algorithm that was used to generate the signature.

            

Version Information

.NET Framework:
Supported in: 4.5 and newer, 3.5

See Also