Beispiel #1
0
 /// <summary>
 /// Generate random primes: P and Q
 /// </summary>
 private void GeneratePQ()
 {
     do
     {
         _p = RsaMath.GeneratePrimeNumber(MIN_PRIMES_VALUE, MAX_PRIMES_VALUE);
         _q = RsaMath.GeneratePrimeNumber(MIN_PRIMES_VALUE, MAX_PRIMES_VALUE);
     } while (_p == _q);
 }
Beispiel #2
0
 /// <summary>
 /// Choose public key exponent
 /// </summary>
 private void ChooseE()
 {
     E = RsaMath.ChoosePublicKeyExponent(_totient);
 }
Beispiel #3
0
 /// <summary>
 /// Calculate Euler's totient function
 /// </summary>
 private void CalculateTotient()
 {
     _totient = RsaMath.CalculateEulersTotientFunction(_p, _q);
 }
Beispiel #4
0
 /// <summary>
 /// Calculate modulus for public and private keys
 /// </summary>
 private void CalculateN()
 {
     N = RsaMath.CalculateModulusForKeys(_p, _q);
 }
Beispiel #5
0
        /// <summary>
        /// Decrypt <c>int</c> message
        /// </summary>
        /// <param name="encryptedMessage">Encrypted message</param>
        /// <returns>Decrypted message</returns>
        public int DecryptMessage(int encryptedMessage)
        {
            int decrypted = RsaMath.DecryptMessage(encryptedMessage, D, N);

            return(decrypted);
        }
Beispiel #6
0
        /// <summary>
        /// Encrypt <c>int</c> message
        /// </summary>
        /// <param name="message">Input message</param>
        /// <returns>Encrypted message</returns>
        public int EncryptMessage(int message)
        {
            int encrypted = RsaMath.EncryptMessage(message, E, N);

            return(encrypted);
        }
Beispiel #7
0
 /// <summary>
 /// Calculate private key exponent
 /// </summary>
 private void CalculateD()
 {
     D = RsaMath.CalculatePrivateKeyExponent(E, _totient);
 }