modPow() public method

public modPow ( BigInteger exp, BigInteger n ) : BigInteger
exp BigInteger
n BigInteger
return BigInteger
Beispiel #1
0
 public void MakeAESKey(string keyExchangeBytes)
 {
     BigInteger A = new BigInteger(keyExchangeBytes);
     byte[] R = A.modPow(privateKey, Module).getBytes();
     aesKey = new byte[16];
     Array.Copy(R, aesKey, 16);
     for (int i = 0; i < 16; i++)
     {
         byte tmp = (byte)(aesKey[i] >> 4);
         byte tmp2 = (byte)(aesKey[i] & 0xF);
         if (tmp > 9)
             tmp = (byte)(tmp - 9);
         if (tmp2 > 9)
             tmp2 = (byte)(tmp2 - 9);
         aesKey[i] = (byte)( tmp << 4 | tmp2);
     }
 }
 /// <summary>
 /// Extracts secret information from the key exchange data.
 /// </summary>
 /// <param name="keyEx">The key exchange data within which the shared key is hidden.</param>
 /// <returns>The shared key derived from the key exchange data.</returns>
 public override byte[] DecryptKeyExchange(byte[] keyEx)
 {
     BigInteger pvr = new BigInteger(keyEx);
     BigInteger z = pvr.modPow(m_X, m_P);
     byte[] ret = z.getBytes();
     z.Clear();
     return ret;
 }