[encryption] improved error handling (OC6) 

Backport of #7155 to OC6