You can refer to the below to accomplish the goal.
CLIENT
// Create RSA Key Pair
NCryptOpenStorageProvider
NCryptCreatePersistedKey("MyRSAKeyName") -> n_hRSAKey
NCryptFinalizeKey
// Export RSA Public Key blob
NCryptExportKey (n_hRSAKey, BCRYPT_RSAPUBLIC_BLOB ) -> n_pbRSAPublicKeyBlob
SERVER
// Import RSA Public Key Blob
NCryptOpenStorageProvider
NCryptImportKey(n_pbRSAPublicKeyBlob) -> n_hRSAPublicKey
// Generate Random AES Key
BCryptOpenAlgorithmProvider(BCRYPT_AES_ALGORITHM)
BCryptGenerateSymmetricKey(random AES key bytes) -> b_hAESKey
BCryptExportKey(b_hAESKey, BCRYPT_KEY_DATA_BLOB) -> b_pbAESKeyBlob, b_dwAESKeyBlobSize
// Create NCRYPT_CIPHER_KEY_BLOB
NCRYPT_KEY_BLOB_HEADER *pbCipherBlob;
DWORD dwCipherBlobSize;
LPCWSTR szwAESAlg[] = { NCRYPT_AES_ALGORITHM };
PBYTE pbPointer;
dwCipherBlobSize = sizeof(NCRYPT_KEY_BLOB_HEADER) + b_dwAESKeyBlobSize + ((wcslen(szwAESAlg[0]) + 1) * sizeof(WCHAR));
pbCipherBlob = // Allocate dwCipherBlobSize bytes
pbCipherBlob->cbSize = sizeof(NCRYPT_KEY_BLOB_HEADER);
pbCipherBlob->dwMagic = NCRYPT_CIPHER_KEY_BLOB_MAGIC;
pbCipherBlob->cbAlgName = (wcslen(szwAESAlg[0]) + 1 ) * sizeof(WCHAR);
pbCipherBlob->cbKeyData = b_dwAESKeyBlobSize;
// Immediately follow with Algorithm Name and Key Blob
pbPointer = (PBYTE)pbCipherBlob + pbCipherBlob->cbSize;
CopyMemory(pbPointer, szwAESAlg[0], pbCipherBlob->cbAlgName);
pbPointer += pbCipherBlob->cbAlgName;
CopyMemory(pbPointer, b_pbAESKeyBlob, b_dwAESKeyBlobSize);
// Import NCRYPT_CIPHER_KEY_BLOB
NCryptImportKey(NCRYPT_CIPHER_KEY_BLOB, pbCipherBlob, dwCipherBlobSize) -> n_hAESKey
// Export (Encrypt) the AES key with RSA key
NCryptExportKey(n_hAESKey, n_hRSAPublicKey) -> n_pbEncryptedAESKeyBlob, n_dwEncryptedAESKeyBlobSize
CLIENT
NCryptOpenStorageProvider
NCryptOpenKey("MyRSAKeyName") -> n_hRSAKey
// Import and decrypt key blob using RSA private key)
NCryptImportKey(n_hRSAKey, NCRYPT_OPAQUETRANSPORT_BLOB, n_pbEncryptedAESKeyBlob, n_dwEncryptedAESKeyBlobSize) -> n_hAESKey
// Export AES key to NCRYPT_CIPHER_KEY_BLOB)
NCryptExportKey(n_hAESKey, NCRYPT_CIPHER_KEY_BLOB) -> n_pbCipherBlob
// Import BCRYPT_KEY_DATA_BLOB contained in NCRYPT_CIPHER_KEY_BLOB to get BCryptHandle
b_pbAESKeyBlob = n_pbCipherBlob + n_pbCipherBlob->cbSize + n_ pbCipherBlob->cbAlgName;
BCryptOpenAlgorithmProvider(BCRYPT_AES_ALGORITHM)
BCryptImportKey(BCRYPT_KEY_DATA_BLOB, b_pbAESKeyBlob, n_pbCipherBlob->cbKeyData) -> b_hAESKey
If you still have problem or concern, a support ticket is recommend so that our engineer could work closely with you to resolve this issue as soon as possible. You can open links below and navigate to 'Contact US' to open the ticket: