public static byte[] CreateSignature(byte[] p_data, ElGamalKeyStruct p_key_struct)
{
BigInteger x_pminusone = p_key_struct.P - 1;
BigInteger K;
do
{
K = new BigInteger();
K.genRandomBits(p_key_struct.P.bitCount() - 1, new Random());
} while (K.gcd(x_pminusone) != 1);
BigInteger A = p_key_struct.G.modPow(K, p_key_struct.P);
BigInteger B = mod(mod(K.modInverse(x_pminusone) * (new BigInteger(p_data) - (p_key_struct.X * (A))), (x_pminusone)), (x_pminusone));
byte[] x_a_bytes = A.getBytes();
byte[] x_b_bytes = B.getBytes();
int x_result_size = (((p_key_struct.P.bitCount() + 7) / 8) * 2);
byte[] x_result = new byte[x_result_size];
Array.Copy(x_a_bytes, 0, x_result, x_result_size / 2 - x_a_bytes.Length, x_a_bytes.Length);
Array.Copy(x_b_bytes, 0, x_result, x_result_size - x_b_bytes.Length, x_b_bytes.Length);
return(x_result);
}