KeyUsage= ASYMMETRIC_SIGN_VERIFY_RSA_2048 is required when calling the CreateKey API to create a CMK.tccli kms CreateKey --Alias test_rsa --KeyUsage ASYMMETRIC_SIGN_VERIFY_RSA_2048
{"Response": {"KeyId": "22d79428-61d9-11ea-a3c8-525400******","Alias": "test_rsa","CreateTime": 1583739580,"Description": "","KeyState": "Enabled","KeyUsage": "ASYMMETRIC_SIGN_VERIFY_RSA_2048","TagCode": 0,"TagMsg": "","RequestId": "0e3c62db-a408-406a-af27-dd5ced******"}}
tccli kms GetPublicKey --KeyId 22d79428-61d9-11ea-a3c8-525400******
{"Response": {"RequestId": "408fa858-cd6d-4011-b8a0-653805******","KeyId": "22d79428-61d9-11ea-a3c8-525400******","PublicKey": "MFkwEwYHKoZIzj0CAQYIKoEcz1UBgi0DQgAEFLlge0vtct949CwtadHODzisgXJahujq+PvM***************bBs/f3axWbvgvHx8Jmqw==","PublicKeyPem": "-----BEGIN PUBLIC KEY-----\\nMFkwEwYHKoZIzj0CAQYIKoEcz1UBgi0DQgAEFLlge0vtct949CwtadHODzisgXJa\\nhujq+PvM***************bBs/f3axWbvgvHx8Jmqw==\\n-----END PUBLIC KEY-----\\n"}}
PublicKeyPem into the PEM format and save it in the file public_key.pem.echo "-----BEGIN PUBLIC KEY-----MFkwEwYHKoZIzj0CAQYIKoEcz1UBgi0DQgAEFLlge0vtct949CwtadHODzisgXJahujq+PvM***************bBs/f3axWbvgvHx8Jmqw==-----END PUBLIC KEY-----" > public_key.pem
echo "test" > test_verify.txt
test_verity.txt.openssl dgst -sha256 -binary -out digest.bin test_verify.txt
// Base64-encode the message abstractopenssl enc -e -base64 -A -in digest.bin -out encoded.base64// Base64-encode the original messageopenssl enc -e -base64 -A -in test_verify.txt -out encoded.base64
// Generate the signature for the message abstract using the content of the file `encoded.base64` as the `Message` parameter of `SignByAsymmetricKey`.tccli kms SignByAsymmetricKey --KeyId 22d79428-61d9-11ea-a3c8-525400****** --Algorithm RSA_PSS_SHA_256 --Message "qJQj83hSyOuU7Tn0SRReGCk4yuuVWaeZ44BP******==" --MessageType DIGEST// Generate the signature for the Base64-encoded original messagetccli kms SignByAsymmetricKey --KeyId 22d79428-61d9-11ea-a3c8-525400****** --Algorithm RSA_PSS_SHA_256 --Message "dG***Ao=" --MessageType RAW
// Generate the signature for the message abstract using the content of the file `encoded.base64` as the `Message` parameter of `SignByAsymmetricKey`.tccli kms SignByAsymmetricKey --KeyId 22d79428-61d9-11ea-a3c8-525400****** --Algorithm RSA_PKCS1_SHA_256 --Message "qJQj83hSyOuU7Tn0SRReGCk4yuuVWaeZ44BP******==" --MessageType DIGEST// Generate the signature for the Base64-encoded original messagetccli kms SignByAsymmetricKey --KeyId 22d79428-61d9-11ea-a3c8-525400****** --Algorithm RSA_PKCS1_SHA_256 --Message "dG***Ao=" --MessageType RAW
{"Response": {"Signature": "U7Tn0SRReGCk4yuuVWaeZ4******","RequestId": "408fa858-cd6d-4011-b8a0-653805******"}}
Signature in the file signContent.sign:echo "U7Tn0SRReGCk4yuuVWaeZ4******" | base64 -d > signContent.bin
// Verify the message abstract (verify the signature for the message abstract using the content of the file `encoded.base64` mentioned in step 4 as the `Message` parameter of `VerifyByAsymmetricKey`).tccli kms VerifyByAsymmetricKey --KeyId 22d79428-61d9-11ea-a3c8-525400****** --SignatureValue "U7Tn0SRReGCk4yuuVWaeZ4******" --Message "QUuAcNFr1Jl5+3GDbCxU7te7Uekq+oTxZ**********=" --Algorithm RSA_PSS_SHA_256 --MessageType DIGEST// Verify the Base64-encoded original message.tccli kms VerifyByAsymmetricKey --KeyId 22d79428-61d9-11ea-a3c8-525400****** --SignatureValue "U7Tn0SRReGCk4yuuVWaeZ4******" --Message "dG***Ao=" --Algorithm RSA_PSS_SHA_256 --MessageType RAW
// Verify the message abstract (verify the signature for the message abstract using the content of the file `encoded.base64` mentioned in step 4 as the `Message` parameter of `VerifyByAsymmetricKey`).tccli kms VerifyByAsymmetricKey --KeyId 22d79428-61d9-11ea-a3c8-525400****** --SignatureValue "U7Tn0SRReGCk4yuuVWaeZ4******" --Message "QUuAcNFr1Jl5+3GDbCxU7te7Uekq+oTxZ**********=" --Algorithm RSA_PKCS1_SHA_256 --MessageType DIGEST// Verify the Base64-encoded original message.tccli kms VerifyByAsymmetricKey --KeyId 22d79428-61d9-11ea-a3c8-525400****** --SignatureValue "U7Tn0SRReGCk4yuuVWaeZ4******" --Message "dG***Ao=" --Algorithm RSA_PKCS1_SHA_256 --MessageType RAW
{"Response": {"SignatureValid": true,"RequestId": "6758cbf5-5e21-4c37-a2cf-8d47f5******"}}
Message and MessageType used in the signature API call should be the same as those of the signature verification API call.// Use the `RSA_PSS_SHA_256` algorithm to verify the signature.openssl dgst -verify public_key.pem -sha256 -sigopt rsa_padding_mode:pss -sigopt rsa_pss_saltlen:-1 -signature ./signContent.bin ./test_verify.txt// Use the `RSA_PKCS1_SHA_256` algorithm to verify the signature.openssl dgst -verify public_key.pem -sha256 -signature ./signContent.bin ./test_verify.txt
Verified OK
Feedback