I have a Windows Application which contains functions for Encrypt/Decrypt which is working fine when both the functions are put together as a single code. Now, I wanted to call encrypt and decrypt functions independently of each other, thus, I split the code temporarily in say, function1() and function2() for encrypt / decrypt respectively.
There are few parameters like key etc, which are created only during encryption, i.e. in function1() but will also be used when decryption, i.e. function2() would be called.
I am not able to access the values of the variables being created in the function1() from function2()
Is there any way I can achieve this?
Declaring the functions private or public doesn't make any difference. Also, I cannot create new keys as it would result in improper decryption.
All the above functions are in a single code, Form1.cs
The code which creates the keys is as follows:
ElGamalParameters dhParams = new ElGamalParameters(p, g, privateValueSize); ElGamalKeyGenerationParameters ekgParams = new ElGamalKeyGenerationParameters(new SecureRandom(), dhParams); ElGamalKeyPairGenerator kpGen = new ElGamalKeyPairGenerator(); kpGen.Init(ekgParams); AsymmetricCipherKeyPair pair = kpGen.GenerateKeyPair(); ElGamalPublicKeyParameters pu = (ElGamalPublicKeyParameters)pair.Public; ElGamalPrivateKeyParameters pv = (ElGamalPrivateKeyParameters)pair.Private;
The pubic key is accessed using
and the private key using