Structural colors of 2D gratings are iridescent, color-tunable, and never fade, which renders them appealing for anti-counterfeiting applications. However, for advanced security, it still remains a challenge to completely hide the encrypted color patterns and reveal them on demand. In this work, a water-responsive photonic grating consisting of a micropillar array and a hydrogel overcoat with a similar refractive index, termed "hydrocipher", is presented. The joint effect of stimuli-reversible refractive-index (mis)match and reconfigurable grating-based diffraction coloration enables a complete encryption of the structural color and rapid decryption. The photonic structure shows a strong iridescence due to the angle-dependent diffraction when the hydrogel overcoat is swollen from water. Upon drying, the micropillars bend and the refractive index contrast disappears, which dramatically lessens the diffraction intensity and renders the surface highly transparent. The dehydrated-to-hydrated state transition can occur within 1 s, enabling fast decryption. The color switching is highly reversible over a prolonged hydration/dehydration cycle, and the dehydrated hydrogel layer protects the delicate micropillar array from external mechanical stress. The creative combination of hydrogel material and the 2D grating structure offers a new and simple strategy for realizing reversible, durable, and fast-response cryptography with potentially broad impact on the anti-counterfeiting technology market.