This document proposes a unified framework for approximating the optimal key estimation of stream ciphers using probabilistic inference. It formulates the key estimation problem as determining the secret key that maximizes the joint probability based on the observed keystream. An approximation algorithm called the sum-product algorithm is used to efficiently compute approximate marginal probabilities on a factor graph representing the cipher structure. Preprocessing techniques can reduce the complexity of the sum-product algorithm when applied to ciphers using linear feedback shift registers.