If I understand things correctly, the encCtx->type gets garbage for some reasons. Can you try to dump the template you created in encDataNode to a file or stdout right before you call the encryption function, please? I wonder if the problem is in the template creation or template parser part. Aleksey