1. A method, performed by a processor of a cryptographic system, of detecting errors when cryptographically generating a message, the method including: generating a pair of public and private cryptographic keys from a multiplicative group of integers modulo n, with n being the product of the two prime numbers p and q, said generating including performing the following for generating the two prime numbers p and q used to generate the public and private cryptographic keys: a random drawing of candidate integers for p and q, and an test of the primality of said candidate integers including: a first step of searching for a generator a of the multiplicative group of integers modulo p, zero being excluded, a second step of searching for a generator b of the multiplicative group of integers modulo q, zero being excluded, wherein the generator a or b is selected via the following process: selecting a candidate integer w as p or q when w satisfies w−1=2 s r, wherein s is an integer and r is an odd integer, selecting a number c as a candidate generator for generators a or b such that 1≤c≤w−1, calculating the number y as c 2 s−1 r in order to save system resources, comparing said number y with the number w−1, and selecting said number c as generator of the multiplicative group of integers modulo w, zero being excluded, when y=w−1 mod w, rejecting p or q when p or q fails the test of their primality and generating another candidate integer for p or q upon which to perform an additional test for primality; performing an integrity test of the generated public and private cryptographic keys by encrypting a number y, as message m, using the generated public and private cryptographic keys, wherein the message satisfies: 1≤y≤n−1 with y=a mod p and γ=b mod q, and the message m is of order λ(n), wherein λ(n) is the lowest common multiple between p−1 and q−1, in order to optimize integrity verification by decreasing the error rate at which the public and private cryptographic keys are generated.