This paper presents an effective technique and approach to deal with the dual challenges of performance optimization and privacy protection in microgrid power trading systems (MPTS) by utilizing attribute encryption technology. By embedding advanced cryptographic techniques into the operational substrate of microgrids, we introduce a novel approach to dramatically enhance the efficiency of energy distribution, while guaranteeing the privacy protection and integrity of participant data. The core objective of this technique is the application of attribute-based encryption (ABE), a method that offers fine-grained access control, ensuring sensitive information is made available only to eligible users based on their attributes, rather than their identities. In doing so, it meets the important requirement of securing data, without impairing the overall productivity of a power trading system. This paper presents a novel technique of ABE in the domain of MPTS, but also quantifies, through extensive theoretical analysis and simulations, how this integration leads to superior energy resource allocation and lower operational costs.