A key has a dual purpose. One is to open, another to lock. There is a type of door or gate which needs to be locked, and there is one that needs to be opened. The same is true in one’s life.

Negative influences need to be closed off from a person. He needs to lock his gate and not permit them to enter. In contrast, he needs to welcome those good, desirable matters, such as the Torah and its mitzvos opening his gates to allow them in.

Igros Kodesh, Vol. 22, p. 333