Does $R \times S \cong R' \times S$ imply $R \cong R '$ for finite rings? Let $R,R',S$ be finite (unital, associative) rings. Assume that $R \times S \cong R' \times S$ as rings. Does it follow that $R \cong R'$ as rings ? What if we assume $R,R',S$ to be commutative as well?

This clearly fails if we do not assume finiteness, take e.g. a domain $R$ and
$R' = R \times R, \;     S = \prod\limits_{n \in \Bbb N} R$.
The question for finite groups was asked here. It implies in particular that the additive groups and the unit groups of $R,R'$ are isomorphic, but this does not imply the rings to be isomorphic (at least if we allow infinite rings, in which case some number fields provide a counterexample).
A similar question for rings was asked here, but the counter-example given there probably cannot be adapted here since I want finite rings.
 A: Let $R$ be a ring with finitely many central idempotents.  The set of central idempotents of $R$ then forms a finite Boolean algebra, which is isomorphic to the power set of a finite set.  Under this isomorphism, the singleton sets correspond to the minimal nonzero idempotents $e_1,\dots,e_n$ of $R$, which are orthogonal and satisfy $\sum e_i=1$.  This gives an isomorphism $R\cong \prod R_i$ where $R_i=R/(1-e_i)$.  Moreover, each $R_i$ is indecomposable (nonzero and cannot be written nontrivially as a product), since product decompositions of $R$ correspond to central idempotents and there are no nonzero idempotents below each $e_i$.  Moreover, this is the unique way to write $R$ as a product of indecomposable rings, since an indecomposable quotient of $R$ is exactly a quotient of $R$ by a minimal nonzero central idempotent.  (More precisely, by this uniqueness I mean that the set of kernels of the projection homomorphisms will be the same for any other way of writing $R$ as a product of indecomposable rings, since they must be ideals of the form $1-e$ where $e$ is a minimal nonzero central idempotent.)
So, the upshot is we have "unique factorization" for rings with finitely many central idempotents: every such ring can be written as a finite product of indecomposable rings and this factorization is unique up isomorphisms and permutations of the factors.  It follows immediately that if $R\times S\cong R'\times S$ for three such rings $R,R',S$, we must have $R\cong R'$, since $R$ and $R'$ must have the same indecomposable factors.
A: Here is an alternative solution, based on the following "Fake Yoneda Lemma". It does not just hold for rings, but for all algebraic objects of a given type (with the same proof), see my  answer here.

Let $R,S$ be finite rings. Assume that for all finite rings $T$ there is a bijection $\mathrm{Hom}(T,R) \cong \mathrm{Hom}(T,S)$; not assumed to be natural. Then there is an isomorphism of rings $R \cong S$.

Now, if $ R,R',S$ are finite rings with $R \times S \cong R' \times S$, then for all finite rings $T$ we obtain, using the universal property of products
$$\begin{align*} & \quad\,\,\mathrm{Hom}(T,R') \times \mathrm{Hom}(T,S) \\ & \cong \mathrm{Hom}(T,R' \times S) \\ & \cong \mathrm{Hom}(T,R \times S) \\ & \cong \mathrm{Hom}(T,R) \times \mathrm{Hom}(T,S).\end{align*}$$
But these are just finite sets. So if $\mathrm{Hom}(T,S)$ was non-empty, we could derive $\mathrm{Hom}(T,R') \cong \mathrm{Hom}(T,R)$ and apply the "Fake Yoneda Lemma" to deduce $R \cong R'$. (This is exactly how one can prove cancellation for finite groups, see Seirios' answer here.)
The problem is that the zero map $T \to S$ is not a ring homomorphism (unless $S=0$). So let us just switch the category and work with rngs instead! Since the forgetful functor $\mathbf{Ring} \to \mathbf{Rng}$ preserves products and the "Fake Yoneda Lemma" also holds for rngs, the above argument, using finite rngs $ T$ instead, gives us an isomorphism $R \cong R'$ in the category $\mathbf{Rng}$. Now, any surjective homomorphism $\varphi$ of rngs between rings automatically preserves the multipliactive unit (since $\varphi(1)$ is a unit for the image, hence for the whole ring, and units are unique). So we get $R \cong R'$ in $\mathbf{Ring}$.
