In recent years, several countries have increasingly promoted digital health to improve medical care quality and precision medicine. Concerns such as how to employ and manage medical data, including physiological signals and medical images, have emerged as one of the core issues in eHealth. The National Health Insurance of Taiwan has gradually generated cross-hospital medical image databases since the year 2018, including lung cancer, brain tumor, breast tumor, liver tumor, and coronary arterial diseases. Digitized medical image data can be stored in cloud databases or be transmitted via computer networks or wireless transmissions. However, patient confidentiality and transmission infosecurity are serious concerns in public channels or spaces, which raises the question of how to prevent data from being stolen, tampered, or peeked after receipt by unauthorized people. Hence, infosecurity has become an important issue in the digital era. This study proposes hash transformation with multi-secret keys and an optimization-based controller to engage a novel cryptographic method to encrypt and decrypt digital medical images in a health information system. Both the gradient descent (GD) and the particle swarm optimization (PSO)-based controllers are implemented to search the decryption key parameters. For a case study in breast elastography and X-ray images consisting of 150 benign tumors and 150 malignant tumors, the peak signal-to-noise ratio (PSNR) is used to evaluate the similarity of two images between the original images and the decrypted images. Conclusively, the PSO-based controller performed better than the GD-based controller and traditional cryptographic methods in terms of recovery reliability. INDEX TERMS Digital health, infosecurity, hash transformation, optimization based controller, signal-tonoise ratio.