Advanced Metering Infrastructure (AMI) is one of the basic functional blocks of the SmartGrid that supports mutual communications between customers and electric utilities. AMI needs universal definitions and communication standards for interoperability between meters and other devices. For some countries (including europian countries) Device Language Message specification (DLMS)/Companion Specification for Energy Metering (COSEM) is the common language so that the partners can understand each other. The security problems should be considered prior to the AMI system rollout. To consider the security issues in DLMS/COSEM, various key types are introduced, but managing these keys has not been described. To ensure confidentiality and integrity in keys problem, a key management scheme is required. For the first time, in this paper, a key management scheme for AMI system based on DLMS/COSEM standard is proposed. In the first step, three protocols for distribution of master key and global/authentication keys are considered, then in the next step two updating protocols are presented for refreshing these keys.