--- title: "Decryption" slug: "dsm-example-code-decryption" updated: 2026-03-23T05:24:51Z published: 2026-03-23T05:25:38Z canonical: "support.fortanix.com/dsm-example-code-decryption" --- > ## Documentation Index > Fetch the complete documentation index at: https://support.fortanix.com/llms.txt > Use this file to discover all available pages before exploring further. # Decryption - [C++](/docs/dsm-example-code-decryption#tabs-1) - [C#](/docs/dsm-example-code-decryption#tabs-2) - [Go](/docs/dsm-example-code-decryption#tabs-3) - [Java](/docs/dsm-example-code-decryption#tabs-4) - [Python](/docs/dsm-example-code-decryption#tabs-5) - [PHP](/docs/dsm-example-code-decryption#tabs-6) - [Javascript](/docs/dsm-example-code-decryption#tabs-7) - [REST API using curl](/docs/dsm-example-code-decryption#tabs-8) ### C++ ```bash string decrypt(CK_FUNCTION_LIST_PTR p11, CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hKey, string iv_cipher) { CK_RV rv; CK_BYTE *plain; CK_ULONG plain_len; string iv; string cipher; Base64::Decode(iv_cipher.substr(0, iv_cipher.find(':')), &iv); CK_MECHANISM mechanism = { CKM_AES_CBC_PAD, (CK_BYTE_PTR) iv.c_str(), iv.length() }; rv = p11->C_DecryptInit(hSession, &mechanism, hKey); if (rv == CKR_OK) { Base64::Decode(iv_cipher.substr(iv_cipher.find(':')+1, iv_cipher.length() - iv_cipher.find(':') + 1), &cipher); rv = p11->C_Decrypt(hSession, (CK_BYTE_PTR) cipher.c_str(), cipher.length(), NULL, &plain_len); if (rv == CKR_OK) { plain = (CK_BYTE *)malloc(plain_len * sizeof(CK_BYTE)); rv = p11->C_Decrypt(hSession, (CK_BYTE_PTR) cipher.c_str(), cipher.length(), plain, &plain_len); } } if (rv != CKR_OK) { cout << "Decryption failed. Error code = " << rv << endl; return string(); } return string((char*)plain, plain_len); } ``` ### C# ```plaintext public void decrypt() {    EncryptionAndDecryptionApi encryptionAndDecryptionApi = new EncryptionAndDecryptionApi();    DecryptRequest decReq = new DecryptRequest(Alg: ObjectType.AES, Mode: CryptMode.CBC, Cipher: cipher, Iv: encResp.Iv);    DecryptResponse decResp = encryptionAndDecryptionApi.Decrypt(key.Kid, decReq); } ``` ### Go ```bash iv := byte[]() keyId := decryptReq := sdkms.DecryptRequest{            Cipher: byte[](),            Iv: &iv            Alg: sdkms.AlgorithmAes,            Key: sdkms.SobjectById(keyId),            Mode: sdkms.CryptModeSymmetric(sdkms.CipherModeCbc), } decryptResp, err := client.Decrypt(ctx, decryptReq) decryptResp.Plain //decrypted plain text data ``` ### Java ```bash byte[] cipher, iv; DecryptRequest encryptRequest = new DecryptRequest(); decryptRequest       .alg(ObjectType.AES)       .cipher(cipher)       .mode(CryptMode.CBC)       .iv(iv); DecryptResponse decryptResponse = encryptionAndDecryptionApi.decrypt(, decryptRequest); decryptResponse.plain // decrypted plaintext data ``` ### Python ```bash cipher, iv api_instance = sdkms.v1.EncryptionAndDecryptionApi(api_client=client) request = sdkms.v1.DecryptRequest(alg=ObjectType.AES, cipher= cipher, iv=iv, mode=CipherMode.CBC) decryption_response = api_instance.decrypt(, request) decryption_response.plain #decrypted plain text data ``` ### PHP ```bash public function decrypt() {    $decryptionRequestBody = array('alg' => $objType::AES, 'mode' => $cryptMode::CBC, 'cipher' => $encRes['cipher'], 'iv' => $encRes['iv']);    $decryptionRequest = new Swagger\Client\Model\DecryptRequest($decryptionRequestBody);    $encryptionAndDecryptionApi = new Swagger\Client\Api\EncryptionAndDecryptionApi($client);    $decryptionResponse = $encryptionAndDecryptionApi->decrypt($securityObjectResponse["kid"], $decryptionRequest); } ``` ### Javascript ```bash var decryptCallback = function(error, data, response) {    if (error) {        console.error("Error: " + JSON.stringify(response));    } else {        console.log('Cipher decrypted successfully. result: ' + JSON.stringify(data));    } }; var encryptionAndDecryptionApi = new FortanixSdkmsRestApi.EncryptionAndDecryptionApi() var decryptRequest = FortanixSdkmsRestApi.DecrypttRequest.constructFromObject({"alg": "AES", "mode": "CBC", "cipher": "cipher"}) encryptionAndDecryptionApi.decrypt(data["kid"], decryptRequest, decryptCallback) ``` ### REST API using curl ```bash $ curl /crypto/v1/decrypt -H 'Authorization: Bearer YhXwwa-6C...ig5g' -d '{"key": {"kid": "Key-UUID"}, "alg": "AES", "mode": "CBC", "cipher": "YiBmaHViIGNpdXJlZyB1eXZpZyB2ZQoK", "iv": "Y25lYm4gdmVidmllamJ2ZWlqYgo="}' {"plain": "SGVsbG8gV29ybGQhCg=="} $ echo "SGVsbG8gV29ybGQhCg==" | base64 -d Hello World! ``` ## Related - [Encryption](/dsm-example-code-encryption.md) - [Key Operations](/fortanix-dsm-key-operations.md) - [Tips and tricks](/fortanix-ccm-tips-and-tricks.md) - [Add Quorum Approval Policy](/dsm-example-code-add-quorum-approval-policy.md)