Added length check as well to null in encrypt method