Physical unclonable functions (PUFs) are complex physical objects that aim at overcoming the vulnerabilities of traditional cryptographic keys, promising a robust class of security primitives for different applications. Optical PUFs present advantages over traditional electronic realizations, namely, a stronger unclonability, but suffer from problems of reliability and weak unpredictability of the key. We here develop a two-step PUF generation strategy based on deep learning, which associates reliable keys verified against the National Institute of Standards and Technology (NIST) certification standards of true random generators for cryptography. The idea explored in this work is to decouple the design of the PUFs from the key generation and train a neural architecture to learn the mapping algorithm between the key and the PUF. We report experimental results with all-optical PUFs realized in silica aerogels and analyzed a population of 100 generated keys, each of 10,000 bit length. The key generated passed all tests required by the NIST standard, with proportion outcomes well beyond the NIST’s recommended threshold. The two-step key generation strategy studied in this work can be generalized to any PUF based on either optical or electronic implementations. It can help the design of robust PUFs for both secure authentications and encrypted communications.