Move key generation to Key class