Jasher 2:11

And Cainan grew up and he was forty years old, and he became wise and had knowledge and skill in all wisdom, and he reigned over all the sons of men, and he led the sons of men to wisdom and knowledge; for Cainan was a very wise man and had understanding in all wisdom, and with his wisdom he ruled over spirits and demons;