Torque flows from the shaft (centre) through the key to the hub (outer ring). The cyan line is the shear plane; the key sides are the bearing faces. Colour shows the safety factor (green = margin / red = short).
$$T = \frac{9549\,P}{N}, \qquad F = \frac{2T}{d}$$
Transmitted torque T [N·m] (P: power kW, N: speed rpm) and the tangential force F [N] at the shaft surface (d: shaft diameter).
$$\tau = \frac{F}{b\,L} = \frac{2T}{d\,b\,L}, \qquad \sigma_c = \frac{F}{(h/2)\,L} = \frac{4T}{d\,h\,L}$$
Shear stress τ and bearing stress σ_c. b: key width, h: key height, L: effective length. Bearing assumes half the key height carries the load.
$$n_{\text{shear}} = \frac{0.577\,\sigma_y}{\tau}, \qquad n_{\text{bearing}} = \frac{\sigma_y}{\sigma_c}$$
Shear and bearing safety factors. σ_y: yield strength. Shear yield is 0.577σ_y by the von Mises criterion. The design is OK when both factors meet the target S.