Given $A^2 = AB$ and $B^2=I+BA$, prove that $A=0$. $A,B$ are a $n\times n$ matrices. given that

$A^2 = AB$ and $B^2=I+BA$

Prove that $A=0$.
Is the following proof correct?
If we write $A^2=AB \rightarrow A^2-AB=0 \rightarrow A(A-B)=0$
We get that $A$ or $(A-B)$ equals $0$.
We then write $B^2 = I+BA \rightarrow B^2 -BA = I \rightarrow B(B-A)=I$
and we get that $B^{-1}=(B-A)$
Now, since $-B^{-1}=-(B-A)=(A-B)$
And that $B(-B^{-1})=-(BB^{-1})=-I$ we get that $(A-B) \neq 0$ which means $A=0$
 A: Note that
$$\tag1A^2=AB$$
and $$\tag2B^2=I+BA$$
imply
$$A^3\stackrel{(1)}=A^2B\stackrel{(1)}=AB^2\stackrel{(2)}=A(I+BA)=A+ABA\stackrel{(1)}=A+A^3$$
so that $A=0$.
Apparently, the conclusion is valid in any ring,  not just for matrices.

Nevertheless, your proof is nicely savable, even in spit of the major blunder where you say that one of the factors has to be zero:
You show correctly that $B(B-A)=I$, hence $B-A$ is invertible, hence so is $A-B$, hence $0=A(A-B)$ does imply that $A=0$ (namely, by multiplying with $(A-B)^{-1}$ from the right; you even elaborate that $(A-B)^{-1}=-B$. I am however certain that the mentioned blunder will lead to severe point deduction.
A: For matrices, you cannot conclude that $ST = 0$ implies at least one of $S$ and $T$ is the zero matrix in general (cf the example by player3236 in the comments). So that part isn't quite right though the rest seems okay to me. That said, the last bit is a bit clunky. I'd write it as $A(A-B) = 0$ however $(A-B)$ is invertible per the above and multiplying on the right on both sides by its inverse leads to $A = 0$.
