Abstract:This study examines the secrecy performance of an uplink device-to-device (D2D) communication system enhanced by reconfigurable intelligent surfaces (RIS) while considering the presence of multiple eavesdroppers. RIS technology is employed to improve wireless communication environment by intelligently reflecting signals, thereby improving both capacity and security. We employ deep reinforcement learning (DRL) to optimize resource allocation dynamically, addressing challenges in D2D pairs and optimizing RIS positioning and phase shifts in a changing wireless environment. Our simulations demonstrate that the developed DRL-based framework significantly maximizes the sum secrecy capacity of both D2D and cellular communications, achieving higher transmission secrecy rates compared to existing benchmarks. The results highlight the effectiveness of integrating RIS with D2D communications for improved security performance.